mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 19:49:01 +01:00 
			
		
		
		
	refactor(export/zip): separate building provider into own method
This commit is contained in:
		
							parent
							
								
									a9f68f5487
								
							
						
					
					
						commit
						acb0991d05
					
				| @ -20,7 +20,7 @@ import type 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"; | ||||
| import { AdvancedExportOptions, ZipExportProvider, ZipExportProviderData } from "./zip/abstract_provider.js"; | ||||
| import { AdvancedExportOptions, ZipExportProviderData } from "./zip/abstract_provider.js"; | ||||
| import MarkdownExportProvider from "./zip/markdown.js"; | ||||
| import ShareThemeExportProvider from "./zip/share_theme.js"; | ||||
| import type BNote from "../../becca/entities/bnote.js"; | ||||
| @ -36,6 +36,25 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h | ||||
| 
 | ||||
|     const noteIdToMeta: Record<string, NoteMeta> = {}; | ||||
| 
 | ||||
|     function buildProvider() { | ||||
|         const providerData: ZipExportProviderData = { | ||||
|             getNoteTargetUrl, | ||||
|             metaFile, | ||||
|             archive, | ||||
|             rootMeta: rootMeta! | ||||
|         }; | ||||
|         switch (format) { | ||||
|             case "html": | ||||
|                 return new HtmlExportProvider(providerData); | ||||
|             case "markdown": | ||||
|                 return new MarkdownExportProvider(providerData); | ||||
|             case "share": | ||||
|                 return new ShareThemeExportProvider(providerData); | ||||
|             default: | ||||
|                 throw new Error(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     function getUniqueFilename(existingFileNames: Record<string, number>, fileName: string) { | ||||
|         const lcFileName = fileName.toLowerCase(); | ||||
| 
 | ||||
| @ -388,26 +407,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h | ||||
|         files: [rootMeta] | ||||
|     }; | ||||
| 
 | ||||
|     let provider: ZipExportProvider; | ||||
|     const providerData: ZipExportProviderData = { | ||||
|         getNoteTargetUrl, | ||||
|         metaFile, | ||||
|         archive, | ||||
|         rootMeta | ||||
|     }; | ||||
|     switch (format) { | ||||
|         case "html": | ||||
|             provider = new HtmlExportProvider(providerData); | ||||
|             break; | ||||
|         case "markdown": | ||||
|             provider = new MarkdownExportProvider(providerData); | ||||
|             break; | ||||
|         case "share": | ||||
|             provider = new ShareThemeExportProvider(providerData); | ||||
|             break; | ||||
|         default: | ||||
|             throw new Error(); | ||||
|     } | ||||
|     const provider= buildProvider(); | ||||
| 
 | ||||
|     provider.prepareMeta(); | ||||
| 
 | ||||
|  | ||||
| @ -35,13 +35,15 @@ export default class ShareThemeExportProvider extends ZipExportProvider { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     prepareContent(title: string, content: string | Buffer, noteMeta: NoteMeta, note: BNote, branch: BBranch): string | Buffer { | ||||
|     prepareContent(title: string, content: string | Buffer, noteMeta: NoteMeta, note: BNote | undefined, branch: BBranch): string | Buffer { | ||||
|         if (!noteMeta?.notePath?.length) { | ||||
|             throw new Error("Missing note path."); | ||||
|         } | ||||
|         const basePath = "../".repeat(noteMeta.notePath.length - 1); | ||||
| 
 | ||||
|         content = renderNoteForExport(note, branch, basePath); | ||||
|         if (note) { | ||||
|             content = renderNoteForExport(note, branch, basePath); | ||||
|         } | ||||
| 
 | ||||
|         return content; | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran