Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c8449b04a | ||
|
|
cbf32b3f0b |
26
build.sh
26
build.sh
@@ -4,16 +4,24 @@ set -e # 出错立即退出
|
||||
# 1. 构建
|
||||
npm run build
|
||||
|
||||
# 2. 目标路径
|
||||
TARGET=~/myweb/.obsidian/plugins/note-to-mp/main.js
|
||||
BACKUP=~/myweb/.obsidian/plugins/note-to-mp/main.js.bk
|
||||
# 2. 目标目录
|
||||
PLUGIN_DIR=~/myweb/.obsidian/plugins/note-to-mp
|
||||
FILES=("main.js" "styles.css" "manifest.json")
|
||||
|
||||
# 3. 如果存在 main.js,先备份
|
||||
if [ -f "$TARGET" ]; then
|
||||
# 3. 遍历文件,逐一备份并覆盖
|
||||
for FILE in "${FILES[@]}"; do
|
||||
TARGET="$PLUGIN_DIR/$FILE"
|
||||
BACKUP="$PLUGIN_DIR/$FILE.bk"
|
||||
|
||||
if [ -f "$TARGET" ]; then
|
||||
cp -f "$TARGET" "$BACKUP"
|
||||
echo "已备份 $TARGET -> $BACKUP"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 4. 覆盖复制新的 main.js
|
||||
cp -f main.js "$TARGET"
|
||||
echo "已更新 $TARGET"
|
||||
if [ -f "$FILE" ]; then
|
||||
cp -f "$FILE" "$TARGET"
|
||||
echo "已更新 $TARGET"
|
||||
else
|
||||
echo "⚠️ 源文件 $FILE 不存在,跳过"
|
||||
fi
|
||||
done
|
||||
|
||||
39
src/main.ts
39
src/main.ts
@@ -38,6 +38,7 @@ import { XiaohongshuAPIManager } from './xiaohongshu/api';
|
||||
export default class NoteToMpPlugin extends Plugin {
|
||||
settings: NMPSettings;
|
||||
assetsManager: AssetsManager;
|
||||
ribbonIconEl: HTMLElement | null = null;
|
||||
constructor(app: App, manifest: PluginManifest) {
|
||||
super(app, manifest);
|
||||
AssetsManager.setup(app, manifest);
|
||||
@@ -55,6 +56,12 @@ export default class NoteToMpPlugin extends Plugin {
|
||||
uevent('load');
|
||||
this.app.workspace.onLayoutReady(()=>{
|
||||
this.loadResource();
|
||||
// 布局就绪后清理旧视图并自动打开一个新的标准预览(可选)
|
||||
this.cleanupLegacyViews();
|
||||
// 如果当前没有我们的预览叶子,自动激活一次,改善首次体验
|
||||
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_NOTE_PREVIEW).length === 0) {
|
||||
this.activateView();
|
||||
}
|
||||
})
|
||||
|
||||
this.registerView(
|
||||
@@ -62,10 +69,10 @@ export default class NoteToMpPlugin extends Plugin {
|
||||
(leaf) => new NotePreview(leaf, this)
|
||||
);
|
||||
|
||||
const ribbonIconEl = this.addRibbonIcon('clipboard-paste', '复制到公众号', (evt: MouseEvent) => {
|
||||
this.ribbonIconEl = this.addRibbonIcon('clipboard-paste', '复制到公众号', (evt: MouseEvent) => {
|
||||
this.activateView();
|
||||
});
|
||||
ribbonIconEl.addClass('note-to-mp-plugin-ribbon-class');
|
||||
this.ribbonIconEl.addClass('note-to-mp-plugin-ribbon-class');
|
||||
|
||||
this.addCommand({
|
||||
id: 'note-to-mp-preview',
|
||||
@@ -146,7 +153,35 @@ export default class NoteToMpPlugin extends Plugin {
|
||||
}
|
||||
|
||||
onunload() {
|
||||
console.log('Unloading NoteToMP');
|
||||
// 移除 ribbon icon,避免重载插件时重复创建
|
||||
if (this.ribbonIconEl) {
|
||||
this.ribbonIconEl.remove();
|
||||
this.ribbonIconEl = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理历史失效视图:
|
||||
* 某些用户可能曾使用过旧插件构建(例如 note-mp-preview-manager),升级后残留的标签页会提示“插件不再活动”。
|
||||
* 这里做一次性清理,避免用户手动关标签造成困扰。
|
||||
*/
|
||||
private cleanupLegacyViews() {
|
||||
try {
|
||||
const legacyIds = ['note-mp-preview-manager']; // 可扩展
|
||||
const { workspace } = this.app;
|
||||
// 遍历所有叶子,关闭可能的失效 view(无法直接匹配 id 时,仅检测报错视图类型)
|
||||
workspace.getLeavesOfType(VIEW_TYPE_NOTE_PREVIEW).forEach(l => {
|
||||
// 如果 view 的 plugin 不存在或 manifest id 不匹配我们当前的 id,则关闭
|
||||
const anyView: any = l.view;
|
||||
const vid = (anyView?.plugin?.manifest?.id) || '';
|
||||
if (vid && vid !== this.manifest.id && legacyIds.includes(vid)) {
|
||||
workspace.detachLeavesOfType(VIEW_TYPE_NOTE_PREVIEW);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn('[NoteToMp] cleanupLegacyViews 失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
|
||||
13
todolist.md
13
todolist.md
@@ -55,9 +55,20 @@
|
||||
|
||||
|
||||
## 问题
|
||||
1. "发布平台"选“小红书”时,预览页面没有加载当前文章。
|
||||
1. "发布平台"首次选“小红书”时,预览页面没有加载当前文章。
|
||||
2. 顶部按钮适应窗口宽度,超出窗口,折行显示。
|
||||
3. 页预览不完整,改为
|
||||
4. 修改:
|
||||
- 公共部分独立出来,如“发布平台”,放在新建platform-choose.ts中,“发布平台”选择切换平台逻辑放在该模块中,便于以后其他平台扩展。
|
||||
- 其他所有组件独立。node-preview.ts改为mp-preview.ts, 专门用于处理微信公众号模式下的页面和逻辑处理;preview-view.ts改为xhs-preview.ts,专门用于小红书模式下的页面和逻辑处理。
|
||||
|
||||
效果不理想。❌,需求修改如下:
|
||||
|
||||
目前mp-preview.ts中既实现微信公众号(micro-public,mp)的处理逻辑,又实现小红书(xiaohongshu,xhs)的处理逻辑。优化:
|
||||
- 平台选择的逻辑放在platform-choose.ts中。
|
||||
平台选择后,依据选择模式,调用mp-preview.ts(微信公众号mp)或xhs-preview.ts(小红书,xhs)中的方法。
|
||||
- mp-preview.ts中保留微信公众号模式(micro-public,mp)相关的处理逻辑。
|
||||
- mp-preview.ts中去掉小红书处理逻辑(移到xhs-preview.ts中)。
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user