Fix pull job and link rewrite

This commit is contained in:
Peaceultime 2025-04-18 20:10:21 +02:00
parent e7d0d69e55
commit e5b53585aa
3 changed files with 28 additions and 26 deletions

View File

@ -2,8 +2,8 @@
<NuxtLink class="text-accent-blue inline-flex items-center" :to="overview ? { name: 'explore-path', params: { path: overview.path }, hash: hash } : href" :class="class"> <NuxtLink class="text-accent-blue inline-flex items-center" :to="overview ? { name: 'explore-path', params: { path: overview.path }, hash: hash } : href" :class="class">
<HoverCard nuxt-client class="max-w-[600px] max-h-[600px] w-full overflow-auto z-[45]" :class="{'overflow-hidden !p-0': overview?.type === 'canvas'}" :disabled="!overview"> <HoverCard nuxt-client class="max-w-[600px] max-h-[600px] w-full overflow-auto z-[45]" :class="{'overflow-hidden !p-0': overview?.type === 'canvas'}" :disabled="!overview">
<template #content> <template #content>
<Markdown v-if="overview?.type === 'markdown'" class="!px-6" :path="pathname" :filter="hash.substring(1)" popover /> <Markdown v-if="overview?.type === 'markdown'" class="!px-6" :path="decodeURIComponent(pathname)" :filter="hash.substring(1)" popover />
<template v-else-if="overview?.type === 'canvas'"><div class="w-[600px] h-[600px] relative"><Canvas :path="pathname" /></div></template> <template v-else-if="overview?.type === 'canvas'"><div class="w-[600px] h-[600px] relative"><Canvas :path="decodeURIComponent(pathname)" /></div></template>
</template> </template>
<span> <span>
<slot v-bind="$attrs"></slot> <slot v-bind="$attrs"></slot>
@ -26,7 +26,7 @@ const { href } = defineProps<{
const { hash, pathname } = parseURL(href); const { hash, pathname } = parseURL(href);
const { content } = useContent(); const { content } = useContent();
const overview = computed(() => content.value.find(e => e.path === pathname)); const overview = computed(() => content.value.find(e => e.path === decodeURIComponent(pathname)));
</script> </script>
<style> <style>

View File

@ -4,6 +4,7 @@ import type { FileType } from '~/types/content';
import type { CanvasColor, CanvasContent } from "~/types/canvas"; import type { CanvasColor, CanvasContent } from "~/types/canvas";
import { explorerContentTable } from "~/db/schema"; import { explorerContentTable } from "~/db/schema";
import { convertToStorableLinks } from "../api/file.post"; import { convertToStorableLinks } from "../api/file.post";
import { parsePath } from "~/shared/general.util";
const typeMapping: Record<string, FileType> = { const typeMapping: Record<string, FileType> = {
".md": "markdown", ".md": "markdown",
@ -17,6 +18,7 @@ export default defineTask({
}, },
async run(event) { async run(event) {
try { try {
//@ts-ignore
const tree = await $fetch('https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/git/trees/master', { const tree = await $fetch('https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/git/trees/master', {
method: 'get', method: 'get',
headers: { headers: {
@ -33,44 +35,41 @@ export default defineTask({
{ {
const title = basename(e.path); const title = basename(e.path);
const order = /(\d+)\. ?(.+)/gsmi.exec(title); const order = /(\d+)\. ?(.+)/gsmi.exec(title);
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
return { return {
path: path.toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""), path: e.path,
order: i, order: i,
title: order && order[2] ? order[2] : title, title: title,
type: 'folder', type: 'folder',
content: null, content: null,
owner: '1', owner: 1,
navigable: true, navigable: true,
private: e.path.startsWith('98.Privé'), private: e.path === '98. Privé',
timestamp: new Date(),
} }
} }
const extension = extname(e.path); const extension = extname(e.path);
const title = basename(e.path, extension); const title = basename(e.path, extension);
const order = /(\d+)\. ?(.+)/gsmi.exec(title); const order = /(\d+)\. ?(.+)/gsmi.exec(title);
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
const content = (await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`)); const content = (await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`));
return { return {
path: (extension === '.md' ? path.replace(extension, '') : path).toLowerCase().replaceAll(" ", "-").normalize("NFD").replace(/[\u0300-\u036f]/g, ""), path: extension === '.md' ? e.path.replace(extension, '') : e.path,
order: i, order: i,
title: order && order[2] ? order[2] : title, title: title,
type: (typeMapping[extension] ?? 'file'), type: (typeMapping[extension] ?? 'file'),
content: reshapeContent(content as string, typeMapping[extension] ?? 'File'), content: reshapeContent(content as string, typeMapping[extension] ?? 'File'),
owner: '1', owner: 1,
navigable: true, navigable: true,
private: e.path.startsWith('98.Privé') private: e.path === '98. Privé',
timestamp: new Date(),
} }
})); }));
const pathList = files.map(e => e.path);
files.forEach(e => { files.forEach(e => {
if(e.type !== 'folder' && e.content) const content = reshapeLinks(e.content as string | null, files) ?? null;
{ e.content = content ? Buffer.from(content, 'utf-8') : null;
e.content = Buffer.from(convertToStorableLinks(e.content.toString('utf-8'), files.map(e => e.path)), 'utf-8'); });
}
})
const db = useDatabase(); const db = useDatabase();
db.delete(explorerContentTable).run(); db.delete(explorerContentTable).run();
@ -86,21 +85,24 @@ export default defineTask({
} }
}, },
}) })
function reshapeLinks(content: string | null, all: typeof explorerContentTable.$inferInsert[])
{
return content?.replace(/!?\[\[([^\[\]\|\#]+)?(#+[^\[\]\|\#]+)?(\|[^\[\]\|\#]+)?\]\]/g, (str, link, header, title) => {
return `[[${link ? all.find(e => e.path.endsWith(link))?.path ?? link : ''}${header ?? ''}${title ?? ''}]]`;
});
}
function reshapeContent(content: string, type: FileType): string | null function reshapeContent(content: string, type: FileType): string | null
{ {
switch(type) switch(type)
{ {
case "markdown": 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 ?? ''}]]`;
});
case "file": case "file":
return content; return content;
case "canvas": case "canvas":
const data = JSON.parse(content) as CanvasContent; const data = JSON.parse(content) as CanvasContent;
data.edges.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined); data.edges?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
data.nodes.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined); data.nodes?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
return JSON.stringify(data); return JSON.stringify(data);
default: default:
case 'folder': case 'folder':

View File

@ -14,7 +14,7 @@ export function unifySlug(slug: string | string[]): string
} }
export function parsePath(path: string): string export function parsePath(path: string): string
{ {
return path.toLowerCase().replaceAll(" ", "-").normalize("NFD").replaceAll(/[\u0300-\u036f]/g, "").replaceAll('(', '').replaceAll(')', ''); return path.toLowerCase().trim().replaceAll(" ", "-").normalize("NFD").replaceAll(/[\u0300-\u036f]/g, "").replaceAll('(', '').replaceAll(')', '');
} }
export function parseId(id: string | undefined): string |undefined export function parseId(id: string | undefined): string |undefined
{ {