Skip to content

Instantly share code, notes, and snippets.

View kartiknair's full-sized avatar

Kartik Nair kartiknair

View GitHub Profile
const addHomePage = posts => {
fs.writeFile(`${config.dev.outdir}/index.html`, homepage(posts), e => {
if (e) throw e;
console.log(`index.html was created successfully`);
});
};
const homepage = posts => `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="${config.blogDescription}" />
<title>${config.blogName}</title>
</head>
<body>
const config = {
blogName: "Blog",
blogDescription: "Sharing what I learn as a web developer & designer",
authorName: "Kartik Nair",
authorDescription:
"a web developer and designer making lot's of stuff in Dubai",
authorTwitter: "https://twitter.com/kartiknair",
dev: {
postsdir: "./content",
const fs = require("fs");
const postMethods = require("./posts");
const config = require("./config");
const posts = fs
.readdirSync(config.dev.postsdir)
.map(post => post.slice(0, -3))
.map(post => postMethods.createPost(post));
if (!fs.existsSync(config.dev.outdir)) fs.mkdirSync(config.dev.outdir);
const createPosts = posts => {
posts.forEach(post => {
if (!fs.existsSync(`${config.dev.outdir}/${post.path}`))
fs.mkdirSync(`${config.dev.outdir}/${post.path}`);
fs.writeFile(
`${config.dev.outdir}/${post.path}/index.html`,
posthtml(post),
e => {
if (e) throw e;
const posthtml = data => `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="${data.attributes.description}" />
<title>${data.attributes.title}</title>
</head>
<body>
const marked = require("marked");
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code, language) {
const hljs = require("highlight.js");
const validLanguage = hljs.getLanguage(language) ? language : "plaintext";
return hljs.highlight(validLanguage, code).value;
},
pedantic: false,
const config = require("./config");
const createPost = require("./posts.js");
const posts = fs
.readdirSync(config.dev.postsdir)
.map(post => post.slice(0, -3))
.map(post => postMethods.createPost(post));
console.log(posts);
const config = require("./config");
const fm = require("front-matter");
const marked = require("marked");
const createPost = postPath => {
const data = fs.readFileSync(`${config.dev.postsdir}/${postPath}.md`, "utf8");
const content = fm(data);
content.body = marked(content.body);
content.path = postPath;
return content;
title date description
Post One
2020–02–28T22:19:00Z
My reasons for starting a blog.

This is an amazing blog post.

Really it's just great