Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
d49f56e0
Commit
d49f56e0
authored
Aug 24, 2016
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markdown metadata parser
parent
2f7056a2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
pages.js
controllers/pages.js
+2
-3
markdown.js
models/markdown.js
+13
-4
view.pug
views/pages/view.pug
+3
-3
No files found.
controllers/pages.js
View file @
d49f56e0
...
...
@@ -13,9 +13,8 @@ router.get('/', (req, res) => {
fs
.
readFileAsync
(
"repo/Storage/Redis.md"
,
"utf8"
).
then
(
function
(
contents
)
{
let
pageData
=
mark
.
parse
(
contents
);
if
(
!
pageData
.
title
)
{
pageData
.
title
=
'Redis'
;
pageData
.
subtitle
=
'An open source, in-memory data structure store, used as database, cache and message broker.'
;
if
(
!
pageData
.
meta
.
title
)
{
pageData
.
meta
.
title
=
'Redis.md'
;
}
res
.
render
(
'pages/view'
,
{
pageData
});
});
...
...
models/markdown.js
View file @
d49f56e0
...
...
@@ -55,10 +55,6 @@ mkdown.renderer.rules.emoji = function(token, idx) {
return
'<i class="twa twa-'
+
token
[
idx
].
markup
+
'"></i>'
;
};
mkdown
.
inline
.
ruler
.
push
(
'internal_link'
,
(
state
)
=>
{
});
/**
* 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
=
{
parse
(
content
)
{
return
{
meta
:
parseMeta
(
content
),
html
:
parseContent
(
content
),
tree
:
parseTree
(
content
)
};
...
...
views/pages/view.pug
View file @
d49f56e0
...
...
@@ -37,9 +37,9 @@ block content
.column
h1.title#title= pageData.title
if pageData.subtitle
h2.subtitle= pageData.subtitle
h1.title#title= pageData.
meta.
title
if pageData.
meta.
subtitle
h2.subtitle= pageData.
meta.
subtitle
.content.mkcontent
!= pageData.html
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment