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
38
lib/utils.js
38
lib/utils.js
@ -1,8 +1,8 @@
|
||||
import {Node} from "./node"
|
||||
import {Transformer} from "./transformer";
|
||||
import unified from "unified";
|
||||
import { Node } from "./node"
|
||||
import { Transformer } from "./transformer";
|
||||
import { unified } from "unified";
|
||||
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";
|
||||
|
||||
@ -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
|
||||
@ -140,7 +144,7 @@ export function constructGraphData() {
|
||||
// console.log("==============Constructing graph" )
|
||||
}
|
||||
)
|
||||
const data = {nodes, edges};
|
||||
const data = { nodes, edges };
|
||||
fs.writeFileSync(filepath, JSON.stringify(data), "utf-8");
|
||||
return data;
|
||||
}
|
||||
@ -149,7 +153,7 @@ export function constructGraphData() {
|
||||
|
||||
export function getLocalGraphData(currentNodeId) {
|
||||
|
||||
const {nodes, edges} = constructGraphData()
|
||||
const { nodes, edges } = constructGraphData()
|
||||
|
||||
const newNodes = nodes.map(aNode => (
|
||||
{
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -254,7 +260,7 @@ export function convertObject(thisObject) {
|
||||
|
||||
function flat(array) {
|
||||
var result = [];
|
||||
array.forEach(function (a) {
|
||||
array.forEach(function(a) {
|
||||
result.push(a);
|
||||
if (Array.isArray(a.children)) {
|
||||
result = result.concat(flat(a.children));
|
||||
|
Loading…
Reference in New Issue
Block a user