implement the second part of the sharejs

This commit is contained in:
Wael Nasreddine 2025-12-25 22:06:30 -08:00
parent afcd23cb99
commit 8368969932
2 changed files with 17 additions and 3 deletions

View File

@ -295,6 +295,14 @@ async function exportToZip(taskContext: TaskContext<"export">, branch: BBranch,
return url ? `href="${url}"` : match;
});
if (format === "share") {
content = content.replace(/src="[^"]*api\/notes\/([a-zA-Z0-9_]+)\/download"/g, (match, targetNoteId) => {
const url = getNoteTargetUrl(targetNoteId, noteMeta);
return url ? `src="${url}"` : match;
});
}
return content;
function findAttachment(targetAttachmentId: string) {

View File

@ -73,6 +73,14 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
note: parentBranch.getNote()
};
// Determine JS to load.
const jsToLoad: string[] = [
`${basePath}assets/scripts.js`
];
for (const jsRelation of note.getRelations("shareJs")) {
jsToLoad.push(`api/notes/${jsRelation.value}/download`);
}
return renderNoteContentInternal(note, {
subRoot,
rootNoteId: parentBranch.noteId,
@ -80,9 +88,7 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
`${basePath}assets/styles.css`,
`${basePath}assets/scripts.css`,
],
jsToLoad: [
`${basePath}assets/scripts.js`
],
jsToLoad,
logoUrl: `${basePath}icon-color.svg`,
faviconUrl: `${basePath}favicon.ico`,
ancestors,