diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts
index 3e9e8db18..819f7bbe6 100644
--- a/apps/server/src/share/content_renderer.ts
+++ b/apps/server/src/share/content_renderer.ts
@@ -47,15 +47,14 @@ function addContentAccessQuery(note: SNote | BNote, secondEl?:boolean) {
return ""
}
-function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {
+export function getSharedSubTreeRoot(note: SNote | BNote | undefined, parentId: string | undefined = undefined): Subroot {
if (!note || note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
// share root itself is not shared
return {};
}
- // every path leads to share root, but which one to choose?
- // for the sake of simplicity, URLs are not note paths
- const parentBranch = note.getParentBranches()[0];
+ const parentBranches = note.getParentBranches()
+ const parentBranch = (parentId ? parentBranches.find((pb: SBranch | BBranch) => pb.parentNoteId === parentId) : undefined) || parentBranches[0];
if (note instanceof BNote) {
return {
@@ -71,7 +70,7 @@ function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {
};
}
- return getSharedSubTreeRoot(parentBranch.getParentNote());
+ return getSharedSubTreeRoot(parentBranch.getParentNote(), parentId);
}
export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath: string, ancestors: string[]) {
@@ -98,7 +97,7 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
}
export function renderNoteContent(note: SNote) {
- const subRoot = getSharedSubTreeRoot(note);
+ const subRoot = getSharedSubTreeRoot(note, note.parentId);
const ancestors: string[] = [];
let notePointer = note;
@@ -114,23 +113,23 @@ export function renderNoteContent(note: SNote) {
// Determine CSS to load.
const cssToLoad: string[] = [];
if (!note.isLabelTruthy("shareOmitDefaultCss")) {
- cssToLoad.push(`assets/styles.css`);
- cssToLoad.push(`assets/scripts.css`);
+ cssToLoad.push(`../assets/styles.css`);
+ cssToLoad.push(`../assets/scripts.css`);
}
for (const cssRelation of note.getRelations("shareCss")) {
- cssToLoad.push(`api/notes/${cssRelation.value}/download${addContentAccessQuery(note)}`);
+ cssToLoad.push(`../api/notes/${cssRelation.value}/download${addContentAccessQuery(note)}`);
}
// Determine JS to load.
const jsToLoad: string[] = [
- "assets/scripts.js"
+ "../assets/scripts.js"
];
for (const jsRelation of note.getRelations("shareJs")) {
- jsToLoad.push(`api/notes/${jsRelation.value}/download${addContentAccessQuery(note)}`);
+ jsToLoad.push(`../api/notes/${jsRelation.value}/download${addContentAccessQuery(note)}`);
}
const customLogoId = note.getRelation("shareLogo")?.value;
- const logoUrl = customLogoId ? `api/images/${customLogoId}/image.png${addContentAccessQuery(note)}` : `../${assetUrlFragment}/images/icon-color.svg`;
+ const logoUrl = customLogoId ? `../api/images/${customLogoId}/image.png${addContentAccessQuery(note)}` : `../../${assetUrlFragment}/images/icon-color.svg`;
return renderNoteContentInternal(note, {
subRoot,
@@ -140,7 +139,7 @@ export function renderNoteContent(note: SNote) {
logoUrl,
ancestors,
isStatic: false,
- faviconUrl: note.hasRelation("shareFavicon") ? `api/notes/${note.getRelationValue("shareFavicon")}/download${addContentAccessQuery(note)}` : `../favicon.ico`
+ faviconUrl: note.hasRelation("shareFavicon") ? `../api/notes/${note.getRelationValue("shareFavicon")}/download${addContentAccessQuery(note)}` : `../../favicon.ico`
});
}
@@ -365,7 +364,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNot
const attachment = getAttachment(attachmentId);
if (attachment) {
- linkEl.setAttribute("href", `api/attachments/${attachmentId}/download${addContentAccessQuery(note)}`);
+ linkEl.setAttribute("href", `../api/attachments/${attachmentId}/download${addContentAccessQuery(note)}`);
linkEl.classList.add(`attachment-link`);
linkEl.classList.add(`role-${attachment.role}`);
linkEl.childNodes.length = 0;
@@ -381,7 +380,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNot
const linkedNote = getNote(noteId);
if (linkedNote) {
const isExternalLink = linkedNote.hasLabel("shareExternalLink");
- const href = isExternalLink ? linkedNote.getLabelValue("shareExternalLink") : `./${linkedNote.shareId}`;
+ const href = isExternalLink ? linkedNote.getLabelValue("shareExternalLink") : `../${linkedNote.shareId}`;
if (href) {
linkEl.setAttribute("href", href);
}
@@ -438,7 +437,7 @@ function renderMermaid(result: Result, note: SNote | BNote) {
}
result.content = `
-
+