Remove troublesome FrontMatter pluggin (temporarily)

Cached graph-data, which result in hugely improved build performance and probably browsing experience as well
This commit is contained in:
Tuan Cao 2022-04-29 15:35:10 +07:00
parent 1a11bdb2b0
commit 233e5ba4ed
2 changed files with 40 additions and 31 deletions

View File

@ -65,7 +65,7 @@ export const Transformer = {
.use(obsidianImage) .use(obsidianImage)
.use(highlight) .use(highlight)
.use(externalLinks, {target: "_blank", rel: ['noopener']}) .use(externalLinks, {target: "_blank", rel: ['noopener']})
.use(frontmatter, ['yaml', 'toml']) // .use(frontmatter, ['yaml', 'toml'])
.use(wikiLinkPlugin, { .use(wikiLinkPlugin, {
permalinks: null, permalinks: null,
pageResolver: function (pageName) { pageResolver: function (pageName) {

View File

@ -3,6 +3,8 @@ import {Transformer} from "./transformer";
import unified from "unified"; import unified from "unified";
import markdown from "remark-parse"; import markdown from "remark-parse";
import {toString} from 'mdast-util-to-string' import {toString} from 'mdast-util-to-string'
import path from "path";
import fs from "fs";
const dirTree = require("directory-tree"); const dirTree = require("directory-tree");
@ -46,7 +48,7 @@ export function getSinglePost(slug) {
//console.log("hrmlcontents and backlinks") //console.log("hrmlcontents and backlinks")
return { return {
id: slug, id: slug,
...currentFileFrontMatter, // ...currentFileFrontMatter,
data: htmlContent, data: htmlContent,
} }
@ -100,41 +102,48 @@ export function toSlug(filePath) {
} }
export function constructGraphData() { export function constructGraphData() {
const filePaths = getAllMarkdownFiles(); const filepath = path.join(process.cwd(), "graph-data.json");
const edges = [] if (Node.isFile(filepath)) {
const nodes = [] const data = fs.readFileSync(filepath);
return JSON.parse(String(data))
} else {
const filePaths = getAllMarkdownFiles();
const edges = []
const nodes = []
filePaths
.forEach(aFilePath => {
// const {currentFilePath} = getFileNames(filename)
const aNode = {
title: Transformer.parseFileNameFromPath(aFilePath),
slug: toSlug(aFilePath),
shortSummary: getShortSummary(toSlug(aFilePath))
}
nodes.push(aNode)
filePaths // console.log("Constructing graph for node: " + aFilePath )
.forEach(aFilePath => { const internalLinks = Transformer.getInternalLinks(aFilePath)
// const {currentFilePath} = getFileNames(filename) internalLinks.forEach(aLink => {
const aNode = {
title: Transformer.parseFileNameFromPath(aFilePath),
slug: toSlug(aFilePath),
shortSummary: getShortSummary(toSlug(aFilePath))
}
nodes.push(aNode)
// console.log("Constructing graph for node: " + aFilePath ) if (aLink.slug === null || aLink.slug.length === 0) return
const internalLinks = Transformer.getInternalLinks(aFilePath)
internalLinks.forEach(aLink => {
if (aLink.slug === null || aLink.slug.length === 0) return const anEdge = {
source: toSlug(aFilePath),
const anEdge = { target: aLink.slug,
source: toSlug(aFilePath), }
target: aLink.slug, edges.push(anEdge)
// console.log("Source: " + anEdge.source)
// console.log("Target: " + anEdge.target)
})
// console.log("==============Constructing graph" )
} }
edges.push(anEdge) )
// console.log("Source: " + anEdge.source) const data = {nodes, edges};
// console.log("Target: " + anEdge.target) fs.writeFileSync(filepath, JSON.stringify(data), "utf-8");
}) return data;
// console.log("==============Constructing graph" ) }
}
)
return {nodes, edges};
} }