Merge branch 'develop'

This commit is contained in:
delphi 2025-04-03 10:06:55 +08:00
commit 0ee78f128e
8 changed files with 148 additions and 40 deletions

View file

@ -43,4 +43,87 @@ jobs:
gh release create "$tag" \
--title="$tag" \
--draft \
main.js manifest.json styles.css
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"

View file

@ -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",

4
package-lock.json generated
View file

@ -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",

View file

@ -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": {

View file

@ -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);

View file

@ -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(

View file

@ -313,4 +313,22 @@ export class TemplateProcessor {
private getArticleProperty(article: CuboxArticle, propertyName: string): unknown {
return (article as unknown as Record<string, unknown>)[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}}}');
}
}

View file

@ -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"
}