Markdown metadata parser
This commit is contained in:
parent
2f7056a29e
commit
d49f56e022
@ -13,9 +13,8 @@ router.get('/', (req, res) => {
|
|||||||
|
|
||||||
fs.readFileAsync("repo/Storage/Redis.md", "utf8").then(function(contents) {
|
fs.readFileAsync("repo/Storage/Redis.md", "utf8").then(function(contents) {
|
||||||
let pageData = mark.parse(contents);
|
let pageData = mark.parse(contents);
|
||||||
if(!pageData.title) {
|
if(!pageData.meta.title) {
|
||||||
pageData.title = 'Redis';
|
pageData.meta.title = 'Redis.md';
|
||||||
pageData.subtitle = 'An open source, in-memory data structure store, used as database, cache and message broker.';
|
|
||||||
}
|
}
|
||||||
res.render('pages/view', { pageData });
|
res.render('pages/view', { pageData });
|
||||||
});
|
});
|
||||||
|
@ -55,10 +55,6 @@ mkdown.renderer.rules.emoji = function(token, idx) {
|
|||||||
return '<i class="twa twa-' + token[idx].markup + '"></i>';
|
return '<i class="twa twa-' + token[idx].markup + '"></i>';
|
||||||
};
|
};
|
||||||
|
|
||||||
mkdown.inline.ruler.push('internal_link', (state) => {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse markdown content and build TOC tree
|
* Parse markdown content and build TOC tree
|
||||||
*
|
*
|
||||||
@ -159,10 +155,23 @@ const parseContent = (content) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseMeta = (content) => {
|
||||||
|
|
||||||
|
let commentMeta = new RegExp('<!-- ?([a-zA-Z]+):(.*)-->','g');
|
||||||
|
let results = {}, match;
|
||||||
|
while(match = commentMeta.exec(content)) {
|
||||||
|
results[_.toLower(match[1])] = _.trim(match[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
parse(content) {
|
parse(content) {
|
||||||
return {
|
return {
|
||||||
|
meta: parseMeta(content),
|
||||||
html: parseContent(content),
|
html: parseContent(content),
|
||||||
tree: parseTree(content)
|
tree: parseTree(content)
|
||||||
};
|
};
|
||||||
|
@ -37,9 +37,9 @@ block content
|
|||||||
|
|
||||||
.column
|
.column
|
||||||
|
|
||||||
h1.title#title= pageData.title
|
h1.title#title= pageData.meta.title
|
||||||
if pageData.subtitle
|
if pageData.meta.subtitle
|
||||||
h2.subtitle= pageData.subtitle
|
h2.subtitle= pageData.meta.subtitle
|
||||||
.content.mkcontent
|
.content.mkcontent
|
||||||
!= pageData.html
|
!= pageData.html
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user