TemplateInstructions

This commit is contained in:
delphi 2025-02-26 18:44:11 +08:00
parent bc62105b0a
commit 9e37aa7bfb
3 changed files with 171 additions and 26 deletions

View file

@ -3,6 +3,7 @@ import { CuboxApi, CuboxApiOptions } from './cuboxApi';
import { TemplateProcessor } from './templateProcessor';
import { formatISODateTime, getCurrentFormattedTime } from './utils';
import { FolderSelectModal } from './folderSelectModal';
import { filenameTemplateInstructions, metadataTemplateInstructions, contentTemplateInstructions } from './templateInstructions';
interface CuboxSyncSettings {
domain: string; // 可以是 'cubox.cc' | 'cubox.pro' | ''
@ -397,31 +398,69 @@ class CuboxSyncSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));
// 更新文件名模板设置
const filenameInstructionsFragment = document.createRange().createContextualFragment(filenameTemplateInstructions);
new Setting(containerEl)
.setName('File Name Template')
.setDesc('Enter the file name when the data is stored')
.setDesc(filenameInstructionsFragment)
.addText(text => text
.setPlaceholder('Enter file name template')
.setValue(this.plugin.settings.filenameTemplate)
.onChange(async (value) => {
this.plugin.settings.filenameTemplate = value;
await this.plugin.saveSettings();
}))
.addButton(button => button
.setIcon('reset')
.setTooltip('Reset to default')
.onClick(async () => {
this.plugin.settings.filenameTemplate = DEFAULT_SETTINGS.filenameTemplate;
await this.plugin.saveSettings();
this.display(); // 刷新显示
}));
// 为参考链接添加事件监听器
containerEl.querySelectorAll('.reference-link').forEach(el => {
el.addEventListener('click', (e) => {
e.preventDefault();
// 这里可以添加打开参考文档的逻辑
});
});
// 更新前置元数据模板设置
const metadataInstructionsFragment = document.createRange().createContextualFragment(metadataTemplateInstructions);
new Setting(containerEl)
.setName('Front Matter')
.setDesc('Enter the metadata')
.setName('Metadata Template')
.setDesc(metadataInstructionsFragment)
.addTextArea(text => text
.setPlaceholder('Enter front matter template')
.setValue(this.plugin.settings.frontMatterTemplate)
.onChange(async (value) => {
this.plugin.settings.frontMatterTemplate = value;
await this.plugin.saveSettings();
})
// 设置文本区域的大小
.then(textArea => {
textArea.inputEl.rows = 6;
textArea.inputEl.cols = 50;
}))
.addButton(button => button
.setIcon('reset')
.setTooltip('Reset to default')
.onClick(async () => {
this.plugin.settings.frontMatterTemplate = DEFAULT_SETTINGS.frontMatterTemplate;
await this.plugin.saveSettings();
this.display(); // 刷新显示
}));
// 更新内容模板设置
const contentInstructionsFragment = document.createRange().createContextualFragment(contentTemplateInstructions);
new Setting(containerEl)
.setName('Content Template')
.setDesc('Enter the file name when the data is stored')
.setDesc(contentInstructionsFragment)
.addTextArea(text => text
.setPlaceholder('Enter content template')
.setValue(this.plugin.settings.contentTemplate)
@ -431,29 +470,16 @@ class CuboxSyncSettingTab extends PluginSettingTab {
})
// 设置文本区域的大小
.then(textArea => {
textArea.inputEl.rows = 8; // 设置行数
textArea.inputEl.cols = 50; // 设置列数
}));
new Setting(containerEl)
.setName('Highlight Text in Content')
.setDesc('Highlight text in articles')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.highlightInContent)
.onChange(async (value) => {
this.plugin.settings.highlightInContent = value;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Date Format')
.setDesc('Enter the xxxxx, 0 means manual sync')
.addText(text => text
.setPlaceholder('Enter date format')
.setValue(this.plugin.settings.dateFormat)
.onChange(async (value) => {
this.plugin.settings.dateFormat = value;
textArea.inputEl.rows = 8;
textArea.inputEl.cols = 50;
}))
.addButton(button => button
.setIcon('reset')
.setTooltip('Reset to default')
.onClick(async () => {
this.plugin.settings.contentTemplate = DEFAULT_SETTINGS.contentTemplate;
await this.plugin.saveSettings();
this.display(); // 刷新显示
}));
// 状态部分

View file

@ -0,0 +1,76 @@
export const filenameTemplateInstructions = `
Enter template for creating synced article file name.
<div class="cubox-variables-container">
<div class="cubox-variables-title">Available variables</div>
<ul class="cubox-variables-list">
<li>{{card_title}}</li>
<li>{{article_title}}</li>
<li>{{date_saved}}</li>
<li>{{date_updated}}</li>
<li>{{site_domain}}</li>
<li>{{type}}</li>
</ul>
<div class="cubox-reference">For more, refer to <a href="#" class="reference-link">reference</a>.</div>
</div>
`;
export const metadataTemplateInstructions = `
Enter the metadata separated by comma. you can also use custom aliases in the format of metadata::alias.
<div class="cubox-variables-container">
<div class="cubox-variables-title">Available variables</div>
<ul class="cubox-variables-list">
<li>card_title</li>
<li>article_title</li>
<li>tags</li>
<li>date_saved</li>
<li>date_updated</li>
<li>site_domain</li>
<li>original_url</li>
<li>cubox_url</li>
<li>description</li>
<li>words_count</li>
<li>type</li>
<li>id</li>
</ul>
<div class="cubox-reference">For more, refer to <a href="#" class="reference-link">reference</a>.</div>
</div>
`;
export const contentTemplateInstructions = `
Enter template for creating synced article content.
<div class="cubox-variables-container">
<div class="cubox-variables-title">Available variables</div>
<ul class="cubox-variables-list">
<li>{{id}}</li>
<li>{{card_title}}</li>
<li>{{description}}</li>
<li>{{article_title}}</li>
<li>{{content}}</li>
<li>{{content_highlighted}}</li>
<li>{{highlights}}</li>
<li class="highlight-item">
{{highlight_text}}
<ul class="highlight-sublist">
<li>{{highlight_text}}</li>
<li>{{highlight_url}}</li>
<li>{{highlight_note}}</li>
<li>{{date_highlighted}}</li>
<li>{{highlight_id}}</li>
<li>{{highlight_color}}</li>
</ul>
</li>
<li>{{tags}}</li>
<li>{{date_saved}}</li>
<li>{{date_updated}}</li>
<li>{{site_domain}}</li>
<li>{{original_url}}</li>
<li>{{cubox_url}}</li>
<li>{{description}}</li>
<li>{{words_count}}</li>
</ul>
<div class="cubox-reference">For more, refer to <a href="#" class="reference-link">reference</a>.</div>
</div>
`;

View file

@ -36,3 +36,46 @@ If your plugin does not need CSS, delete this file.
background-color: var(--interactive-accent);
color: var(--text-on-accent);
}
/* 变量列表样式优化 */
.cubox-variables-container {
margin: 20px 0;
color: var(--text-muted);
}
.cubox-variables-title {
font-weight: 500;
margin-bottom: 8px;
color: var(--text-normal);
}
.cubox-variables-list {
margin: 0;
padding-left: 20px;
list-style-type: disc;
}
.cubox-variables-list li {
margin-bottom: 4px;
line-height: 1.5;
}
.highlight-sublist {
margin-top: 4px;
padding-left: 20px;
list-style-type: circle;
}
.cubox-reference {
margin-top: 10px;
font-size: 0.9em;
}
.reference-link {
color: var(--text-accent);
text-decoration: none;
}
.reference-link:hover {
text-decoration: underline;
}