mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
refactor(share): remove note uploading mechanism
This commit is contained in:
parent
c6ffa53f0b
commit
11853962b7
@ -5,10 +5,8 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esrun scripts/build.ts",
|
"build": "esrun scripts/build.ts",
|
||||||
"build-all": "esrun scripts/build.ts -- --templates",
|
|
||||||
"build-scripts": "esrun scripts/build.ts -- --module=scripts",
|
"build-scripts": "esrun scripts/build.ts -- --module=scripts",
|
||||||
"build-styles": "esrun scripts/build.ts -- --module=styles",
|
"build-styles": "esrun scripts/build.ts -- --module=styles",
|
||||||
"templates": "esrun scripts/build.ts -- --only-templates",
|
|
||||||
"dist": "esrun scripts/build.ts -- --minify",
|
"dist": "esrun scripts/build.ts -- --minify",
|
||||||
"test": "esrun src/scripts/test.ts"
|
"test": "esrun src/scripts/test.ts"
|
||||||
},
|
},
|
||||||
@ -27,7 +25,6 @@
|
|||||||
"esbuild": "^0.19.3",
|
"esbuild": "^0.19.3",
|
||||||
"eslint": "^8.49.0",
|
"eslint": "^8.49.0",
|
||||||
"highlight.js": "^11.8.0",
|
"highlight.js": "^11.8.0",
|
||||||
"trilium-etapi": "^0.1.2",
|
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
},
|
},
|
||||||
"nx": {
|
"nx": {
|
||||||
|
@ -3,7 +3,6 @@ import path from "node:path";
|
|||||||
// import {fileURLToPath} from "node:url";
|
// import {fileURLToPath} from "node:url";
|
||||||
|
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import tepi from "trilium-etapi";
|
|
||||||
import * as esbuild from "esbuild";
|
import * as esbuild from "esbuild";
|
||||||
|
|
||||||
|
|
||||||
@ -14,64 +13,7 @@ import * as esbuild from "esbuild";
|
|||||||
// console.log(process.env.npm_package_json);
|
// console.log(process.env.npm_package_json);
|
||||||
const rootDir = path.dirname(process.env.npm_package_json!);
|
const rootDir = path.dirname(process.env.npm_package_json!);
|
||||||
|
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
if (process.env.TRILIUM_ETAPI_TOKEN) tepi.token(process.env.TRILIUM_ETAPI_TOKEN);
|
|
||||||
|
|
||||||
|
|
||||||
const templateMap: Record<string, string> = {
|
|
||||||
page: process.env.PAGE_TEMPLATE_ID!,
|
|
||||||
tree_item: process.env.ITEM_TEMPLATE_ID!,
|
|
||||||
toc_item: process.env.TOC_TEMPLATE_ID!,
|
|
||||||
};
|
|
||||||
|
|
||||||
async function sendTemplates() {
|
|
||||||
for (const template in templateMap) {
|
|
||||||
const templatePath = path.join(rootDir, "src", "templates", `${template}.ejs`);
|
|
||||||
const contents = fs.readFileSync(templatePath).toString();
|
|
||||||
await tepi.putNoteContentById(templateMap[template], contents);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv.includes("--only-templates")) {
|
|
||||||
await sendTemplates();
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const bundleMap = {
|
|
||||||
"scripts.js": process.env.JS_NOTE_ID,
|
|
||||||
"styles.css": process.env.CSS_NOTE_ID
|
|
||||||
};
|
|
||||||
|
|
||||||
const triliumPlugin: esbuild.Plugin = {
|
|
||||||
name: "Trilium",
|
|
||||||
setup(build) {
|
|
||||||
build.onEnd(async result => {
|
|
||||||
if (!result.metafile) return;
|
|
||||||
|
|
||||||
const bundles = Object.keys(result.metafile.outputs);
|
|
||||||
for (const bundle of bundles) {
|
|
||||||
const filename = path.basename(bundle);
|
|
||||||
const noteId = bundleMap[filename as keyof typeof bundleMap];
|
|
||||||
if (!noteId) {
|
|
||||||
console.info(`No note id found for bundle ${bundle}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bundlePath = path.join(rootDir, bundle);
|
|
||||||
if (!fs.existsSync(bundlePath)) {
|
|
||||||
console.error(`Could not find bundle ${bundle}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const contents = fs.readFileSync(bundlePath).toString();
|
|
||||||
await tepi.putNoteContentById(noteId, contents);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const modules = ["scripts", "styles"];
|
const modules = ["scripts", "styles"];
|
||||||
const entryPoints: {in: string, out: string}[] = [];
|
const entryPoints: {in: string, out: string}[] = [];
|
||||||
@ -103,13 +45,11 @@ async function runBuild() {
|
|||||||
".html": "text",
|
".html": "text",
|
||||||
".css": "css"
|
".css": "css"
|
||||||
},
|
},
|
||||||
plugins: [triliumPlugin],
|
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
metafile: true,
|
metafile: true,
|
||||||
minify: process.argv.includes("--minify")
|
minify: process.argv.includes("--minify")
|
||||||
});
|
});
|
||||||
const after = performance.now();
|
const after = performance.now();
|
||||||
if (process.argv.includes("--templates")) await sendTemplates();
|
|
||||||
console.log(`Build actually took ${(after - before).toFixed(2)}ms`);
|
console.log(`Build actually took ${(after - before).toFixed(2)}ms`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user