Skip to content

Commit 114c3c6

Browse files
authored
Merge pull request #18 from Ghostdar/master
fix: front matter 语雀编辑器设置多个属性解析错误, 增加文档关于配置文章信息的指引
2 parents f8ab8c3 + c0e69a6 commit 114c3c6

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,31 @@ DEBUG=yuque-hexo.* yuque-hexo sync
8787

8888
# Notice
8989

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

92-
- yuque.json: 从语雀 API 拉取的数据
93-
- source/_posts/yuque/*.md: 生成的 md 文件
92+
- yuque.json: 从语雀 API 拉取的数据
93+
- source/_posts/yuque/*.md: 生成的 md 文件
94+
95+
2. 支持配置front-matter, 语雀编辑器编写示例如下:
96+
- 语雀编辑器示例,可参考[原文](https://www.yuque.com/u46795/blog/dlloc7)
97+
![image.png](https://cdn.nlark.com/yuque/0/2019/png/155457/1547033073596-797e3d68-fac4-40fd-8e8d-16ea1da4b705.png)
98+
语雀编辑器转换成的markdown 如下(已做兼容):
99+
```markdown
100+
tags: [hexo, node]<br />date: 2018-06-09<br />categories: 前端
101+
102+
---
103+
```
104+
105+
- 标准 markdown 示例:
106+
107+
```markdown
108+
date: 2015-04-18 00:00:00
109+
tags: [css]
110+
categories: CSS
111+
---
112+
```
113+
114+
> 注意:分割线不能少,兼容一个或多个属性的自定义
94115

95116
# Example
96117

lib/download.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ function formatRaw(body) {
242242
function parseMatter(body) {
243243
body = entities.decode(body);
244244
try {
245+
// front matter信息的<br/>换成 \n
246+
const regex = /(title:|layout:|tags:|date:|categories:){1}(\S|\s)+?---/gi;
247+
body = body.replace(regex, a => a.replace(/(<br \/>|<br>|<br\/>)/gi, '\n'));
245248
const result = FrontMatter.parse(body);
246249
result.body = result._content;
247250
if (result.date) {

0 commit comments

Comments
 (0)