mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
feat(in-app-help): create notes at root level
This commit is contained in:
parent
58e82fb0f8
commit
f1d641ac32
@ -6,6 +6,8 @@ import noteService from "./notes.js";
|
|||||||
import log from "./log.js";
|
import log from "./log.js";
|
||||||
import migrationService from "./migration.js";
|
import migrationService from "./migration.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
|
import app_path from "./app_path.js";
|
||||||
|
import { getHelpHiddenSubtreeData } from "./in_app_help.js";
|
||||||
|
|
||||||
const LBTPL_ROOT = "_lbTplRoot";
|
const LBTPL_ROOT = "_lbTplRoot";
|
||||||
const LBTPL_BASE = "_lbTplBase";
|
const LBTPL_BASE = "_lbTplBase";
|
||||||
@ -16,21 +18,21 @@ const LBTPL_BUILTIN_WIDGET = "_lbTplBuiltinWidget";
|
|||||||
const LBTPL_SPACER = "_lbTplSpacer";
|
const LBTPL_SPACER = "_lbTplSpacer";
|
||||||
const LBTPL_CUSTOM_WIDGET = "_lbTplCustomWidget";
|
const LBTPL_CUSTOM_WIDGET = "_lbTplCustomWidget";
|
||||||
|
|
||||||
interface Attribute {
|
interface HiddenSubtreeAttribute {
|
||||||
type: AttributeType;
|
type: AttributeType;
|
||||||
name: string;
|
name: string;
|
||||||
isInheritable?: boolean;
|
isInheritable?: boolean;
|
||||||
value?: string;
|
value?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Item {
|
export interface HiddenSubtreeItem {
|
||||||
notePosition?: number;
|
notePosition?: number;
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
type: NoteType;
|
type: NoteType;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
attributes?: Attribute[];
|
attributes?: HiddenSubtreeAttribute[];
|
||||||
children?: Item[];
|
children?: HiddenSubtreeItem[];
|
||||||
isExpanded?: boolean;
|
isExpanded?: boolean;
|
||||||
baseSize?: string;
|
baseSize?: string;
|
||||||
growthFactor?: string;
|
growthFactor?: string;
|
||||||
@ -54,9 +56,9 @@ enum Command {
|
|||||||
* duplicate subtrees. This way, all instances will generate the same structure with the same IDs.
|
* duplicate subtrees. This way, all instances will generate the same structure with the same IDs.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let hiddenSubtreeDefinition: Item;
|
let hiddenSubtreeDefinition: HiddenSubtreeItem;
|
||||||
|
|
||||||
function buildHiddenSubtreeDefinition(): Item {
|
function buildHiddenSubtreeDefinition(): HiddenSubtreeItem {
|
||||||
return {
|
return {
|
||||||
id: "_hidden",
|
id: "_hidden",
|
||||||
title: t("hidden-subtree.root-title"),
|
title: t("hidden-subtree.root-title"),
|
||||||
@ -350,7 +352,8 @@ function buildHiddenSubtreeDefinition(): Item {
|
|||||||
id: "_help",
|
id: "_help",
|
||||||
title: t("hidden-subtree.user-guide"),
|
title: t("hidden-subtree.user-guide"),
|
||||||
type: "book",
|
type: "book",
|
||||||
icon: "bx-help-circle"
|
icon: "bx-help-circle",
|
||||||
|
children: getHelpHiddenSubtreeData()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@ -374,7 +377,7 @@ function checkHiddenSubtree(force = false, extraOpts: CheckHiddenExtraOpts = {})
|
|||||||
checkHiddenSubtreeRecursively("root", hiddenSubtreeDefinition, extraOpts);
|
checkHiddenSubtreeRecursively("root", hiddenSubtreeDefinition, extraOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkHiddenSubtreeRecursively(parentNoteId: string, item: Item, extraOpts: CheckHiddenExtraOpts = {}) {
|
function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtreeItem, extraOpts: CheckHiddenExtraOpts = {}) {
|
||||||
if (!item.id || !item.type || !item.title) {
|
if (!item.id || !item.type || !item.title) {
|
||||||
throw new Error(`Item does not contain mandatory properties: ${JSON.stringify(item)}`);
|
throw new Error(`Item does not contain mandatory properties: ${JSON.stringify(item)}`);
|
||||||
}
|
}
|
||||||
|
47
src/services/in_app_help.ts
Normal file
47
src/services/in_app_help.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import type { HiddenSubtreeItem } from "./hidden_subtree.js";
|
||||||
|
import type NoteMeta from "./meta/note_meta.js";
|
||||||
|
import type { NoteMetaFile } from "./meta/note_meta.js";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { isDev } from "./utils.js";
|
||||||
|
|
||||||
|
export function getHelpHiddenSubtreeData() {
|
||||||
|
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const appDir = path.join(srcRoot, "public", isDev ? "app" : "app-dist");
|
||||||
|
const helpDir = path.join(appDir, "doc_notes", "en", "User Guide");
|
||||||
|
const metaFilePath = path.join(helpDir, "!!!meta.json");
|
||||||
|
const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
return parseNoteMetaFile(metaFileContent as NoteMetaFile);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNoteMetaFile(noteMetaFile: NoteMetaFile): HiddenSubtreeItem[] {
|
||||||
|
if (!noteMetaFile.files) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const metaRoot = noteMetaFile.files[0];
|
||||||
|
const items: HiddenSubtreeItem[] = [];
|
||||||
|
|
||||||
|
for (const childMeta of metaRoot.children ?? []) {
|
||||||
|
items.push(parseNoteMeta(childMeta));
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNoteMeta(noteMeta: NoteMeta): HiddenSubtreeItem {
|
||||||
|
const item: HiddenSubtreeItem = {
|
||||||
|
id: `_help_${noteMeta.noteId}`,
|
||||||
|
title: noteMeta.title,
|
||||||
|
type: "doc"
|
||||||
|
};
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
@ -8,10 +8,10 @@ export interface NoteMetaFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default interface NoteMeta {
|
export default interface NoteMeta {
|
||||||
noteId?: string;
|
noteId: string;
|
||||||
notePath?: string[];
|
notePath?: string[];
|
||||||
isClone?: boolean;
|
isClone?: boolean;
|
||||||
title?: string;
|
title: string;
|
||||||
notePosition?: number;
|
notePosition?: number;
|
||||||
prefix?: string | null;
|
prefix?: string | null;
|
||||||
isExpanded?: boolean;
|
isExpanded?: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user