Skip to content

Conversation

@CloudyCity
Copy link
Contributor

#6

@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

# hexo migrate github-issue Yikun/hexo-migrator-github-issue
INFO  Validating config
INFO  Migrate from Yikun/hexo-migrator-github-issue...
INFO  create post: [Test] Issue
INFO  create post: Support front-matter in the issue content
INFO  create post: 兼容更多Meta
Unhandled rejection YAMLException: bad indentation of a mapping entry (1:15)

 1 | title: [Test] Issue
-------------------^
 2 | date: 2021-06-03 02:45:20
 3 | tags:
    at generateError (/root/test/node_modules/js-yaml/lib/loader.js:183:10)
    at throwError (/root/test/node_modules/js-yaml/lib/loader.js:187:9)
    at readBlockMapping (/root/test/node_modules/js-yaml/lib/loader.js:1182:7)
    at composeNode (/root/test/node_modules/js-yaml/lib/loader.js:1441:12)
    at readDocument (/root/test/node_modules/js-yaml/lib/loader.js:1625:3)
    at loadDocuments (/root/test/node_modules/js-yaml/lib/loader.js:1688:5)
    at load (/root/test/node_modules/js-yaml/lib/loader.js:1714:19)
    at /root/test/node_modules/hexo/lib/hexo/post.js:152:63
    at tryCatcher (/root/test/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/root/test/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/root/test/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/root/test/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/root/test/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/root/test/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._settlePromise (/root/test/node_modules/bluebird/js/release/promise.js:617:21)
    at Promise._settlePromise0 (/root/test/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/root/test/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/root/test/node_modules/bluebird/js/release/promise.js:673:18)
    at /root/test/node_modules/bluebird/js/release/nodeback.js:42:21
    at /root/test/node_modules/nunjucks/src/environment.js:41:5
    at RawTask.call (/root/test/node_modules/asap/asap.js:40:19)
    at flush (/root/test/node_modules/asap/raw.js:50:29)

yaml中有特殊字符的话会break

@CloudyCity CloudyCity closed this Jun 3, 2021
@CloudyCity CloudyCity reopened this Jun 3, 2021
@CloudyCity
Copy link
Contributor Author

# hexo migrate github-issue Yikun/hexo-migrator-github-issue
INFO  Validating config
INFO  Migrate from Yikun/hexo-migrator-github-issue...
INFO  create post: [Test] Issue
INFO  create post: Support front-matter in the issue content
INFO  create post: 兼容更多Meta
Unhandled rejection YAMLException: bad indentation of a mapping entry (1:15)

 1 | title: [Test] Issue
-------------------^
 2 | date: 2021-06-03 02:45:20
 3 | tags:
    at generateError (/root/test/node_modules/js-yaml/lib/loader.js:183:10)
    at throwError (/root/test/node_modules/js-yaml/lib/loader.js:187:9)
    at readBlockMapping (/root/test/node_modules/js-yaml/lib/loader.js:1182:7)
    at composeNode (/root/test/node_modules/js-yaml/lib/loader.js:1441:12)
    at readDocument (/root/test/node_modules/js-yaml/lib/loader.js:1625:3)
    at loadDocuments (/root/test/node_modules/js-yaml/lib/loader.js:1688:5)
    at load (/root/test/node_modules/js-yaml/lib/loader.js:1714:19)
    at /root/test/node_modules/hexo/lib/hexo/post.js:152:63
    at tryCatcher (/root/test/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/root/test/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/root/test/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/root/test/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/root/test/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/root/test/node_modules/bluebird/js/release/promise.js:673:18)
    at Promise._settlePromise (/root/test/node_modules/bluebird/js/release/promise.js:617:21)
    at Promise._settlePromise0 (/root/test/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/root/test/node_modules/bluebird/js/release/promise.js:729:18)
    at Promise._fulfill (/root/test/node_modules/bluebird/js/release/promise.js:673:18)
    at /root/test/node_modules/bluebird/js/release/nodeback.js:42:21
    at /root/test/node_modules/nunjucks/src/environment.js:41:5
    at RawTask.call (/root/test/node_modules/asap/asap.js:40:19)
    at flush (/root/test/node_modules/asap/raw.js:50:29)

yaml中有特殊字符的话会break

能否提供下yaml内容?

@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

@CloudyCity
用这个命令可以复现:hexo migrate github-issue Yikun/hexo-migrator-github-issue

但和你这个patch无关应该,旧版本也有问题。
复现用例:#9
issue:#10

@@ -4,7 +4,8 @@
"description": "Github issue migrator plugin for Hexo.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"version": "0.1.5" 直接改成0.16吧,merge后我就release

var topPrefix = 'top_';
var categoryPrefix = 'category_';
var category_prefix = 'category_';
var regexp = /^(-{3,})(\r\n)([\s\S]+?)\r\n\1\r\n?([\s\S]*)/;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个regexp自己写的吗?靠谱不,看的头大。:)

Copy link
Contributor Author

@CloudyCity CloudyCity Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@CloudyCity CloudyCity Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段主要是将FrontMatter中的CRLF替换为LF(我的文章中都是CRLF,不知道你的有没有这个问题),不然无法正常解析。如果全文替换,又会影响文章生成,所以最后用了正则。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加个注释吧

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者是不是可以直接引用这个变量,防止发生变化。加个注释和链接也可以,你自己看吧。:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者是不是可以直接引用这个变量,防止发生变化。加个注释和链接也可以,你自己看吧。:)

正则稍有不同,hexo-front-matter用的是LF,这里是用CRLF。我注释个链接。

@Yikun Yikun closed this Jun 3, 2021
@Yikun Yikun reopened this Jun 3, 2021
@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

close and reopen to trigger CI, : )

@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

好了,我没啥问题了。可以merge的话我就merge了

@CloudyCity
Copy link
Contributor Author

@Yikun 合并front-matter时的覆盖优先级你更偏向哪一种?

data = Object.assign(meta, data);
data = Object.assign(data, meta);

@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

meta应该可以覆盖掉data的。

当用户指定meta后,可以无视我们的规则(title的对应,label的对应等)。

这个文档补充一下:
If you specify the front-matter in the issue content, like:

---
cover: http://demo.jpeg
top: 1
---
# Title
Hello World!

The front-matter will be transparently added in your post writings. Note that, the front-matter in issue has the highest priority, that means the internal front-matter(such as, title, tags, number, date) will also be replaced.

- "top_", set the top priority for the post.
- "draft", the post layout will be set to "draft", that means the post will be stored in draft dir
- "publish", if user migrate with "--publish" opt, only post with "publish" label will be created.

Copy link
Owner

@Yikun Yikun Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Front-matter support

If you specify the front-matter in the issue content, like:

---
cover: http://demo.jpeg
top: 1
---
# Title
Hello World!

The front-matter will be transparently added in your post writings.

Note that, the front-matter in the issue content has the highest priority, that means the internal front-matter which generated by migrator (such as, title, tags, number, date) will also be replaced.

Front-matter作为一个独立的章节写吧

@Yikun Yikun merged commit dc0add2 into Yikun:master Jun 3, 2021
@Yikun
Copy link
Owner

Yikun commented Jun 3, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants