mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 12:39:04 +01:00
fix(export/share): note children preview links not working
This commit is contained in:
parent
0efdf65202
commit
8523050ab2
@ -35,6 +35,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
|
|||||||
});
|
});
|
||||||
|
|
||||||
const noteIdToMeta: Record<string, NoteMeta> = {};
|
const noteIdToMeta: Record<string, NoteMeta> = {};
|
||||||
|
const rewriteFn = (zipExportOptions?.customRewriteLinks ? zipExportOptions?.customRewriteLinks(rewriteLinks, getNoteTargetUrl) : rewriteLinks);
|
||||||
|
|
||||||
function buildProvider() {
|
function buildProvider() {
|
||||||
const providerData: ZipExportProviderData = {
|
const providerData: ZipExportProviderData = {
|
||||||
@ -42,7 +43,8 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
|
|||||||
metaFile,
|
metaFile,
|
||||||
archive,
|
archive,
|
||||||
rootMeta: rootMeta!,
|
rootMeta: rootMeta!,
|
||||||
branch
|
branch,
|
||||||
|
rewriteFn
|
||||||
};
|
};
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case "html":
|
case "html":
|
||||||
@ -275,8 +277,6 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rewriteFn = (zipExportOptions?.customRewriteLinks ? zipExportOptions?.customRewriteLinks(rewriteLinks, getNoteTargetUrl) : rewriteLinks);
|
|
||||||
|
|
||||||
function rewriteLinks(content: string, noteMeta: NoteMeta): string {
|
function rewriteLinks(content: string, noteMeta: NoteMeta): string {
|
||||||
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/[^"]*"/g, (match, targetNoteId) => {
|
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/[^"]*"/g, (match, targetNoteId) => {
|
||||||
const url = getNoteTargetUrl(targetNoteId, noteMeta);
|
const url = getNoteTargetUrl(targetNoteId, noteMeta);
|
||||||
@ -325,9 +325,6 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
|
|||||||
}
|
}
|
||||||
|
|
||||||
content = provider.prepareContent(title, content, noteMeta, note, branch);
|
content = provider.prepareContent(title, content, noteMeta, note, branch);
|
||||||
if (isText) {
|
|
||||||
content = rewriteFn(content as string, noteMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ export interface ZipExportProviderData {
|
|||||||
rootMeta: NoteMeta;
|
rootMeta: NoteMeta;
|
||||||
archive: Archiver;
|
archive: Archiver;
|
||||||
zipExportOptions?: AdvancedExportOptions;
|
zipExportOptions?: AdvancedExportOptions;
|
||||||
|
rewriteFn: RewriteLinksFn;
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ZipExportProvider {
|
export abstract class ZipExportProvider {
|
||||||
@ -37,6 +38,7 @@ export abstract class ZipExportProvider {
|
|||||||
rootMeta: NoteMeta;
|
rootMeta: NoteMeta;
|
||||||
archive: Archiver;
|
archive: Archiver;
|
||||||
zipExportOptions?: AdvancedExportOptions;
|
zipExportOptions?: AdvancedExportOptions;
|
||||||
|
rewriteFn: RewriteLinksFn;
|
||||||
|
|
||||||
constructor(data: ZipExportProviderData) {
|
constructor(data: ZipExportProviderData) {
|
||||||
this.branch = data.branch;
|
this.branch = data.branch;
|
||||||
@ -45,6 +47,7 @@ export abstract class ZipExportProvider {
|
|||||||
this.rootMeta = data.rootMeta;
|
this.rootMeta = data.rootMeta;
|
||||||
this.archive = data.archive;
|
this.archive = data.archive;
|
||||||
this.zipExportOptions = data.zipExportOptions;
|
this.zipExportOptions = data.zipExportOptions;
|
||||||
|
this.rewriteFn = data.rewriteFn;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract prepareMeta(): void;
|
abstract prepareMeta(): void;
|
||||||
|
|||||||
@ -62,7 +62,11 @@ export default class HtmlExportProvider extends ZipExportProvider {
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return content.length < 100_000 ? html.prettyPrint(content, { indent_size: 2 }) : content;
|
if (content.length < 100_000) {
|
||||||
|
content = html.prettyPrint(content, { indent_size: 2 })
|
||||||
|
}
|
||||||
|
content = this.rewriteFn(content as string, noteMeta);
|
||||||
|
return content;
|
||||||
} else {
|
} else {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export default class MarkdownExportProvider extends ZipExportProvider {
|
|||||||
${markdownContent}`;
|
${markdownContent}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markdownContent = this.rewriteFn(markdownContent, noteMeta);
|
||||||
return markdownContent;
|
return markdownContent;
|
||||||
} else {
|
} else {
|
||||||
return content;
|
return content;
|
||||||
|
|||||||
@ -51,6 +51,7 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
|
|||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
content = renderNoteForExport(note, branch, basePath);
|
content = renderNoteForExport(note, branch, basePath);
|
||||||
|
content = this.rewriteFn(content, noteMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
|
|||||||
@ -137,7 +137,7 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes";
|
const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes";
|
||||||
for (const childNote of note[action]()) {
|
for (const childNote of note[action]()) {
|
||||||
const isExternalLink = childNote.hasLabel("shareExternal") || childNote.hasLabel("shareExternalLink");
|
const isExternalLink = childNote.hasLabel("shareExternal") || childNote.hasLabel("shareExternalLink");
|
||||||
const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId}`;
|
const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId ?? "#root/" + childNote.noteId}`;
|
||||||
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "";
|
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "";
|
||||||
%>
|
%>
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user