fix a few utils bugs
- unified import no longer default import - make index file a variable but also be my actual entry file for my notes - create some variables to make reading easier - cleanup the file/directory replacement characters (what like "++++" which is ridiculous) - lots of formatting changes
This commit is contained in:
parent
44c5ca07b2
commit
c31428d8e4
26
lib/utils.js
26
lib/utils.js
@ -1,6 +1,6 @@
|
||||
import { Node } from "./node"
|
||||
import { Transformer } from "./transformer";
|
||||
import unified from "unified";
|
||||
import { unified } from "unified";
|
||||
import markdown from "remark-parse";
|
||||
import { toString } from 'mdast-util-to-string'
|
||||
import path from "path";
|
||||
@ -79,20 +79,24 @@ export function getSlugHashMap() {
|
||||
slugMap[aSlug] = aFile
|
||||
})
|
||||
|
||||
slugMap['index'] = Node.getMarkdownFolder() + "/index.md"
|
||||
slugMap['/'] = Node.getMarkdownFolder() + "/index.md"
|
||||
const indexFile = "/🌎 Home.md"
|
||||
slugMap['index'] = Node.getMarkdownFolder() + indexFile
|
||||
slugMap['/'] = Node.getMarkdownFolder() + indexFile
|
||||
|
||||
return slugMap
|
||||
}
|
||||
|
||||
|
||||
export function toSlug(filePath) {
|
||||
const markdownFolder = Node.getMarkdownFolder()
|
||||
const isFile = Node.isFile(filePath)
|
||||
const isMarkdownFolder = filePath.includes(markdownFolder)
|
||||
|
||||
if (Node.isFile(filePath) && filePath.includes(Node.getMarkdownFolder())) {
|
||||
return filePath.replace(Node.getMarkdownFolder(), '')
|
||||
.replaceAll('/', '__')
|
||||
.replaceAll(' ', '++++')
|
||||
.replaceAll('&', 'ambersand')
|
||||
if (isFile && isMarkdownFolder) {
|
||||
return filePath.replace(markdownFolder, '')
|
||||
.replaceAll('/', '_')
|
||||
.replaceAll(' ', '%')
|
||||
.replaceAll('&', '+')
|
||||
.replace('.md', '')
|
||||
} else {
|
||||
//TODO handle this properly
|
||||
@ -215,12 +219,14 @@ export function getLocalGraphData(currentNodeId) {
|
||||
export function getAllSlugs() {
|
||||
//console.log("\n\nAll Posts are scanning")
|
||||
// Get file names under /posts
|
||||
const filePaths = Node.getFiles(Node.getMarkdownFolder()).filter(f => !(f.endsWith("index") || f.endsWith("sidebar")))
|
||||
const markdownFolder = Node.getMarkdownFolder()
|
||||
const markdownFiles = Node.getFiles(markdownFolder)
|
||||
const filePaths = markdownFiles.filter(file => !(file.endsWith("index") || file.endsWith("sidebar")))
|
||||
return filePaths.map(f => toSlug(f))
|
||||
}
|
||||
|
||||
export function getDirectoryData() {
|
||||
const filteredDirectory = dirTree(Node.getMarkdownFolder(), {extensions: /\.md/});
|
||||
const filteredDirectory = dirTree(Node.getMarkdownFolder(), { extensions: /\.md/, exclude: [/\.git/, /\.obsidian/] });
|
||||
return convertObject(filteredDirectory)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user