mirror of
https://github.com/woodchen-ink/obsidian-publish-to-discourse.git
synced 2025-07-18 05:42:05 +08:00
新增跳过一级标题选项,优化发布到 Discourse 的内容处理
- 在配置中添加 skipH1 字段,默认为 false - 更新发布逻辑,支持根据设置跳过 Markdown 中的 H1 标题 - 添加相应的国际化支持,包括英文和中文描述
This commit is contained in:
parent
57863bb962
commit
0c97380a32
@ -7,13 +7,15 @@ export interface DiscourseSyncSettings {
|
||||
apiKey: string;
|
||||
disUser: string;
|
||||
category: number;
|
||||
skipH1: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: DiscourseSyncSettings = {
|
||||
baseUrl: "https://yourforum.example.com",
|
||||
apiKey: "apikey",
|
||||
disUser: "DiscourseUsername",
|
||||
category: 1
|
||||
category: 1,
|
||||
skipH1: false
|
||||
};
|
||||
|
||||
export class DiscourseSyncSettingsTab extends PluginSettingTab {
|
||||
@ -65,6 +67,18 @@ export class DiscourseSyncSettingsTab extends PluginSettingTab {
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t('SKIP_H1'))
|
||||
.setDesc(t('SKIP_H1_DESC'))
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.skipH1)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.skipH1 = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(t('TEST_API_KEY'))
|
||||
.setDesc('')
|
||||
|
@ -6,6 +6,8 @@ export default {
|
||||
'API_KEY_DESC': "API key created in '/admin/api/keys'",
|
||||
'USERNAME': 'Username',
|
||||
'USERNAME_DESC': 'Your Discourse username',
|
||||
'SKIP_H1': 'Skip First Heading',
|
||||
'SKIP_H1_DESC': 'Skip the first heading (H1) when publishing to Discourse',
|
||||
'TEST_API_KEY': 'Test Connection',
|
||||
'TESTING': 'Testing...',
|
||||
'API_TEST_SUCCESS': 'Connection successful! API key is valid',
|
||||
|
@ -6,6 +6,8 @@ export default {
|
||||
'API_KEY_DESC': "在'/admin/api/keys'中创建的 API 密钥",
|
||||
'USERNAME': '用户名',
|
||||
'USERNAME_DESC': 'Discourse 用户名',
|
||||
'SKIP_H1': '跳过一级标题',
|
||||
'SKIP_H1_DESC': '发布到 Discourse 时跳过笔记中的一级标题',
|
||||
'TEST_API_KEY': '测试连接',
|
||||
'TESTING': '测试中...',
|
||||
'API_TEST_SUCCESS': '连接成功!API密钥有效',
|
||||
|
@ -182,6 +182,12 @@ export default class PublishToDiscourse extends Plugin implements PluginInterfac
|
||||
// 替换嵌入引用为Markdown格式
|
||||
content = this.embedHandler.replaceEmbedReferences(content, embedReferences, uploadedUrls);
|
||||
|
||||
// 如果启用了"跳过一级标题"选项,则删除所有H1标题
|
||||
if (this.settings.skipH1) {
|
||||
// 匹配Markdown中的所有H1标题(# 标题)
|
||||
content = content.replace(/^\s*# [^\n]+\n?/gm, '');
|
||||
}
|
||||
|
||||
// 获取Front Matter
|
||||
const frontMatter = getFrontMatter(this.activeFile.content);
|
||||
const postId = frontMatter?.discourse_post_id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user