mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
feat(export/zip): get boxicons to work
This commit is contained in:
@@ -517,13 +517,15 @@ ${markdownContent}`;
|
|||||||
archive.append(fullHtml, { name: indexMeta.dataFileName });
|
archive.append(fullHtml, { name: indexMeta.dataFileName });
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveCss(rootMeta: NoteMeta, cssMeta: NoteMeta) {
|
function saveAssets(rootMeta: NoteMeta, assetsMeta: NoteMeta[]) {
|
||||||
if (!cssMeta.dataFileName) {
|
for (const assetMeta of assetsMeta) {
|
||||||
return;
|
if (!assetMeta.dataFileName) {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let cssContent = getShareThemeAssets("css");
|
let cssContent = getShareThemeAssets(assetMeta.dataFileName);
|
||||||
archive.append(cssContent, { name: cssMeta.dataFileName });
|
archive.append(cssContent, { name: assetMeta.dataFileName });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingFileNames: Record<string, number> = format === "html" ? { navigation: 0, index: 1 } : {};
|
const existingFileNames: Record<string, number> = format === "html" ? { navigation: 0, index: 1 } : {};
|
||||||
@@ -540,7 +542,7 @@ ${markdownContent}`;
|
|||||||
|
|
||||||
let navigationMeta: NoteMeta | null = null;
|
let navigationMeta: NoteMeta | null = null;
|
||||||
let indexMeta: NoteMeta | null = null;
|
let indexMeta: NoteMeta | null = null;
|
||||||
let cssMeta: NoteMeta | null = null;
|
let assetsMeta: NoteMeta[] = [];
|
||||||
|
|
||||||
if (format === "html") {
|
if (format === "html") {
|
||||||
navigationMeta = {
|
navigationMeta = {
|
||||||
@@ -557,12 +559,24 @@ ${markdownContent}`;
|
|||||||
|
|
||||||
metaFile.files.push(indexMeta);
|
metaFile.files.push(indexMeta);
|
||||||
|
|
||||||
cssMeta = {
|
const assets = [
|
||||||
noImport: true,
|
"style.css",
|
||||||
dataFileName: "style.css"
|
"boxicons.css",
|
||||||
};
|
"boxicons.eot",
|
||||||
|
"boxicons.woff2",
|
||||||
|
"boxicons.woff",
|
||||||
|
"boxicons.ttf",
|
||||||
|
"boxicons.svg",
|
||||||
|
];
|
||||||
|
|
||||||
metaFile.files.push(cssMeta);
|
for (const asset of assets) {
|
||||||
|
const assetMeta = {
|
||||||
|
noImport: true,
|
||||||
|
dataFileName: asset
|
||||||
|
};
|
||||||
|
assetsMeta.push(assetMeta);
|
||||||
|
metaFile.files.push(assetMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const noteMeta of Object.values(noteIdToMeta)) {
|
for (const noteMeta of Object.values(noteIdToMeta)) {
|
||||||
@@ -596,13 +610,13 @@ ${markdownContent}`;
|
|||||||
saveNote(rootMeta, "");
|
saveNote(rootMeta, "");
|
||||||
|
|
||||||
if (format === "html") {
|
if (format === "html") {
|
||||||
if (!navigationMeta || !indexMeta || !cssMeta) {
|
if (!navigationMeta || !indexMeta || !assetsMeta) {
|
||||||
throw new Error("Missing meta.");
|
throw new Error("Missing meta.");
|
||||||
}
|
}
|
||||||
|
|
||||||
saveNavigation(rootMeta, navigationMeta);
|
saveNavigation(rootMeta, navigationMeta);
|
||||||
saveIndex(rootMeta, indexMeta);
|
saveIndex(rootMeta, indexMeta);
|
||||||
saveCss(rootMeta, cssMeta);
|
saveAssets(rootMeta, assetsMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
const note = branch.getNote();
|
const note = branch.getNote();
|
||||||
@@ -634,17 +648,22 @@ async function exportToZipFile(noteId: string, format: "markdown" | "html", zipF
|
|||||||
log.info(`Exported '${noteId}' with format '${format}' to '${zipFilePath}'`);
|
log.info(`Exported '${noteId}' with format '${format}' to '${zipFilePath}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getShareThemeAssets(extension: string) {
|
function getShareThemeAssets(nameWithExtension: string) {
|
||||||
|
// Rename share.css to style.css.
|
||||||
|
if (nameWithExtension === "style.css") {
|
||||||
|
nameWithExtension = "share.css";
|
||||||
|
}
|
||||||
|
|
||||||
let path: string | undefined;
|
let path: string | undefined;
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
path = join(getResourceDir(), "..", "..", "client", "dist", "src", `share.${extension}`);
|
path = join(getResourceDir(), "..", "..", "client", "dist", "src", nameWithExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
throw new Error("Not yet defined.");
|
throw new Error("Not yet defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs.readFileSync(path, "utf-8");
|
return fs.readFileSync(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
|
|||||||
subRoot,
|
subRoot,
|
||||||
rootNoteId: note.getParentNotes()[0].noteId,
|
rootNoteId: note.getParentNotes()[0].noteId,
|
||||||
cssToLoad: [
|
cssToLoad: [
|
||||||
`${basePath}style.css`
|
`${basePath}style.css`,
|
||||||
|
`${basePath}boxicons.css`
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user