ref: update semtree; update semtree impl.

This commit is contained in:
manunamz
2024-09-02 11:56:15 -04:00
parent 7d7eddfa73
commit 06ebc36941
3 changed files with 66 additions and 46 deletions
+1 -1
View File
@@ -28,7 +28,7 @@
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"remark-caml": "^0.0.6-rm", "remark-caml": "^0.0.6-rm",
"remark-wikirefs": "^0.0.7-rm", "remark-wikirefs": "^0.0.7-rm",
"semtree": "^0.0.4", "semtree": "^0.0.12",
"unist-util-select": "^5.0.0", "unist-util-select": "^5.0.0",
"wikirefs": "^0.0.4" "wikirefs": "^0.0.4"
} }
+28 -17
View File
@@ -1,14 +1,17 @@
import type { SemTree } from 'semtree';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import path from 'path'; import path from 'path';
import { SemTree } from 'semtree'; import * as semtree from 'semtree';
export async function buildBonsai() { export async function buildBonsai(): Promise<SemTree | undefined> {
// init vars // init vars
const bonsai = new SemTree({ const opts = {
// if set to 'false', make sure to extract urls of index docs below // if set to 'false', make sure to extract urls of index docs below
virtualTrunk: true, virtualTrunk: true,
}); // semtree options: https://github.com/wikibonsai/semtree?tab=readme-ov-file#options
};
const bonsaiText: any = {}; // { filename: content } hash const bonsaiText: any = {}; // { filename: content } hash
const rootFilename: string = 'i.bonsai'; const rootFilename: string = 'i.bonsai';
// build 'bonsaiText' hash // build 'bonsaiText' hash
@@ -16,10 +19,13 @@ export async function buildBonsai() {
allIndexDocs.forEach((doc: any) => { // remove preceding/trailing newlines/whitespace allIndexDocs.forEach((doc: any) => { // remove preceding/trailing newlines/whitespace
bonsaiText[path.basename(doc.id, '.md')] = doc.body.replace(/^\s+|\s+$/g, ''); bonsaiText[path.basename(doc.id, '.md')] = doc.body.replace(/^\s+|\s+$/g, '');
}); });
let res; let bonsai: SemTree | string = 'uninitialized bonsai';
try { try {
// build bonsai tree data struct // build bonsai tree data struct
res = bonsai.parse(bonsaiText, rootFilename); bonsai = semtree.create(rootFilename, bonsaiText, opts);
if (typeof bonsai === 'string') {
throw new Error(bonsai);
} else {
// append url for template rendering and init fam metadata // append url for template rendering and init fam metadata
const allEntryDocs = await getCollection('entries'); const allEntryDocs = await getCollection('entries');
for (const node of bonsai.nodes) { for (const node of bonsai.nodes) {
@@ -43,19 +49,24 @@ export async function buildBonsai() {
// node.url = '/blog/' + doc.slug; // node.url = '/blog/' + doc.slug;
// } // }
// } // }
return bonsai;
} catch (e) {
console.error(e, res);
}
if (bonsai.duplicates.length > 0) {
console.log('bonsai duplicates: ' + bonsai.duplicates);
} else {
console.log('bonsai: \n' console.log('bonsai: \n'
+ 'res: ' + JSON.stringify(res) + '\n' + '\n---\n'
+ 'root: ' + bonsai.root + '\n' + 'root: ' + bonsai.root
+ 'duplicates: ' + bonsai.duplicates + '\n---\n'
+ 'trunk: ' + bonsai.trunk
+ '\n---\n'
+ 'petioleMap: ' + JSON.stringify(bonsai.petioleMap)
+ '\n---\n'
+ 'orphans: ' + bonsai.orphans
+ '\n---\n'
+ 'nodes: ' + JSON.stringify(bonsai.nodes)
+ '\n---\n'
); );
return bonsai;
}
} catch (e) {
console.error(e, bonsai);
} }
} }
export const bonsai = await buildBonsai(); export const bonsai: SemTree | undefined = await buildBonsai();
+15 -6
View File
@@ -2676,7 +2676,7 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
nanoid@^3.3.4, nanoid@^3.3.6: nanoid@^3.3.6:
version "3.3.6" version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
@@ -3211,12 +3211,14 @@ section-matter@^1.0.0:
extend-shallow "^2.0.1" extend-shallow "^2.0.1"
kind-of "^6.0.0" kind-of "^6.0.0"
semtree@^0.0.4: semtree@^0.0.12:
version "0.0.4" version "0.0.12"
resolved "https://registry.yarnpkg.com/semtree/-/semtree-0.0.4.tgz#2c22727524ad4af4e5c8758a7a7908a79b627abf" resolved "https://registry.yarnpkg.com/semtree/-/semtree-0.0.12.tgz#a942285774b37862383fb51604359cee49d8a477"
integrity sha512-JUGAa9KLpFLMvPzR1+OA++wL6tGJN71LL5Z6KT5YJVYUn9kBUv2FY5SYvo4tR5aLssO+BWDyoXyMy416SeZawA== integrity sha512-CAsJk4DwmVcr8hsxSXYH3rQNVkr0tAepO5FnJ3T3v8unZ6hhWKI0PWmGiaIPx+S/uti8BExUZDpA3jmQXij9Tg==
dependencies: dependencies:
nanoid "^3.3.4" caml-mkdn "^0.0.2"
gray-matter "^4.0.3"
wikirefs "^0.0.5"
semver@^6.3.1: semver@^6.3.1:
version "6.3.1" version "6.3.1"
@@ -3821,6 +3823,13 @@ wikirefs@^0.0.4:
dependencies: dependencies:
escape-mkdn "^0.0.3" escape-mkdn "^0.0.3"
wikirefs@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/wikirefs/-/wikirefs-0.0.5.tgz#78a097a72ac6a0a5215c9be753c9e27643d70a17"
integrity sha512-wxGl7+XC+f4/dfhf9Z2J+dozgHDZoKvX6UpHRohQyTKDHIxfFMdoN3pDx9ySFNG5vC0xQXF9iIfPhLUwKXjXVg==
dependencies:
escape-mkdn "^0.0.3"
wrap-ansi@^8.1.0: wrap-ansi@^8.1.0:
version "8.1.0" version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"