-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Live reload support for md and layouts
- Loading branch information
1 parent
fe31a5c
commit 89202ba
Showing
12 changed files
with
1,290 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require('fs-extra'); | ||
const markdownIt = require('markdown-it'); | ||
const markdownItContainer = require('markdown-it-container'); | ||
const frontMatter = require('markdown-it-front-matter'); | ||
|
||
const yamlToObject = require('./yamlToObject'); | ||
const { LAYOUTS } = require('./constants'); | ||
|
||
const mdOptions = { | ||
html: true | ||
}; | ||
|
||
let meta = {}; | ||
|
||
const md = markdownIt(mdOptions) | ||
.use(frontMatter, function(fm) { | ||
meta = yamlToObject(fm); | ||
}) | ||
.use(markdownItContainer, 'include', { | ||
validate: function(params) { | ||
return params.endsWith(':::') && params.includes('include'); | ||
}, | ||
|
||
render: function(tokens, idx) { | ||
let statement = tokens[idx]; | ||
if (statement.type === 'container_include_open') { | ||
let [, elements] = statement.info.trim().split(' '); | ||
return fs.readFileSync(`${LAYOUTS}/${elements}`).toString(); | ||
} | ||
|
||
return ''; | ||
} | ||
}); | ||
|
||
module.exports = function(pageContents) { | ||
let html = md.render(pageContents); | ||
return { html, meta }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const chokidar = require('chokidar'); | ||
|
||
const { STATIC } = require('./constants'); | ||
|
||
module.exports = function(site, runTask) { | ||
let postsWatcher = chokidar.watch(['posts/*md', 'posts/*html'], { | ||
ignored: /(^|[/\\])\../, | ||
ignoreInitial: true | ||
}); | ||
|
||
postsWatcher.on('all', async(event, path) => { | ||
await site.handlePostChange(event, path); | ||
// Need to further refine this to only rebuild changed files | ||
runTask([ | ||
'generatePostsFromMarkdown', | ||
'generatePages', | ||
'generatePagesForTags' | ||
], site); | ||
}); | ||
|
||
let layoutsWatcher = chokidar.watch('layouts/*html', { | ||
ignored: /(^|[/\\])\../, | ||
ignoreInitial: true | ||
}); | ||
|
||
layoutsWatcher.on('all', () => { | ||
// Need to further refine this to only rebuild changed files | ||
runTask([ | ||
'generatePostsFromMarkdown', | ||
'generatePages', | ||
'generatePagesForTags' | ||
], site); | ||
}); | ||
|
||
let majorAssetsWatcher = chokidar.watch([`${STATIC}/css/**/*css`, `${STATIC}/js/**/*js`], { | ||
ignored: /(^|[/\\])\../, | ||
ignoreInitial: true | ||
}); | ||
|
||
majorAssetsWatcher.on('all', async(event, path) => { | ||
// Need to further refine this to only rebuild changed files | ||
runTask('copyMajorStaticAssets', site, { event, path }); | ||
}); | ||
} |
Oops, something went wrong.