From 7182d2452a0579ea77d22ddfb56739e3ec00c55b Mon Sep 17 00:00:00 2001 From: delphi Date: Fri, 28 Mar 2025 15:16:59 +0800 Subject: [PATCH 1/4] style: modify the reset button --- src/cuboxSetting.ts | 56 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/cuboxSetting.ts b/src/cuboxSetting.ts index d892582..4b05686 100644 --- a/src/cuboxSetting.ts +++ b/src/cuboxSetting.ts @@ -374,14 +374,14 @@ export class CuboxSyncSettingTab extends PluginSettingTab { this.plugin.settings.filenameTemplate = value; await this.plugin.saveSettings(); })) - .addButton(button => button + .addExtraButton(button => button .setIcon('reset') .setTooltip('Reset to default') .onClick(async () => { this.plugin.settings.filenameTemplate = DEFAULT_SETTINGS.filenameTemplate; await this.plugin.saveSettings(); // 刷新显示 - const textComponent = button.buttonEl.parentElement?.parentElement?.querySelector('input'); + const textComponent = button.extraSettingsEl.parentElement?.parentElement?.querySelector('input'); if (textComponent) { textComponent.value = DEFAULT_SETTINGS.filenameTemplate; } @@ -412,18 +412,20 @@ export class CuboxSyncSettingTab extends PluginSettingTab { textArea.inputEl.rows = 20; textArea.inputEl.cols = 30; })) - .addButton(button => button - .setIcon('reset') - .setTooltip('Reset to default') - .onClick(async () => { - this.plugin.settings.frontMatterVariables = DEFAULT_SETTINGS.frontMatterVariables; - await this.plugin.saveSettings(); - // 刷新显示 - const textArea = button.buttonEl.parentElement?.parentElement?.querySelector('textarea'); - if (textArea) { - textArea.value = DEFAULT_SETTINGS.frontMatterVariables.join(','); - } - })); + .addExtraButton(button => { + button + .setIcon('reset') + .setTooltip('Reset to default') + .onClick(async () => { + this.plugin.settings.frontMatterVariables = DEFAULT_SETTINGS.frontMatterVariables; + await this.plugin.saveSettings(); + // 刷新显示 + const textArea = button.extraSettingsEl.parentElement?.parentElement?.querySelector('textarea'); + if (textArea) { + textArea.value = DEFAULT_SETTINGS.frontMatterVariables.join(','); + } + }); + }); // 更新内容模板设置 const contentInstructionsFragment = document.createRange().createContextualFragment(contentTemplateInstructions); @@ -443,18 +445,20 @@ export class CuboxSyncSettingTab extends PluginSettingTab { textArea.inputEl.rows = 24; textArea.inputEl.cols = 30; })) - .addButton(button => button - .setIcon('reset') - .setTooltip('Reset to default') - .onClick(async () => { - this.plugin.settings.contentTemplate = DEFAULT_SETTINGS.contentTemplate; - await this.plugin.saveSettings(); - // 刷新显示 - const textArea = button.buttonEl.parentElement?.parentElement?.querySelector('textarea'); - if (textArea) { - textArea.value = DEFAULT_SETTINGS.contentTemplate; - } - })); + .addExtraButton(button => { + button + .setIcon('reset') + .setTooltip('Reset to default') + .onClick(async () => { + this.plugin.settings.contentTemplate = DEFAULT_SETTINGS.contentTemplate; + await this.plugin.saveSettings(); + // 刷新显示 + const textArea = button.extraSettingsEl.parentElement?.parentElement?.querySelector('textarea'); + if (textArea) { + textArea.value = DEFAULT_SETTINGS.contentTemplate; + } + }) + }); // 更新日期格式模板设置 const dateFormatInstructionsFragment = document.createRange().createContextualFragment(cuboxDateFormat); From e82a0f969ec0ded4ed80b4ff3de34ab41b65eac4 Mon Sep 17 00:00:00 2001 From: delphi Date: Fri, 28 Mar 2025 15:24:32 +0800 Subject: [PATCH 2/4] perf: skip article content requests when not needed in templates --- src/main.ts | 18 ++++++++++-------- src/templateProcessor.ts | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index a1f1f9d..d8af2cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -117,6 +117,9 @@ export default class CuboxSyncPlugin extends Plugin { ); const { articles, hasMore: moreArticles} = result; + + // 检查内容模板是否需要文章内容 + const needsContent = this.templateProcessor.needsArticleContent(this.settings.contentTemplate); if (articles.length === 0) { break; @@ -125,15 +128,14 @@ export default class CuboxSyncPlugin extends Plugin { // 处理每篇文章 for (const article of articles) { try { - // 获取文章内容 - const content = await this.cuboxApi.getArticleDetail(article.id); - if (content === null) continue; + let fullArticle = {...article}; - // 合并文章基本信息、内容和高亮 - const fullArticle = { - ...article, - content: content - }; + if (needsContent) { + const content = await this.cuboxApi.getArticleDetail(article.id); + if (content === null) continue; + + fullArticle.content = content; + } // 处理文件名和内容 const filename = this.templateProcessor.processFilenameTemplate( diff --git a/src/templateProcessor.ts b/src/templateProcessor.ts index 5a9cc7f..836e02b 100644 --- a/src/templateProcessor.ts +++ b/src/templateProcessor.ts @@ -313,4 +313,22 @@ export class TemplateProcessor { private getArticleProperty(article: CuboxArticle, propertyName: string): unknown { return (article as unknown as Record)[propertyName]; } + + /** + * 检查模板是否需要文章内容 + * @param template 内容模板 + * @returns 是否需要请求文章内容 + */ + needsArticleContent(template: string): boolean { + // 如果没有模板,但默认模板会输出文章内容,所以需要内容 + if (!template) { + return true; + } + + // 检查模板中是否包含需要文章内容的变量 + return template.includes('{{content}}') || + template.includes('{{{content}}}') || + template.includes('{{content_highlighted}}') || + template.includes('{{{content_highlighted}}}'); + } } \ No newline at end of file From 8d5b04783810ad2fe135efaba5fae4c7377e31ea Mon Sep 17 00:00:00 2001 From: delphi Date: Thu, 3 Apr 2025 10:03:45 +0800 Subject: [PATCH 3/4] add: build action notify --- .github/workflows/release.yml | 85 ++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc2c90c..ebbd851 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,4 +43,87 @@ jobs: gh release create "$tag" \ --title="$tag" \ --draft \ - main.js manifest.json styles.css \ No newline at end of file + main.js manifest.json styles.css + + - name: Send Notification + if: always() + env: + NOTIFY_WEBHOOK: ${{ vars.NOTIFY_WEBHOOK }} + run: | + tag="${GITHUB_REF#refs/tags/}" + repo_name="${GITHUB_REPOSITORY#*/}" + + # 根据任务状态设置消息内容 + if [ "${{ job.status }}" = "success" ]; then + status_emoji="✅" + status_text="成功" + button_text="🔍 确认发布" + header_emoji="🎉" + template_color="blue" + action_url="https://github.com/$GITHUB_REPOSITORY/releases/tag/$tag" + else + status_emoji="❌" + status_text="失败" + button_text="🔍 查看失败详情" + header_emoji="⚠️" + template_color="red" + action_url="https://github.com/$GITHUB_REPOSITORY/actions/runs/${{ github.run_id }}" + fi + + # 构建飞书消息 + curl -X POST -H "Content-Type: application/json" -d "{ + \"msg_type\": \"interactive\", + \"card\": { + \"schema\": \"2.0\", + \"config\": { + \"update_multi\": true, + \"style\": { + \"text_size\": { + \"normal_v2\": { + \"default\": \"normal\", + \"pc\": \"normal\", + \"mobile\": \"heading\" + } + } + } + }, + \"body\": { + \"direction\": \"vertical\", + \"padding\": \"12px 12px 12px 12px\", + \"elements\": [ + { + \"tag\": \"markdown\", + \"content\": \"📦 **${repo_name}** 新版本 **${tag}** 构建${status_text}\\n构建状态:${status_emoji} ${status_text}\", + \"text_align\": \"left\", + \"text_size\": \"normal_v2\", + \"margin\": \"0px 0px 0px 0px\" + }, + { + \"tag\": \"button\", + \"text\": { + \"tag\": \"plain_text\", + \"content\": \"${button_text}\" + }, + \"type\": \"default\", + \"width\": \"default\", + \"size\": \"medium\", + \"behaviors\": [ + { + \"type\": \"open_url\", + \"default_url\": \"${action_url}\" + } + ], + \"margin\": \"0px 0px 0px 0px\" + } + ] + }, + \"header\": { + \"title\": { + \"tag\": \"plain_text\", + \"content\": \"${header_emoji} 插件构建通知\" + }, + \"template\": \"${template_color}\", + \"padding\": \"12px 12px 12px 12px\" + } + } + }" "$NOTIFY_WEBHOOK" \ No newline at end of file From 9baf21b51ac8ed546bc56b3adad2e558ca8329b3 Mon Sep 17 00:00:00 2001 From: delphi Date: Thu, 3 Apr 2025 10:06:01 +0800 Subject: [PATCH 4/4] 1.0.3 --- manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- versions.json | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 9d41817..bb6094c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "cubox-sync", "name": "Cubox", - "version": "1.0.2", + "version": "1.0.3", "minAppVersion": "0.15.0", "description": "Sync your Cubox articles & annotation", "author": "delphi-2015", diff --git a/package-lock.json b/package-lock.json index 525d85a..6fc2302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-cubox", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-cubox", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "dependencies": { "luxon": "^3.1.1", diff --git a/package.json b/package.json index 8225b59..acea808 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-cubox", - "version": "1.0.2", + "version": "1.0.3", "description": "This is a cubox plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index 03d60fe..1da423a 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,6 @@ { "1.0.0": "0.15.0", "1.0.1": "0.15.0", - "1.0.2": "0.15.0" + "1.0.2": "0.15.0", + "1.0.3": "0.15.0" } \ No newline at end of file