fix(share): broken reference links in static HTML export
Some checks are pending
Checks / main (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Documentation / Build and Deploy Documentation (push) Waiting to run
Dev / Test development (push) Waiting to run
Dev / Build Docker image (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile) (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile.alpine) (push) Blocked by required conditions
/ Check Docker build (Dockerfile) (push) Waiting to run
/ Check Docker build (Dockerfile.alpine) (push) Waiting to run
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.alpine, ubuntu-latest, linux/amd64) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v7) (push) Blocked by required conditions
/ Build Docker images (Dockerfile.legacy, ubuntu-24.04-arm, linux/arm/v8) (push) Blocked by required conditions
/ Merge manifest lists (push) Blocked by required conditions
playwright / E2E tests on linux-arm64 (push) Waiting to run
playwright / E2E tests on linux-x64 (push) Waiting to run
Deploy website / Build & deploy website (push) Waiting to run

This commit is contained in:
Elian Doran 2025-11-20 14:50:52 +02:00
parent 1e86d85035
commit c16eee79d4
No known key found for this signature in database

View File

@ -38,6 +38,8 @@ interface Subroot {
branch?: SBranch | BBranch
}
type GetNoteFunction = (id: string) => SNote | BNote | null;
function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {
if (!note || note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
// share root itself is not shared
@ -301,7 +303,7 @@ function renderText(result: Result, note: SNote | BNote) {
result.isEmpty = document.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0;
const getNote = note instanceof BNote
const getNote: GetNoteFunction = note instanceof BNote
? (noteId: string) => becca.getNote(noteId)
: (noteId: string) => shaca.getNote(noteId);
const getAttachment = note instanceof BNote
@ -319,7 +321,7 @@ function renderText(result: Result, note: SNote | BNote) {
}
if (linkEl.classList.contains("reference-link")) {
cleanUpReferenceLinks(linkEl);
cleanUpReferenceLinks(linkEl, getNote);
}
if (href?.startsWith("#")) {
@ -347,7 +349,7 @@ function renderText(result: Result, note: SNote | BNote) {
}
}
function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: (id: string) => SNote | BNote | null, getAttachment: (id: string) => BAttachment | SAttachment | null) {
function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNoteFunction, getAttachment: (id: string) => BAttachment | SAttachment | null) {
const linkRegExp = /attachmentId=([a-zA-Z0-9_]+)/g;
let attachmentMatch;
if ((attachmentMatch = linkRegExp.exec(href))) {
@ -392,13 +394,13 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: (id: s
*
* @param linkEl the <a> element to process.
*/
function cleanUpReferenceLinks(linkEl: HTMLElement) {
function cleanUpReferenceLinks(linkEl: HTMLElement, getNote: GetNoteFunction) {
// Note: this method is basically a reimplementation of getReferenceLinkTitleSync from the link service of the client.
const href = linkEl.getAttribute("href") ?? "";
if (linkEl.classList.contains("attachment-link")) return;
const noteId = href.split("/").at(-1);
const note = noteId ? shaca.getNote(noteId) : undefined;
const note = noteId ? getNote(noteId) : undefined;
if (!note) {
console.warn("Unable to find note ", noteId);
linkEl.innerHTML = "[missing note]";