Fix pull job links. Canvas now start centered and zoomed out based on nodes positions.

This commit is contained in:
Clément Pons
2025-04-02 17:25:29 +02:00
parent 6100fd9411
commit 2c80cb2456
9 changed files with 103 additions and 47 deletions

View File

@@ -2,7 +2,7 @@ import useDatabase from "~/composables/useDatabase";
import { extname, basename } from 'node:path';
import type { CanvasColor, CanvasContent } from "~/types/canvas";
import type { FileType, ProjectContent } from "#shared/content.util";
import { getID, ID_SIZE } from "#shared/general.util";
import { getID, ID_SIZE, parsePath } from "#shared/general.util";
import { projectContentTable, projectFilesTable } from "~/db/schema";
const typeMapping: Record<string, FileType> = {
@@ -37,7 +37,7 @@ export default defineTask({
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
return {
id: getID(ID_SIZE),
path: path.toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
path: parsePath(path),
order: i,
title: order && order[2] ? order[2] : title,
type: 'folder',
@@ -57,7 +57,7 @@ export default defineTask({
return {
id: getID(ID_SIZE),
path: (extension === '.md' ? path.replace(extension, '') : path).toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
path: parsePath(extension === '.md' ? path.replace(extension, '') : path),
order: i,
title: order && order[2] ? order[2] : title,
type: (typeMapping[extension] ?? 'file'),
@@ -69,6 +69,8 @@ export default defineTask({
}
}));
files.forEach(e => e.content = reshapeLinks(e.content as string | null, files) ?? null);
const db = useDatabase();
db.transaction(tx => {
db.delete(projectFilesTable).run();
@@ -88,14 +90,19 @@ export default defineTask({
},
})
function reshapeLinks(content: string | null, all: ProjectContent[])
{
return content?.replace(/\[\[(.*?)?(#.*?)?(\|.*?)?\]\]/g, (str, link, header, title) => {
return `[[${link ? parsePath(all.find(e => e.path.endsWith(parsePath(link)))?.path ?? parsePath(link)) : ''}${header ?? ''}${title ?? ''}]]`;
});
}
function reshapeContent(content: string, type: FileType): string | null
{
switch(type)
{
case "markdown":
return content.replaceAll(/!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/g, (e: string, a1?: string, a2?: string , a3?: string) => {
return `[[${a1?.split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/') ?? ''}${a2 ?? ''}${a3 ?? ''}]]`;
});
return content;
case "file":
return content;
case "canvas":