Skip to content

Commit 269561e

Browse files
committed
vault backup: 2026-01-11 10:36:48
1 parent 9bc91e1 commit 269561e

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

.obsidian/workspace.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@
283283
},
284284
"active": "2f9a825c22e15913",
285285
"lastOpenFiles": [
286-
"source/charts/极地霸权与生存空间:美国对格陵兰岛地缘战略诉求的综合评估报告/index.html.md",
286+
"source/charts/极地霸权与生存空间:美国对格陵兰岛地缘战略诉求的综合评估报告/index.html",
287287
"source/charts/极地霸权与生存空间:美国对格陵兰岛地缘战略诉求的综合评估报告",
288288
"source/模板/新建图表页面.md",
289+
"source/charts/极地霸权与生存空间:美国对格陵兰岛地缘战略诉求的综合评估报告/index.html.md",
289290
"source/_posts/极地霸权与生存空间:美国对格陵兰岛地缘战略诉求的综合评估报告.md",
290291
"source/_posts/2026年拉丁美洲地缘政治格局重塑:左翼政府的退潮、生存与转型深度研究报告.md",
291292
"source/_posts/2026-01-09-futures-report.md",
@@ -318,7 +319,6 @@
318319
"node_modules/jstransformer/LICENSE.md",
319320
"node_modules/jstransformer/CHANGELOG.md",
320321
"node_modules/pug-filters/README.md",
321-
"node_modules/pug-filters/CHANGELOG.md",
322322
"node_modules/hexo-theme-butterfly/source/img/friend_404.gif",
323323
"node_modules/hexo-theme-butterfly/source/img/error-page.png",
324324
"node_modules/hexo-theme-butterfly/source/img/butterfly-icon.png",
File renamed without changes.
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
<% (async () => {
2-
// 【无星号版】使用立即执行函数包裹,完美避开语法解析 Bug
2+
// --- 终极修正版:强制创建 .html 后缀文件 ---
33

44
// 1. 获取剪贴板
55
const htmlContent = await tp.system.clipboard();
66

77
// 2. 建议名称逻辑
88
let suggestion = "new-chart";
99
if (tp.file && tp.file.title) {
10-
// 这里的正则把空格替换为横杠,并转小写
1110
suggestion = tp.file.title.replace(/\s+/g, "-").toLowerCase();
1211
}
1312

1413
// 3. 弹窗询问
1514
const folderName = await tp.system.prompt("请输入图表文件夹名称 (英文ID)", suggestion);
1615

1716
if (folderName) {
18-
// ⚠️ 路径配置:根据你的目录结构,这里指向 source/charts/
17+
// 定义路径
1918
const targetFolder = `source/charts/${folderName}`;
20-
const targetFile = `${targetFolder}/index.html`;
21-
const vault = app.vault;
19+
const targetFilePath = `${targetFolder}/index.html`; // 完整路径
2220

23-
// 检查剪贴板
21+
const vault = app.vault;
22+
2423
if (!htmlContent || htmlContent.trim() === "") {
2524
new Notice("❌ 剪贴板为空!请先复制 HTML 代码。");
2625
} else {
27-
// 检查文件是否存在
28-
const existingFile = vault.getAbstractFileByPath(targetFile);
26+
27+
// A. 先检查文件夹是否存在,不存在则手动创建
28+
// (app.vault.create 不会自动创建父文件夹,所以要手动来)
29+
if (!vault.getAbstractFileByPath(targetFolder)) {
30+
await vault.createFolder(targetFolder);
31+
}
32+
33+
// B. 检查文件是否存在
34+
const existingFile = vault.getAbstractFileByPath(targetFilePath);
2935
3036
if (existingFile) {
3137
const confirm = await tp.system.prompt(`⚠️ ${folderName} 已存在,覆盖吗?(yes/no)`);
@@ -34,10 +40,11 @@
3440
new Notice(`✅ 已更新图表: ${folderName}`);
3541
}
3642
} else {
43+
// C. 核心修改:使用底层 API 直接创建文件
44+
// 这会创建一个纯正的 .html 文件,没有 .md 后缀
3745
try {
38-
// 创建新文件
39-
await tp.file.create_new(htmlContent, "index.html", false, targetFolder);
40-
new Notice(`🎉 创建成功: ${folderName}`);
46+
await vault.create(targetFilePath, htmlContent);
47+
new Notice(`🎉 创建成功: ${targetFilePath}`);
4148
} catch (e) {
4249
new Notice(`❌ 创建失败: ${e.message}`);
4350
console.error(e);
@@ -46,6 +53,5 @@
4653
}
4754
}
4855

49-
// 4. 重要:返回空字符串,这样文档里就不会显示 undefined
5056
return "";
5157
})() %>

0 commit comments

Comments
 (0)