From dbd3da4680ffb97ba45f62f748415f338f08b98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Thu, 11 Oct 2018 17:10:32 -0500 Subject: [PATCH] Some fixes --- app/components/ecosystem/module-lbrycrd.js | 12 +++++++++++- app/components/markdown.js | 22 ++++++++++++++++++---- app/modules/redirect-404.js | 4 ++-- app/views/redirect.js | 7 +++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/components/ecosystem/module-lbrycrd.js b/app/components/ecosystem/module-lbrycrd.js index 744620a..21524ab 100644 --- a/app/components/ecosystem/module-lbrycrd.js +++ b/app/components/ecosystem/module-lbrycrd.js @@ -1,6 +1,16 @@ "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 diff --git a/app/components/markdown.js b/app/components/markdown.js index 9004433..3939fd5 100644 --- a/app/components/markdown.js +++ b/app/components/markdown.js @@ -1,19 +1,28 @@ "use strict"; + + +// P A C K A G E S + import decamelize from "decamelize"; import exists from "fs-exists-sync"; -import fs from "graceful-fs"; import fm from "front-matter"; +import fs from "graceful-fs"; import html from "choo/html"; import path from "path"; import raw from "choo/html/raw"; import { require as local } from "app-root-path"; +// V A R I A B L E + const numberRegex = /^[0-9]/g; + +// U T I L + const md = require("markdown-it")({ html: true, typographer: true -}).use(local("app/modules/markdown-it-sup")) +}).use(local("/app/modules/markdown-it-sup")) .use(require("markdown-it-anchor"), { slugify: 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 markdownFileDetails = fm(markdownFile); const renderedMarkdown = md.render(markdownFileDetails.body); @@ -44,6 +54,10 @@ export default path => { `; }; + + +// H E L P E R + function partialFinder(markdownBody) { const regexToFindPartials = /<\w+ ?\/>/g; const partials = markdownBody.match(regexToFindPartials); @@ -76,7 +90,7 @@ function wikiFinder(markdownBody) { const url = encodeURI("/glossary#" + label.replace(/\s+/g, "-")); return label ? - `${label}` : + `${label}` : match.input; }); } diff --git a/app/modules/redirect-404.js b/app/modules/redirect-404.js index 891e529..52efad7 100644 --- a/app/modules/redirect-404.js +++ b/app/modules/redirect-404.js @@ -9,8 +9,8 @@ import { require as local } from "app-root-path"; // U T I L S -const page404 = local("app/views/404.js"); -const redirects = local("app/data/redirects.json"); +const page404 = local("/app/views/404.js"); +const redirects = local("/app/data/redirects.json"); diff --git a/app/views/redirect.js b/app/views/redirect.js index 708a3c0..b71a211 100644 --- a/app/views/redirect.js +++ b/app/views/redirect.js @@ -12,7 +12,7 @@ import raw from "choo/html/raw"; // 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"); @@ -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 path = `./documents/${partialPath}.md`; - if (!fs.existsSync(path)) { + if (!fs.existsSync(path)) return redirect404(state); - } const markdownFile = fs.readFileSync(path, "utf-8"); const markdownFileDetails = fm(markdownFile); @@ -49,7 +48,7 @@ module.exports = exports = (state, emit) => { // eslint-disable-line if (partialPath === "glossary") pageScript = ""; if (partialPath === "overview") pageScript = ""; if (partialPath === "playground") pageScript = ""; - + // console.log(markdown(path)); return html`