refactor(export/share): use different URL rewriting mechanism

This commit is contained in:
Elian Doran 2025-06-23 19:25:28 +03:00
parent 8523050ab2
commit 77e4c3d0ec
No known key found for this signature in database
3 changed files with 6 additions and 1 deletions

View File

@ -1774,6 +1774,10 @@ class BNote extends AbstractBeccaEntity<BNote> {
return this.getVisibleChildNotes().length > 0;
}
get shareId() {
return this.noteId;
}
}
export default BNote;

View File

@ -51,6 +51,7 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
if (note) {
content = renderNoteForExport(note, branch, basePath);
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
content = this.rewriteFn(content, noteMeta);
}

View File

@ -137,7 +137,7 @@ content = content.replaceAll(headingRe, (...match) => {
const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes";
for (const childNote of note[action]()) {
const isExternalLink = childNote.hasLabel("shareExternal") || childNote.hasLabel("shareExternalLink");
const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId ?? "#root/" + childNote.noteId}`;
const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId}`;
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "";
%>
<li>