import type { PageLoad } from './$types';
import { errorMsg, server } from '../../../../helpers';
import hljs from 'highlight.js';
export const load: PageLoad = async ({ fetch, params }) => {
const u = params.pos
? `${server}/api/tree/${params.user}/${params.repo}?pos=${params.pos}`
: `${server}/api/tree/${params.user}/${params.repo}`;
console.log('url', u);
const resp = await fetch(u, { credentials: 'include' });
if (resp.status == 200) {
const y = await resp.json();
console.log('y', y);
if (y.inode.File?.file) {
console.log('highlighting');
try {
const sp = y.inode.File.path[y.inode.File.path.length - 1].basename.split('.');
const result = hljs.highlight(y.inode.File.file, { language: sp[sp.length - 1] });
y.hled = result.value;
} catch (e) {
console.error(e);
y.hled = y.inode.File.file;
}
}
return y;
} else {
const y = await resp.json();
errorMsg(resp.status, y);
}
};