Skip to content

Commit

Permalink
Merge pull request #18 from Ghostdar/master
Browse files Browse the repository at this point in the history
fix: front matter 语雀编辑器设置多个属性解析错误, 增加文档关于配置文章信息的指引
  • Loading branch information
x-cold authored Jan 10, 2019
2 parents f8ab8c3 + c0e69a6 commit 114c3c6
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -87,10 +87,31 @@ DEBUG=yuque-hexo.* yuque-hexo sync

# Notice

语雀同步过来的文章会生成两部分文件;
1. 语雀同步过来的文章会生成两部分文件;

- yuque.json: 从语雀 API 拉取的数据
- source/_posts/yuque/*.md: 生成的 md 文件
- yuque.json: 从语雀 API 拉取的数据
- source/_posts/yuque/*.md: 生成的 md 文件

2. 支持配置front-matter, 语雀编辑器编写示例如下:
- 语雀编辑器示例,可参考[原文](https://www.yuque.com/u46795/blog/dlloc7)
![image.png](https://cdn.nlark.com/yuque/0/2019/png/155457/1547033073596-797e3d68-fac4-40fd-8e8d-16ea1da4b705.png)
语雀编辑器转换成的markdown 如下(已做兼容):
```markdown
tags: [hexo, node]<br />date: 2018-06-09<br />categories: 前端

---
```

- 标准 markdown 示例:

```markdown
date: 2015-04-18 00:00:00
tags: [css]
categories: CSS
---
```

> 注意:分割线不能少,兼容一个或多个属性的自定义

# Example

3 changes: 3 additions & 0 deletions lib/download.js
Original file line number Diff line number Diff line change
@@ -242,6 +242,9 @@ function formatRaw(body) {
function parseMatter(body) {
body = entities.decode(body);
try {
// front matter信息的<br/>换成 \n
const regex = /(title:|layout:|tags:|date:|categories:){1}(\S|\s)+?---/gi;
body = body.replace(regex, a => a.replace(/(<br \/>|<br>|<br\/>)/gi, '\n'));
const result = FrontMatter.parse(body);
result.body = result._content;
if (result.date) {

0 comments on commit 114c3c6

Please sign in to comment.