mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 03:59:05 +01:00
feat(export/share): render 404 page
This commit is contained in:
parent
4f103375b5
commit
754bb61a52
@ -2,14 +2,16 @@ import { join } from "path";
|
||||
import NoteMeta, { NoteMetaFile } from "../../meta/note_meta";
|
||||
import { ExportFormat, ZipExportProvider } from "./abstract_provider.js";
|
||||
import { RESOURCE_DIR } from "../../resource_dir";
|
||||
import utils, { getResourceDir, isDev } from "../../utils";
|
||||
import { getResourceDir, isDev } from "../../utils";
|
||||
import fs, { readdirSync } from "fs";
|
||||
import { renderNoteForExport } from "../../../share/content_renderer";
|
||||
import { getDefaultTemplatePath, readTemplate, renderNoteForExport } from "../../../share/content_renderer";
|
||||
import type BNote from "../../../becca/entities/bnote.js";
|
||||
import type BBranch from "../../../becca/entities/bbranch.js";
|
||||
import { getShareThemeAssetDir } from "../../../routes/assets";
|
||||
import { convert as convertToText } from "html-to-text";
|
||||
import becca from "../../../becca/becca";
|
||||
import ejs from "ejs";
|
||||
import { t } from "i18next";
|
||||
|
||||
const shareThemeAssetDir = getShareThemeAssetDir();
|
||||
|
||||
@ -92,6 +94,7 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
|
||||
afterDone(rootMeta: NoteMeta): void {
|
||||
this.#saveAssets(rootMeta, this.assetsMeta);
|
||||
this.#saveIndex(rootMeta);
|
||||
this.#save404();
|
||||
|
||||
// Search index
|
||||
for (const item of this.searchIndex.values()) {
|
||||
@ -131,6 +134,12 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
|
||||
}
|
||||
}
|
||||
|
||||
#save404() {
|
||||
const templatePath = getDefaultTemplatePath("404");
|
||||
const content = ejs.render(readTemplate(templatePath), { t });
|
||||
this.archive.append(content, { name: "404.html" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getShareThemeAssets(nameWithExtension: string) {
|
||||
|
||||
@ -212,7 +212,7 @@ export function getDefaultTemplatePath(template: string) {
|
||||
: join(getResourceDir(), `share-theme/templates/${template}.ejs`);
|
||||
}
|
||||
|
||||
function readTemplate(path: string) {
|
||||
export function readTemplate(path: string) {
|
||||
const cachedTemplate = templateCache.get(path);
|
||||
if (cachedTemplate) {
|
||||
return cachedTemplate;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user