This commit is contained in:
1 parent
04d15c7a5c
commit
0b496ba582
4 files changed
+51
-7
No files matched your search
@@ -20,6 +20,7 @@ export interface PostMeta {
|
||||
title: string;
|
||||
published_at: string;
|
||||
category_slug?: string;
|
||||
category_name?: string;
|
||||
}
|
||||
|
||||
export interface PostDetail extends PostMeta {
|
||||
|
||||
@@ -97,7 +97,7 @@ export default class BlogFlarePlugin extends Plugin {
|
||||
|
||||
this.addCommand({
|
||||
id: 'publish-post',
|
||||
name: '发布文章 (push)',
|
||||
name: '发布文章',
|
||||
checkCallback: (checking: boolean) => {
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const file = activeView?.file;
|
||||
@@ -164,7 +164,7 @@ export default class BlogFlarePlugin extends Plugin {
|
||||
|
||||
this.addCommand({
|
||||
id: 'pull-post',
|
||||
name: '拉取文章 (pull)',
|
||||
name: '拉取文章',
|
||||
callback: () => {
|
||||
this.api.getPosts().then(items => {
|
||||
if (items.length === 0) {
|
||||
@@ -181,7 +181,7 @@ export default class BlogFlarePlugin extends Plugin {
|
||||
|
||||
this.addCommand({
|
||||
id: 'init-sync',
|
||||
name: '全量拉取初始化 (init sync)',
|
||||
name: '全量拉取初始化',
|
||||
callback: () => {
|
||||
const mdFiles = this.app.vault.getMarkdownFiles();
|
||||
if (mdFiles.length > 0) {
|
||||
@@ -219,7 +219,17 @@ export default class BlogFlarePlugin extends Plugin {
|
||||
|
||||
const fileContent = frontmatterLines.join('\n') + '\n\n' + (detail.content || '');
|
||||
|
||||
const fileName = `${detail.title.replace(/[/\\:]/g, '-')}.md`;
|
||||
const baseName = detail.title.replace(/[/\\:]/g, '-');
|
||||
let dirPath = '';
|
||||
const categoryDir = detail.category_name || detail.category_slug;
|
||||
if (categoryDir) {
|
||||
dirPath = categoryDir.replace(/[/\\:]/g, '-');
|
||||
const folder = this.app.vault.getAbstractFileByPath(dirPath);
|
||||
if (!folder) {
|
||||
await this.app.vault.createFolder(dirPath);
|
||||
}
|
||||
}
|
||||
const fileName = dirPath ? `${dirPath}/${baseName}.md` : `${baseName}.md`;
|
||||
await this.app.vault.create(fileName, fileContent);
|
||||
successCount++;
|
||||
} catch (err) {
|
||||
@@ -238,7 +248,7 @@ export default class BlogFlarePlugin extends Plugin {
|
||||
|
||||
this.addCommand({
|
||||
id: 'delete-post',
|
||||
name: '下线云端文章 (delete)',
|
||||
name: '下线云端文章',
|
||||
checkCallback: (checking: boolean) => {
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const file = activeView?.file;
|
||||
|
||||
@@ -40,7 +40,17 @@ export class PullSuggestModal extends FuzzySuggestModal<PostMeta> {
|
||||
const fileContent = frontmatterLines.join('\n') + '\n\n' + (detail.content || '');
|
||||
|
||||
// 决定文件名 (过滤掉非法字符)
|
||||
const fileName = `${detail.title.replace(/[/\\:]/g, '-')}.md`;
|
||||
const baseName = detail.title.replace(/[/\\:]/g, '-');
|
||||
let dirPath = '';
|
||||
const categoryDir = detail.category_name || detail.category_slug;
|
||||
if (categoryDir) {
|
||||
dirPath = categoryDir.replace(/[/\\:]/g, '-');
|
||||
const folder = this.app.vault.getAbstractFileByPath(dirPath);
|
||||
if (!folder) {
|
||||
await this.app.vault.createFolder(dirPath);
|
||||
}
|
||||
}
|
||||
const fileName = dirPath ? `${dirPath}/${baseName}.md` : `${baseName}.md`;
|
||||
|
||||
// 检查是否已有该文件
|
||||
let file = this.app.vault.getAbstractFileByPath(fileName);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App, PluginSettingTab, Setting } from 'obsidian';
|
||||
import { App, PluginSettingTab, Setting, Notice } from 'obsidian';
|
||||
import BlogFlarePlugin from './main';
|
||||
|
||||
export interface BlogFlareSettings {
|
||||
@@ -44,5 +44,28 @@ export class BlogFlareSettingTab extends PluginSettingTab {
|
||||
this.plugin.settings.apiToken = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('测试连接')
|
||||
.setDesc('验证当前配置的 Endpoint 与 API 令牌是否能正确连接到 Blogflare 后端')
|
||||
.addButton((button) => {
|
||||
button
|
||||
.setButtonText('测试')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
button.setButtonText('测试中...');
|
||||
button.setDisabled(true);
|
||||
try {
|
||||
await this.plugin.api.getCategories();
|
||||
new Notice('✅ 连接成功!API 令牌有效。');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
new Notice('❌ 连接失败:API 令牌无效或网络错误,请检查设置。');
|
||||
} finally {
|
||||
button.setButtonText('测试');
|
||||
button.setDisabled(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user