fix the unified import - no longer default import
This commit is contained in:
parent
0f845a3218
commit
44c5ca07b2
@ -1,20 +1,20 @@
|
|||||||
import matter from 'gray-matter'
|
import matter from 'gray-matter'
|
||||||
import unified from "unified";
|
import { unified } from "unified";
|
||||||
import markdown from "remark-parse";
|
import markdown from "remark-parse";
|
||||||
import {wikiLinkPlugin} from "remark-wiki-link";
|
import { wikiLinkPlugin } from "remark-wiki-link";
|
||||||
import html from "remark-html";
|
import html from "remark-html";
|
||||||
import frontmatter from "remark-frontmatter";
|
import frontmatter from "remark-frontmatter";
|
||||||
import externalLinks from "remark-external-links";
|
import externalLinks from "remark-external-links";
|
||||||
import highlight from "remark-highlight.js";
|
import highlight from "remark-highlight.js";
|
||||||
import {Node} from "./node";
|
import { Node } from "./node";
|
||||||
import rehypePrism from 'rehype-prism-plus'
|
import rehypePrism from 'rehype-prism-plus'
|
||||||
import remarkRehype from 'remark-rehype'
|
import remarkRehype from 'remark-rehype'
|
||||||
import rehypeStringify from 'rehype-stringify'
|
import rehypeStringify from 'rehype-stringify'
|
||||||
import obsidianImage from './obsidian-image.js'
|
import obsidianImage from './obsidian-image.js'
|
||||||
import {getAllMarkdownFiles, toFilePath, toSlug} from "./utils";
|
import { getAllMarkdownFiles, toFilePath, toSlug } from "./utils";
|
||||||
|
|
||||||
export const Transformer = {
|
export const Transformer = {
|
||||||
haveFrontMatter: function (content) {
|
haveFrontMatter: function(content) {
|
||||||
//console.log("\t Front matter data content", content)
|
//console.log("\t Front matter data content", content)
|
||||||
if (!content) return false
|
if (!content) return false
|
||||||
const indexOfFirst = content.indexOf("---");
|
const indexOfFirst = content.indexOf("---");
|
||||||
@ -27,7 +27,7 @@ export const Transformer = {
|
|||||||
return indexOfSecond !== -1;
|
return indexOfSecond !== -1;
|
||||||
|
|
||||||
},
|
},
|
||||||
getFrontMatterData: function (filecontent) {
|
getFrontMatterData: function(filecontent) {
|
||||||
if (Transformer.haveFrontMatter(filecontent)) {
|
if (Transformer.haveFrontMatter(filecontent)) {
|
||||||
return matter(filecontent).data
|
return matter(filecontent).data
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ export const Transformer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
pageResolver: function (pageName) {
|
pageResolver: function(pageName) {
|
||||||
const allFileNames = getAllMarkdownFiles()
|
const allFileNames = getAllMarkdownFiles()
|
||||||
const result = allFileNames.find(aFile => {
|
const result = allFileNames.find(aFile => {
|
||||||
let parseFileNameFromPath = Transformer.parseFileNameFromPath(aFile);
|
let parseFileNameFromPath = Transformer.parseFileNameFromPath(aFile);
|
||||||
@ -52,26 +52,26 @@ export const Transformer = {
|
|||||||
// console.log("Internal Link resolved: [" + pageName + "] ==> [" + temp[0] +"]")
|
// console.log("Internal Link resolved: [" + pageName + "] ==> [" + temp[0] +"]")
|
||||||
return (result !== undefined && result.length > 0) ? [toSlug(result)] : ["/"]
|
return (result !== undefined && result.length > 0) ? [toSlug(result)] : ["/"]
|
||||||
},
|
},
|
||||||
hrefTemplate: function (permalink) {
|
hrefTemplate: function(permalink) {
|
||||||
// permalink = Transformer.normalizeFileName(permalink)
|
// permalink = Transformer.normalizeFileName(permalink)
|
||||||
permalink = permalink.replace("ç", "c").replace("ı", "i").replace("ş", "s")
|
permalink = permalink.replace("ç", "c").replace("ı", "i").replace("ş", "s")
|
||||||
return `/note/${permalink}`;
|
return `/note/${permalink}`;
|
||||||
}, getHtmlContent: function (content) {
|
}, getHtmlContent: function(content) {
|
||||||
let htmlContent = []
|
let htmlContent = []
|
||||||
const sanitizedContent = Transformer.preprocessThreeDashes(content)
|
const sanitizedContent = Transformer.preprocessThreeDashes(content)
|
||||||
|
|
||||||
unified()
|
unified()
|
||||||
.use(markdown, {gfm: true})
|
.use(markdown, { gfm: true })
|
||||||
.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) {
|
||||||
return Transformer.pageResolver(pageName)
|
return Transformer.pageResolver(pageName)
|
||||||
},
|
},
|
||||||
hrefTemplate: function (permalink) {
|
hrefTemplate: function(permalink) {
|
||||||
return Transformer.hrefTemplate(permalink);
|
return Transformer.hrefTemplate(permalink);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ export const Transformer = {
|
|||||||
.use(rehypePrism)
|
.use(rehypePrism)
|
||||||
.use(rehypeStringify)
|
.use(rehypeStringify)
|
||||||
.process(sanitizedContent,
|
.process(sanitizedContent,
|
||||||
function (err, file) {
|
function(err, file) {
|
||||||
htmlContent.push(String(file).replace("\n", ""))
|
htmlContent.push(String(file).replace("\n", ""))
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("ERRROR:" + err)
|
console.log("ERRROR:" + err)
|
||||||
@ -94,7 +94,7 @@ export const Transformer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* SANITIZE MARKDOWN FOR --- */
|
/* SANITIZE MARKDOWN FOR --- */
|
||||||
preprocessThreeDashes: function (content) {
|
preprocessThreeDashes: function(content) {
|
||||||
const indexOfFirst = content.indexOf("---");
|
const indexOfFirst = content.indexOf("---");
|
||||||
if (indexOfFirst === -1) {
|
if (indexOfFirst === -1) {
|
||||||
return content
|
return content
|
||||||
@ -106,7 +106,7 @@ export const Transformer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* Normalize File Names */
|
/* Normalize File Names */
|
||||||
normalizeFileName: function (filename) {
|
normalizeFileName: function(filename) {
|
||||||
let processedFileName = filename.replace(".md", "");
|
let processedFileName = filename.replace(".md", "");
|
||||||
processedFileName = processedFileName.replace('(', '').replace(')', '')
|
processedFileName = processedFileName.replace('(', '').replace(')', '')
|
||||||
processedFileName = processedFileName.split(" ").join("-")
|
processedFileName = processedFileName.split(" ").join("-")
|
||||||
@ -125,8 +125,8 @@ export const Transformer = {
|
|||||||
return processedFileName
|
return processedFileName
|
||||||
},
|
},
|
||||||
/* Parse file name from path then sanitize it */
|
/* Parse file name from path then sanitize it */
|
||||||
parseFileNameFromPath: function (filepath) {
|
parseFileNameFromPath: function(filepath) {
|
||||||
if (typeof filepath ==='string' && filepath.includes("/")) {
|
if (typeof filepath === 'string' && filepath.includes("/")) {
|
||||||
const parsedFileFromPath = filepath.split("/")[filepath.split("/").length - 1]
|
const parsedFileFromPath = filepath.split("/")[filepath.split("/").length - 1]
|
||||||
return parsedFileFromPath.replace(".md", "")
|
return parsedFileFromPath.replace(".md", "")
|
||||||
} else {
|
} else {
|
||||||
@ -135,14 +135,14 @@ export const Transformer = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* Pair provided and existing Filenames*/
|
/* Pair provided and existing Filenames*/
|
||||||
getInternalLinks: function (aFilePath) {
|
getInternalLinks: function(aFilePath) {
|
||||||
const fileContent = Node.readFileSync(aFilePath);
|
const fileContent = Node.readFileSync(aFilePath);
|
||||||
const internalLinks = []
|
const internalLinks = []
|
||||||
const sanitizedContent = Transformer.preprocessThreeDashes(fileContent)
|
const sanitizedContent = Transformer.preprocessThreeDashes(fileContent)
|
||||||
unified()
|
unified()
|
||||||
.use(markdown, {gfm: true})
|
.use(markdown, { gfm: true })
|
||||||
.use(wikiLinkPlugin, {
|
.use(wikiLinkPlugin, {
|
||||||
pageResolver: function (pageName) {
|
pageResolver: function(pageName) {
|
||||||
|
|
||||||
// let name = [Transformer.parseFileNameFromPath(pageName)];
|
// let name = [Transformer.parseFileNameFromPath(pageName)];
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ export const Transformer = {
|
|||||||
// Meaning it in form of #Heading1 --> slug will be this file slug
|
// Meaning it in form of #Heading1 --> slug will be this file slug
|
||||||
canonicalSlug = toSlug(aFilePath)
|
canonicalSlug = toSlug(aFilePath)
|
||||||
} else {
|
} else {
|
||||||
canonicalSlug =Transformer.pageResolver(tempSlug)[0].split('#')[0]
|
canonicalSlug = Transformer.pageResolver(tempSlug)[0].split('#')[0]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
canonicalSlug = Transformer.pageResolver(pageName)[0].split('#')[0]
|
canonicalSlug = Transformer.pageResolver(pageName)[0].split('#')[0]
|
||||||
@ -174,7 +174,7 @@ export const Transformer = {
|
|||||||
return [canonicalSlug]
|
return [canonicalSlug]
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
hrefTemplate: function (permalink) {
|
hrefTemplate: function(permalink) {
|
||||||
return Transformer.hrefTemplate(permalink)
|
return Transformer.hrefTemplate(permalink)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user