mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 19:49:01 +01:00 
			
		
		
		
	refactor(export/share): build index file
This commit is contained in:
		
							parent
							
								
									acb0991d05
								
							
						
					
					
						commit
						0efdf65202
					
				| @ -16,7 +16,7 @@ import ValidationError from "../../errors/validation_error.js"; | ||||
| import type NoteMeta from "../meta/note_meta.js"; | ||||
| import type AttachmentMeta from "../meta/attachment_meta.js"; | ||||
| import type AttributeMeta from "../meta/attribute_meta.js"; | ||||
| import type BBranch from "../../becca/entities/bbranch.js"; | ||||
| import BBranch from "../../becca/entities/bbranch.js"; | ||||
| import type { Response } from "express"; | ||||
| import type { NoteMetaFile } from "../meta/note_meta.js"; | ||||
| import HtmlExportProvider from "./zip/html.js"; | ||||
| @ -41,7 +41,8 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h | ||||
|             getNoteTargetUrl, | ||||
|             metaFile, | ||||
|             archive, | ||||
|             rootMeta: rootMeta! | ||||
|             rootMeta: rootMeta!, | ||||
|             branch | ||||
|         }; | ||||
|         switch (format) { | ||||
|             case "html": | ||||
|  | ||||
| @ -22,6 +22,7 @@ export interface AdvancedExportOptions { | ||||
| } | ||||
| 
 | ||||
| export interface ZipExportProviderData { | ||||
|     branch: BBranch; | ||||
|     getNoteTargetUrl: (targetNoteId: string, sourceMeta: NoteMeta) => string | null; | ||||
|     metaFile: NoteMetaFile; | ||||
|     rootMeta: NoteMeta; | ||||
| @ -30,7 +31,7 @@ export interface ZipExportProviderData { | ||||
| } | ||||
| 
 | ||||
| export abstract class ZipExportProvider { | ||||
| 
 | ||||
|     branch: BBranch; | ||||
|     metaFile: NoteMetaFile; | ||||
|     getNoteTargetUrl: (targetNoteId: string, sourceMeta: NoteMeta) => string | null; | ||||
|     rootMeta: NoteMeta; | ||||
| @ -38,6 +39,7 @@ export abstract class ZipExportProvider { | ||||
|     zipExportOptions?: AdvancedExportOptions; | ||||
| 
 | ||||
|     constructor(data: ZipExportProviderData) { | ||||
|         this.branch = data.branch; | ||||
|         this.metaFile = data.metaFile; | ||||
|         this.getNoteTargetUrl = data.getNoteTargetUrl; | ||||
|         this.rootMeta = data.rootMeta; | ||||
|  | ||||
| @ -11,6 +11,7 @@ import type BBranch from "../../../becca/entities/bbranch.js"; | ||||
| export default class ShareThemeExportProvider extends ZipExportProvider { | ||||
| 
 | ||||
|     private assetsMeta: NoteMeta[] = []; | ||||
|     private indexMeta: NoteMeta | null = null; | ||||
| 
 | ||||
|     prepareMeta(): void { | ||||
|         const assets = [ | ||||
| @ -33,6 +34,13 @@ export default class ShareThemeExportProvider extends ZipExportProvider { | ||||
|             this.assetsMeta.push(assetMeta); | ||||
|             this.metaFile.files.push(assetMeta); | ||||
|         } | ||||
| 
 | ||||
|         this.indexMeta = { | ||||
|             noImport: true, | ||||
|             dataFileName: "index.html" | ||||
|         }; | ||||
| 
 | ||||
|         this.metaFile.files.push(this.indexMeta); | ||||
|     } | ||||
| 
 | ||||
|     prepareContent(title: string, content: string | Buffer, noteMeta: NoteMeta, note: BNote | undefined, branch: BBranch): string | Buffer { | ||||
| @ -50,6 +58,17 @@ export default class ShareThemeExportProvider extends ZipExportProvider { | ||||
| 
 | ||||
|     afterDone(): void { | ||||
|         this.#saveAssets(this.rootMeta, this.assetsMeta); | ||||
|         this.#saveIndex(); | ||||
|     } | ||||
| 
 | ||||
|     #saveIndex() { | ||||
|         if (!this.indexMeta?.dataFileName) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         const note = this.branch.getNote(); | ||||
|         const fullHtml = this.prepareContent(this.rootMeta.title ?? "", note.getContent(), this.rootMeta, note, this.branch); | ||||
|         this.archive.append(fullHtml, { name: this.indexMeta.dataFileName }); | ||||
|     } | ||||
| 
 | ||||
|     #saveAssets(rootMeta: NoteMeta, assetsMeta: NoteMeta[]) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran