Tweaks
parent
799144a74e
commit
6fe05c1b13
|
@ -43,6 +43,10 @@ export async function compile(
|
||||||
external: excludeModules,
|
external: excludeModules,
|
||||||
loader: {
|
loader: {
|
||||||
".css": "text",
|
".css": "text",
|
||||||
|
".md": "text",
|
||||||
|
".txt": "text",
|
||||||
|
".html": "text",
|
||||||
|
".hbs": "text",
|
||||||
".png": "dataurl",
|
".png": "dataurl",
|
||||||
".gif": "dataurl",
|
".gif": "dataurl",
|
||||||
".jpg": "dataurl",
|
".jpg": "dataurl",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { readdir, readFile, stat, writeFile, unlink } from "fs/promises";
|
import { readdir, readFile, stat, writeFile, unlink, mkdir } from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import type { SysCallMapping } from "../system";
|
import type { SysCallMapping } from "../system";
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ export default function fileSystemSyscalls(root: string = "/"): SysCallMapping {
|
||||||
text: string
|
text: string
|
||||||
): Promise<FileMeta> => {
|
): Promise<FileMeta> => {
|
||||||
let p = resolvedPath(filePath);
|
let p = resolvedPath(filePath);
|
||||||
|
await mkdir(path.dirname(p), { recursive: true });
|
||||||
await writeFile(p, text);
|
await writeFile(p, text);
|
||||||
let s = await stat(p);
|
let s = await stat(p);
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { findNodeOfType, ParseTree, renderToText, replaceNodesMatching, traverseTree } from "@silverbulletmd/common/tree";
|
import { findNodeOfType, traverseTree } from "@silverbulletmd/common/tree";
|
||||||
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
|
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
|
||||||
import { readPage, writePage } from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
import {
|
||||||
|
readPage,
|
||||||
|
writePage,
|
||||||
|
} from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
|
|
||||||
export async function readYamlPage(
|
export async function readYamlPage(
|
||||||
|
@ -40,3 +43,11 @@ export async function readYamlPage(
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function writeYamlPage(
|
||||||
|
pageName: string,
|
||||||
|
data: any
|
||||||
|
): Promise<void> {
|
||||||
|
const text = YAML.stringify(data);
|
||||||
|
await writePage(pageName, "```yaml\n" + text + "\n```");
|
||||||
|
}
|
||||||
|
|
|
@ -9,20 +9,38 @@ export function encodePageUrl(name: string): string {
|
||||||
return name.replaceAll(" ", "_");
|
return name.replaceAll(" ", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanMarkdown(text: string): Promise<string> {
|
export async function cleanMarkdown(
|
||||||
|
text: string,
|
||||||
|
validPages?: string[]
|
||||||
|
): Promise<string> {
|
||||||
let mdTree = await parseMarkdown(text);
|
let mdTree = await parseMarkdown(text);
|
||||||
replaceNodesMatching(mdTree, (n) => {
|
replaceNodesMatching(mdTree, (n) => {
|
||||||
if (n.type === "WikiLink") {
|
if (n.type === "WikiLink") {
|
||||||
const page = n.children![1].children![0].text!;
|
const page = n.children![1].children![0].text!;
|
||||||
|
if (validPages && !validPages.includes(page)) {
|
||||||
|
return {
|
||||||
|
// HACK
|
||||||
|
text: `_${page}_`,
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
// HACK
|
// HACK
|
||||||
text: `[${page}](/${encodePageUrl(page)})`,
|
text: `[${page}](/${encodePageUrl(page)})`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Simply get rid of these
|
// Simply get rid of these
|
||||||
if (n.type === "CommentBlock" || n.type === "Comment") {
|
if (
|
||||||
|
n.type === "CommentBlock" ||
|
||||||
|
n.type === "Comment" ||
|
||||||
|
n.type === "NamedAnchor"
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (n.type === "Hashtag") {
|
||||||
|
return {
|
||||||
|
text: `__${n.children![0].text}__`,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (n.type === "FencedCode") {
|
if (n.type === "FencedCode") {
|
||||||
let codeInfoNode = findNodeOfType(n, "CodeInfo");
|
let codeInfoNode = findNodeOfType(n, "CodeInfo");
|
||||||
if (!codeInfoNode) {
|
if (!codeInfoNode) {
|
||||||
|
|
Loading…
Reference in New Issue