Here's the mu.js and wu.js files that could be used to generate a simple blog.
What is mu? What is wu?
Project /
mu.js
wu.js
markdown/
post-about-something.md
something-else.md
another-post.md
www/ (build folder)
'use strict'
const mu = require('/Users/path/to/mu')
const wu = require('./wu.js')
const build = async () => {
const rootFolder = './www'
try {
const blogPosts = await mu.readFiles('markdown')
const indexPosts = blogPosts.slice()
for (let post of blogPosts) {
post.destination = rootFolder
post.ext = '.html'
post.content = mu.marked(post.content) //md to html
post.content = wu.layout(post)
mu.writeFile(post)
}
// Index
// Sort index in reverse chronological order
indexPosts.sort((a, b) => (a.created > b.created) ? -1 : 1)
// Create a preview for each post
for (let post of indexPosts) {
post.content = mu.stripMarkdown(post.content)
if (post.content.length > 200) {
post.content = post.content.substring(0,180) + '...'
}
}
let postsPerPage = 2
index = mu.merge(indexPosts, postsPerPage)
mu.paginateFiles(index)
for (let page of index) {
page.destination = rootFolder
page.ext = '.html'
page.title = 'Blog'
page.content = wu.layout(page)
mu.writeFile(page)
}
}
catch (e) {
console.log(e)
}
'use strict'
const wu = {}
// Layouts
wu.layout = (page) => {
return `${wu.head(page)}
<body>
${wu.logo)}
<div class="wrap">
<div class="content">
${page.content}
</div>
</div>
${wu.footer()}
</body>
`
}
// Components
wu.head = (page) => {
return `<!doctype html>
<head>
<meta charset="utf-8">
<title>${page.title}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="/resources/blog.css">
</head>`
}
wu.banner = () => {
return `<img src="resources/banner.gif">`
}
wu.logo = () => {
return `
<div id="logo">
<a href="https://myblog.com">
<img id="mw-logo" src="/resources/logo.png" />
</a>
</div>
`
}
wu.footer = () => {
return `
<div id="footer">
Some stuff that would go in a footer
</div>`
}
module.exports = wu