Skip to content

Instantly share code, notes, and snippets.

@mpr0xy
Created June 8, 2014 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpr0xy/cc5459d1001af915c7fb to your computer and use it in GitHub Desktop.
Save mpr0xy/cc5459d1001af915c7fb to your computer and use it in GitHub Desktop.
解析一个md文件前面加入得一些描述信息(比如写一篇博客会包含得信息)
var fs = require('fs');
var yamlish = require('yamlish'); // npm install yamlish
// md文件头部类似下面的注释信息,为了不会于文章里的注释符号冲突,加了>>
// 第一行需要时空行,因为yamlish库是从第二行开始解析得,你妹啊
/*<<
Title: how to make love with a girl
Date: 2014-04-01 12:14:05
Category: love
Tags: love, girl
Sources: github.com
>>*/
// 假设上面得注释信息是在test.md文件里
var md_content = (fs.readFileSync("test.md") + '').split('>>*/');
var md_info = md_content[0].substr(5); // /*<<\n
md_info = yamlish.decode(md_info);
/** md_info:
{ Title: 'how to make love with a girl',
Date: '2014-04-01 12:14:05',
Category: 'love',
Tags: 'love, girl',
Sources: 'github.com',
'': '' }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment