-
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.
- Loading branch information
1 parent
6447c63
commit 0d20d4d
Showing
18 changed files
with
1,499 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const markdownIt = require('markdown-it'); | ||
const markdownItContainer = require('markdown-it-container'); | ||
const frontMatter = require('markdown-it-front-matter'); | ||
|
||
const filterFileList = require('./utils/filterFileList'); | ||
const yamlToObject = require('./utils/yamlToObject'); | ||
|
||
const { POSTS, LAYOUTS } = require('./utils/constants'); | ||
|
||
let _post = {}; | ||
|
||
const mdOptions = { | ||
html: true | ||
}; | ||
|
||
const md = markdownIt(mdOptions) | ||
.use(frontMatter, function(fm) { | ||
_post = 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(); | ||
} | ||
} | ||
}); | ||
|
||
class Site { | ||
constructor() { | ||
this._posts = []; | ||
this._tags = []; | ||
|
||
const posts = fs.readdirSync(POSTS); | ||
const filteredPages = filterFileList(posts, 'md'); | ||
|
||
for (const post of filteredPages) { | ||
const pageContents = fs.readFileSync(`${POSTS}/${post}`).toString(); | ||
const renderedMarkdown = md.render(pageContents); | ||
let postData = Object.assign({ | ||
path: path.parse(post).name, | ||
html: renderedMarkdown | ||
}, _post); | ||
|
||
this._posts.push(postData); | ||
this._tags = this._tags.concat(postData.tags || []); | ||
} | ||
} | ||
|
||
getPosts() { | ||
return this._posts; | ||
} | ||
|
||
getTags() { | ||
return this._tags; | ||
} | ||
} | ||
|
||
module.exports = Site; |
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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
const generateHtmlFromLiquid = require('../utils/generateHtmlFromLiquid'); | ||
const filterFileList = require('../utils/filterFileList'); | ||
const { PAGES, BUILD } = require('../utils/constants'); | ||
|
||
module.exports = async function(site) { | ||
try { | ||
const posts = site.getPosts(); | ||
const pages = fs.readdirSync(PAGES); | ||
const filteredPages = filterFileList(pages, 'html') | ||
.filter(page => page !== '404.html'); | ||
|
||
for (const page of filteredPages) { | ||
const pageContents = fs.readFileSync(`${PAGES}/${page}`).toString(); | ||
const htmlPath = `${BUILD}/${path.parse(page).name}`; | ||
fs.mkdirp(htmlPath); | ||
|
||
const renderedHtml = await generateHtmlFromLiquid(pageContents, { posts }); | ||
fs.writeFileSync(`${htmlPath}/index.html`, renderedHtml); | ||
} | ||
|
||
// copy index/index.html to index.html also | ||
fs.copySync(`${BUILD}/index/index.html`, `${BUILD}/index.html`); | ||
|
||
// generate 404 page | ||
const pageContents = fs.readFileSync(`${PAGES}/404.html`).toString(); | ||
const renderedHtml = await generateHtmlFromLiquid(pageContents, { posts }); | ||
fs.writeFileSync(`${BUILD}/404.html`, renderedHtml); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
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,22 @@ | ||
const fs = require('fs-extra'); | ||
|
||
const generateHtmlFromLiquid = require('../utils/generateHtmlFromLiquid'); | ||
const { BUILD, LAYOUTS } = require('../utils/constants'); | ||
|
||
module.exports = async function(site) { | ||
try { | ||
const baseTemplate = fs.readFileSync(`${LAYOUTS}/tag.html`).toString(); | ||
const tags = [...new Set(site.getTags())]; | ||
const posts = site.getPosts(); | ||
|
||
for (const tag of tags) { | ||
const htmlPath = `${BUILD}/tag/${tag}`; | ||
fs.mkdirp(htmlPath); | ||
|
||
const renderedHtml = await generateHtmlFromLiquid(baseTemplate, { posts, tag }); | ||
fs.writeFileSync(`${htmlPath}/index.html`, renderedHtml); | ||
} | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
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,15 @@ | ||
const liveServer = require('live-server'); | ||
const { BUILD } = require('../utils/constants'); | ||
|
||
module.exports = function() { | ||
const params = { | ||
port: 8181, | ||
host: '0.0.0.0', | ||
root: BUILD, | ||
open: true, | ||
wait: 500, | ||
logLevel: 1 | ||
}; | ||
|
||
liveServer.start(params); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module.exports = { | ||
BUILD: 'build', | ||
PAGES: 'pages', | ||
POSTS: 'posts', | ||
STATIC: 'static', | ||
LAYOUTS: 'layouts' | ||
} |
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
Oops, something went wrong.