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:
Triston Armstrong 2023-12-23 20:16:56 -06:00
parent 44c5ca07b2
commit c31428d8e4

View File

@ -1,6 +1,6 @@
import { Node } from "./node" import { Node } from "./node"
import { Transformer } from "./transformer"; 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 path from "path";
@ -79,20 +79,24 @@ export function getSlugHashMap() {
slugMap[aSlug] = aFile slugMap[aSlug] = aFile
}) })
slugMap['index'] = Node.getMarkdownFolder() + "/index.md" const indexFile = "/🌎 Home.md"
slugMap['/'] = Node.getMarkdownFolder() + "/index.md" slugMap['index'] = Node.getMarkdownFolder() + indexFile
slugMap['/'] = Node.getMarkdownFolder() + indexFile
return slugMap return slugMap
} }
export function toSlug(filePath) { 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())) { if (isFile && isMarkdownFolder) {
return filePath.replace(Node.getMarkdownFolder(), '') return filePath.replace(markdownFolder, '')
.replaceAll('/', '__') .replaceAll('/', '_')
.replaceAll(' ', '++++') .replaceAll(' ', '%')
.replaceAll('&', 'ambersand') .replaceAll('&', '+')
.replace('.md', '') .replace('.md', '')
} else { } else {
//TODO handle this properly //TODO handle this properly
@ -215,12 +219,14 @@ export function getLocalGraphData(currentNodeId) {
export function getAllSlugs() { export function getAllSlugs() {
//console.log("\n\nAll Posts are scanning") //console.log("\n\nAll Posts are scanning")
// Get file names under /posts // 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)) return filePaths.map(f => toSlug(f))
} }
export function getDirectoryData() { export function getDirectoryData() {
const filteredDirectory = dirTree(Node.getMarkdownFolder(), {extensions: /\.md/}); const filteredDirectory = dirTree(Node.getMarkdownFolder(), { extensions: /\.md/, exclude: [/\.git/, /\.obsidian/] });
return convertObject(filteredDirectory) return convertObject(filteredDirectory)
} }