update at 2025-10-16 14:03:45

This commit is contained in:
douboer
2025-10-16 14:03:45 +08:00
parent b9feb2f764
commit 93afc99e7d
14 changed files with 78 additions and 72 deletions

View File

@@ -200,7 +200,7 @@ export class ArticleRender implements MDRendererCallback {
errorContent(error: any) {
return '<h1>渲染失败!</h1><br/>'
+ '如需帮助请前往&nbsp;&nbsp;<a href="https://github.com/sunbooshi/note-to-mp/issues">https://github.com/sunbooshi/note-to-mp/issues</a>&nbsp;&nbsp;反馈<br/><br/>'
+ '如需帮助请前往&nbsp;&nbsp;<a href="https://github.com/sunbooshi/note2any/issues">https://github.com/sunbooshi/note2any/issues</a>&nbsp;&nbsp;反馈<br/><br/>'
+ '如果方便请提供引发错误的完整Markdown内容。<br/><br/>'
+ '<br/>Obsidian版本' + apiVersion
+ '<br/>错误信息:<br/>'
@@ -341,11 +341,11 @@ export class ArticleRender implements MDRendererCallback {
try {
const globalAny = window as any;
const now = Date.now();
if (!globalAny.__note2mp_lastPathLog ||
globalAny.__note2mp_lastPathLog.path !== file.path ||
now - globalAny.__note2mp_lastPathLog.time > 3000) {
console.log('[note2mp] active file path:', file.path);
globalAny.__note2mp_lastPathLog = { path: file.path, time: now };
if (!globalAny.__note2any_lastPathLog ||
globalAny.__note2any_lastPathLog.path !== file.path ||
now - globalAny.__note2any_lastPathLog.time > 3000) {
console.log('[note2any] active file path:', file.path);
globalAny.__note2any_lastPathLog = { path: file.path, time: now };
}
} catch {}
const metadata = this.app.metadataCache.getFileCache(file);
@@ -475,7 +475,7 @@ export class ArticleRender implements MDRendererCallback {
if (base) res.cover = `![[${base}]]`;
}
if (res.cover) {
try { console.log('[note2mp] use default cover:', def, '->', res.cover); } catch {}
try { console.log('[note2any] use default cover:', def, '->', res.cover); } catch {}
}
}
}

View File

@@ -297,7 +297,7 @@ export default class AssetsManager {
getThemeURL() {
const version = this.manifest.version;
return `https://github.com/sunbooshi/note-to-mp/releases/download/${version}/assets.zip`;
return `https://github.com/sunbooshi/note2any/releases/download/${version}/assets.zip`;
}
async getStyle() {

View File

@@ -8,7 +8,7 @@
import { App, Modal, Setting, TFile, Notice, ButtonComponent } from 'obsidian';
import { BatchArticleFilter, BatchFilterConfig } from './batch-filter';
import NoteToMpPlugin from './main';
import Note2AnyPlugin from './main';
// 小红书功能模块
import { XiaohongshuContentAdapter } from './xiaohongshu/adapter';
import { XiaohongshuAPIManager } from './xiaohongshu/api';
@@ -34,7 +34,7 @@ import { XiaohongshuAPIManager } from './xiaohongshu/api';
*/
export class BatchPublishModal extends Modal {
plugin: NoteToMpPlugin;
plugin: Note2AnyPlugin;
filter: BatchArticleFilter;
filteredFiles: TFile[] = [];
selectedFiles: Set<TFile> = new Set();
@@ -69,7 +69,7 @@ export class BatchPublishModal extends Modal {
orderDirection: 'asc'
};
constructor(app: App, plugin: NoteToMpPlugin) {
constructor(app: App, plugin: Note2AnyPlugin) {
super(app);
this.plugin = plugin;
this.filter = new BatchArticleFilter(app);

View File

@@ -10,7 +10,7 @@
import { Plugin, WorkspaceLeaf, App, PluginManifest, Menu, Notice, TAbstractFile, TFile, TFolder } from 'obsidian';
import { PreviewView, VIEW_TYPE_NOTE_PREVIEW } from './preview-view';
import { NMPSettings } from './settings';
import { NoteToMpSettingTab } from './setting-tab';
import { Note2AnySettingTab } from './setting-tab';
import AssetsManager from './assets';
import { setVersion, uevent } from './utils';
import { WidgetsModal } from './widgets-modal';
@@ -20,7 +20,7 @@ import { XiaohongshuContentAdapter } from './xiaohongshu/adapter';
import { XiaohongshuAPIManager } from './xiaohongshu/api';
/**
* NoteToMpPlugin
* Note2AnyPlugin
*
* 中文说明:
* 这是插件的入口类,负责:
@@ -30,12 +30,12 @@ import { XiaohongshuAPIManager } from './xiaohongshu/api';
* - 提供文件右键菜单扩展,支持对单文件或文件夹进行发布操作
*
* 设计决策(简要):
* - 将批量发布的 UI 放在 `BatchPublishModal` 中,命令 `note-to-mp-batch-publish` 会打开该模态框
* - 将批量发布的 UI 放在 `BatchPublishModal` 中,命令 `note2any-batch-publish` 会打开该模态框
* - 单篇发布/文件夹批量发布仍复用 `NotePreview` 的发布逻辑,避免重复实现上传流程
*/
export default class NoteToMpPlugin extends Plugin {
export default class Note2AnyPlugin extends Plugin {
settings: NMPSettings;
assetsManager: AssetsManager;
ribbonIconEl: HTMLElement | null = null;
@@ -51,35 +51,35 @@ export default class NoteToMpPlugin extends Plugin {
}
async onload() {
console.log('Loading NoteToMP (plugin onload start)');
console.log('Loading Note2Any (plugin onload start)');
setVersion(this.manifest.version);
uevent('load');
console.log('[NoteToMpPlugin] workspace.layoutReady at onload =', this.app.workspace.layoutReady);
console.log('[Note2AnyPlugin] workspace.layoutReady at onload =', this.app.workspace.layoutReady);
// 先注册 view 之前,防止旧 snapshot 立即恢复创建大量视图:先临时卸载残留叶子(如果类型匹配)
try {
const legacyLeaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_NOTE_PREVIEW);
if (legacyLeaves.length > 0) {
console.log('[NoteToMpPlugin] detach legacy leaves early count=', legacyLeaves.length);
console.log('[Note2AnyPlugin] detach legacy leaves early count=', legacyLeaves.length);
this.app.workspace.detachLeavesOfType(VIEW_TYPE_NOTE_PREVIEW);
}
} catch (e) {
console.warn('[NoteToMpPlugin] early detach failed', e);
console.warn('[Note2AnyPlugin] early detach failed', e);
}
this.app.workspace.onLayoutReady(async () => {
console.log('[NoteToMpPlugin] onLayoutReady callback entered');
console.time('[NoteToMpPlugin] startup:onLayoutReady→loadResource');
console.log('[Note2AnyPlugin] onLayoutReady callback entered');
console.time('[Note2AnyPlugin] startup:onLayoutReady→loadResource');
try {
await this.loadResource(); // 确保资源完全加载完再继续,避免后续视图初始化反复等待
} catch (e) {
console.error('[NoteToMpPlugin] loadResource 失败', e);
console.error('[Note2AnyPlugin] loadResource 失败', e);
} finally {
console.timeEnd('[NoteToMpPlugin] startup:onLayoutReady→loadResource');
console.timeEnd('[Note2AnyPlugin] startup:onLayoutReady→loadResource');
}
// 清理旧视图
this.cleanupLegacyViews();
// 取消自动打开预览视图(用于排查启动卡顿)。用户可通过图标或命令手动打开。
// console.log('[NoteToMpPlugin] 已跳过自动打开预览视图调试模式');
// console.log('[Note2AnyPlugin] 已跳过自动打开预览视图调试模式');
});
this.registerView(
@@ -90,28 +90,28 @@ export default class NoteToMpPlugin extends Plugin {
this.ribbonIconEl = this.addRibbonIcon('clipboard-paste', '复制到公众号', (evt: MouseEvent) => {
this.activateView();
});
this.ribbonIconEl.addClass('note-to-mp-plugin-ribbon-class');
this.ribbonIconEl.addClass('note2any-plugin-ribbon-class');
this.addCommand({
id: 'note-to-mp-preview',
id: 'note2any-preview',
name: '复制到公众号',
callback: () => {
this.activateView();
}
});
this.addSettingTab(new NoteToMpSettingTab(this.app, this));
this.addSettingTab(new Note2AnySettingTab(this.app, this));
this.addCommand({
id: 'note-to-mp-widget',
name: '插入样式小部件',
id: 'note2any-widget',
name: '插入样式件',
callback: () => {
new WidgetsModal(this.app).open();
}
});
this.addCommand({
id: 'note-to-mp-batch-publish',
id: 'note2any-batch-publish',
name: '批量发布文章',
callback: () => {
new BatchPublishModal(this.app, this).open();
@@ -120,7 +120,7 @@ export default class NoteToMpPlugin extends Plugin {
// TODO: 重构后需要重新实现批量发布功能
// this.addCommand({
// id: 'note-to-mp-pub',
// id: 'note2any-pub',
// name: '发布公众号文章',
// callback: async () => {
// await this.activateView();
@@ -130,7 +130,7 @@ export default class NoteToMpPlugin extends Plugin {
// 命令:当前文件发布到微信草稿
this.addCommand({
id: 'note-to-mp-post-current',
id: 'note2any-post-current',
name: '发布当前文件到公众号草稿',
callback: async () => {
const file = this.app.workspace.getActiveFile();
@@ -181,7 +181,7 @@ export default class NoteToMpPlugin extends Plugin {
}
onunload() {
console.log('Unloading NoteToMP');
console.log('Unloading Note2Any');
// 移除 ribbon icon避免重载插件时重复创建
if (this.ribbonIconEl) {
this.ribbonIconEl.remove();
@@ -208,7 +208,7 @@ export default class NoteToMpPlugin extends Plugin {
}
});
} catch (e) {
console.warn('[NoteToMp] cleanupLegacyViews 失败', e);
console.warn('[Note2Any] cleanupLegacyViews 失败', e);
}
}

View File

@@ -4,19 +4,19 @@
*/
import { App, TextAreaComponent, PluginSettingTab, Setting, Notice, sanitizeHTMLToDom } from 'obsidian';
import NoteToMpPlugin from './main';
import Note2AnyPlugin from './main';
import { wxGetToken, wxEncrypt } from './wechat/weixin-api';
import { cleanMathCache } from './markdown/math';
import { NMPSettings } from './settings';
import { DocModal } from './doc-modal';
export class NoteToMpSettingTab extends PluginSettingTab {
plugin: NoteToMpPlugin;
export class Note2AnySettingTab extends PluginSettingTab {
plugin: Note2AnyPlugin;
wxInfo: string;
wxTextArea: TextAreaComponent|null;
settings: NMPSettings;
constructor(app: App, plugin: NoteToMpPlugin) {
constructor(app: App, plugin: Note2AnyPlugin) {
super(app, plugin);
this.plugin = plugin;
this.settings = NMPSettings.getInstance();
@@ -425,7 +425,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
private renderImageTab(panel: HTMLElement): void {
new Setting(panel)
.setName('切图保存路径')
.setDesc('切图文件的保存目录,默认:/Users/gavin/note2mp/images/xhs')
.setDesc('切图文件的保存目录,默认:/Users/gavin/note2any/images/xhs')
.addText(text => {
text.setPlaceholder('例如 /Users/xxx/images/xhs')
.setValue(this.settings.sliceImageSavePath || '')

View File

@@ -100,7 +100,7 @@ export class NMPSettings {
}
];
// 切图配置默认值
this.sliceImageSavePath = '/Users/gavin/note2mp/images/xhs';
this.sliceImageSavePath = '/Users/gavin/note2any/images/xhs';
this.sliceImageWidth = 1080;
this.sliceImageAspectRatio = '3:4';
this.xhsPreviewWidth = 540;

View File

@@ -31,7 +31,7 @@ export function setVersion(version: string) {
function getStyleSheet() {
for (var i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
if (sheet.title == 'note-to-mp-style') {
if (sheet.title == 'note2any-style') {
return sheet;
}
}

View File

@@ -460,7 +460,7 @@ export class XiaohongshuPreview {
private async persistSettings(): Promise<void> {
try {
const plugin = (this.app as any)?.plugins?.getPlugin?.('note-to-mp');
const plugin = (this.app as any)?.plugins?.getPlugin?.('note2any');
if (plugin?.saveSettings) {
await plugin.saveSettings();
}