Some fixes

This commit is contained in:
ポール ウェッブ 2018-10-11 17:10:32 -05:00
parent 8a20651804
commit dbd3da4680
4 changed files with 34 additions and 11 deletions

View file

@ -1,6 +1,16 @@
"use strict"; "use strict";
import markdown from "../markdown";
// P A C K A G E
import { require as local } from "app-root-path";
// U T I L
const markdown = local("/app/components/markdown").default;
// E X P O R T // E X P O R T

View file

@ -1,19 +1,28 @@
"use strict"; "use strict";
// P A C K A G E S
import decamelize from "decamelize"; import decamelize from "decamelize";
import exists from "fs-exists-sync"; import exists from "fs-exists-sync";
import fs from "graceful-fs";
import fm from "front-matter"; import fm from "front-matter";
import fs from "graceful-fs";
import html from "choo/html"; import html from "choo/html";
import path from "path"; import path from "path";
import raw from "choo/html/raw"; import raw from "choo/html/raw";
import { require as local } from "app-root-path"; import { require as local } from "app-root-path";
// V A R I A B L E
const numberRegex = /^[0-9]/g; const numberRegex = /^[0-9]/g;
// U T I L
const md = require("markdown-it")({ const md = require("markdown-it")({
html: true, html: true,
typographer: true typographer: true
}).use(local("app/modules/markdown-it-sup")) }).use(local("/app/modules/markdown-it-sup"))
.use(require("markdown-it-anchor"), { .use(require("markdown-it-anchor"), {
slugify: stringToSlugify => { slugify: stringToSlugify => {
let finalString = stringToSlugify let finalString = stringToSlugify
@ -32,8 +41,9 @@ const md = require("markdown-it")({
export default path => { // E X P O R T
export default path => {
const markdownFile = fs.readFileSync(path, "utf-8"); const markdownFile = fs.readFileSync(path, "utf-8");
const markdownFileDetails = fm(markdownFile); const markdownFileDetails = fm(markdownFile);
const renderedMarkdown = md.render(markdownFileDetails.body); const renderedMarkdown = md.render(markdownFileDetails.body);
@ -44,6 +54,10 @@ export default path => {
`; `;
}; };
// H E L P E R
function partialFinder(markdownBody) { function partialFinder(markdownBody) {
const regexToFindPartials = /<\w+ ?\/>/g; const regexToFindPartials = /<\w+ ?\/>/g;
const partials = markdownBody.match(regexToFindPartials); const partials = markdownBody.match(regexToFindPartials);
@ -76,7 +90,7 @@ function wikiFinder(markdownBody) {
const url = encodeURI("/glossary#" + label.replace(/\s+/g, "-")); const url = encodeURI("/glossary#" + label.replace(/\s+/g, "-"));
return label ? return label ?
`<a href="${url}" class="link--glossary">${label}</a>` : `<a class="link--glossary" href="${url}">${label}</a>` :
match.input; match.input;
}); });
} }

View file

@ -9,8 +9,8 @@ import { require as local } from "app-root-path";
// U T I L S // U T I L S
const page404 = local("app/views/404.js"); const page404 = local("/app/views/404.js");
const redirects = local("app/data/redirects.json"); const redirects = local("/app/data/redirects.json");

View file

@ -12,7 +12,7 @@ import raw from "choo/html/raw";
// U T I L S // U T I L S
const markdown = local("/app/components/markdown"); const markdown = local("/app/components/markdown").default;
const redirect404 = local("/app/modules/redirect-404"); const redirect404 = local("/app/modules/redirect-404");
@ -23,9 +23,8 @@ module.exports = exports = (state, emit) => { // eslint-disable-line
const partialPath = state.route === "resources/*" ? `resources/${state.params.wildcard}` : state.params.wildcard; const partialPath = state.route === "resources/*" ? `resources/${state.params.wildcard}` : state.params.wildcard;
const path = `./documents/${partialPath}.md`; const path = `./documents/${partialPath}.md`;
if (!fs.existsSync(path)) { if (!fs.existsSync(path))
return redirect404(state); return redirect404(state);
}
const markdownFile = fs.readFileSync(path, "utf-8"); const markdownFile = fs.readFileSync(path, "utf-8");
const markdownFileDetails = fm(markdownFile); const markdownFileDetails = fm(markdownFile);
@ -49,7 +48,7 @@ module.exports = exports = (state, emit) => { // eslint-disable-line
if (partialPath === "glossary") pageScript = "<script>" + fs.readFileSync("./app/components/client/glossary-scripts.js", "utf-8") + "</script>"; if (partialPath === "glossary") pageScript = "<script>" + fs.readFileSync("./app/components/client/glossary-scripts.js", "utf-8") + "</script>";
if (partialPath === "overview") pageScript = "<script>" + fs.readFileSync("./app/components/client/ecosystem-scripts.js", "utf-8") + "</script>"; if (partialPath === "overview") pageScript = "<script>" + fs.readFileSync("./app/components/client/ecosystem-scripts.js", "utf-8") + "</script>";
if (partialPath === "playground") pageScript = "<script>" + fs.readFileSync("./app/components/client/playground-scripts.js", "utf-8") + "</script>"; if (partialPath === "playground") pageScript = "<script>" + fs.readFileSync("./app/components/client/playground-scripts.js", "utf-8") + "</script>";
// console.log(markdown(path));
return html` return html`
<article class="page" itemtype="http://schema.org/BlogPosting"> <article class="page" itemtype="http://schema.org/BlogPosting">
<header class="page__header"> <header class="page__header">