"use strict";
// P A C K A G E S
import decamelize from "decamelize";
import exists from "fs-exists-sync";
import fm from "front-matter";
import fs from "graceful-fs";
import html from "choo/html";
import path from "path";
import { require as local } from "app-root-path";
import raw from "choo/html/raw";
// V A R I A B L E S
const numberRegex = /^[0-9]/g;
const redirect404 = local("app/modules/redirect-404");
const md = require("markdown-it")({
html: true,
typographer: true
}).use(local("app/modules/markdown-it-sup"))
.use(require("markdown-it-anchor"), {
slugify: stringToSlugify => {
let finalString = stringToSlugify
.toLowerCase()
.replace(/\s\/\s/g, "-")
.replace(/\s/g, "-")
.replace(/%/g, "")
.replace(/\(/g, "")
.replace(/\)/g, "")
.replace(/,/g, "");
if (finalString.match(numberRegex)) finalString = `_${finalString}`;
return finalString;
}
});
// E X P O R T
module.exports = exports = (state, emit) => { // eslint-disable-line
let path;
if (state.route === "resources/*") path = `resources/${state.params.wildcard}`;
else path = state.params.wildcard;
if (!fs.existsSync(`./documents/${path}.md`))
return redirect404(state);
const markdownFile = fs.readFileSync(`./documents/${path}.md`, "utf-8");
const markdownFileDetails = fm(markdownFile);
const renderedMarkdown = md.render(markdownFileDetails.body);
const updatedMarkdown = wikiFinder(partialFinder(renderedMarkdown));
if (markdownFileDetails.attributes.meta) {
const customMetadata = {};
for (const key in markdownFileDetails.attributes.meta) {
if (markdownFileDetails.attributes.meta.hasOwnProperty(key)) {
customMetadata[Object.keys(markdownFileDetails.attributes.meta[key])[0]] =
markdownFileDetails.attributes.meta[key][Object.keys(markdownFileDetails.attributes.meta[key])[0]];
}
}
state.lbry = customMetadata;
}
let pageScript = "";
if (path === "glossary") pageScript = "";
if (path === "overview") pageScript = "";
if (path === "playground") pageScript = "";
return html`
${markdownFileDetails.attributes.title}