8 Commits

Author SHA1 Message Date
douboer
5e1351408e update at 2025-10-16 14:06:24 2025-10-16 14:06:24 +08:00
douboer
93afc99e7d update at 2025-10-16 14:03:45 2025-10-16 14:03:45 +08:00
douboer
b9feb2f764 update at 2025-10-13 20:53:32 2025-10-13 20:53:32 +08:00
douboer
97a70bc23b update at 2025-10-10 23:45:02 2025-10-10 23:45:03 +08:00
douboer
437619cfff update at 2025-10-10 22:48:36 2025-10-10 22:48:36 +08:00
douboer
10ef109353 update at 2025-10-10 22:21:06 2025-10-10 22:21:06 +08:00
douboer
1d52f79e0c update at 2025-10-10 21:55:46 2025-10-10 21:55:46 +08:00
douboer
0ab20de880 update at 2025-10-10 21:54:05 2025-10-10 21:54:05 +08:00
21 changed files with 471 additions and 305 deletions

View File

@@ -1,8 +1,8 @@
## 更新说明 ## 更新说明
> [!IMPORTANT] > [!IMPORTANT]
> NoteToMP 1.3.0版本对主题进行了优化,升级后请先清理旧版本主题文件,再重新下载新版主题。 > Note2Any 1.3.0版本对主题进行了优化,升级后请先清理旧版本主题文件,再重新下载新版主题。
> >
> 操作步骤在NoteToMP插件设置中,先点击『清空主题-清空』,然后点击『获取更多主题-下载』 > 操作步骤在Note2Any插件设置中,先点击『清空主题-清空』,然后点击『获取更多主题-下载』
> >
> 注意:如果修改过主题文件请做备份后再操作。 > 注意:如果修改过主题文件请做备份后再操作。
@@ -49,30 +49,30 @@
``` ```
路径日志做了节流:同一文件 3 秒内不重复打印。后续可加"调试开关"以完全关闭。 路径日志做了节流:同一文件 3 秒内不重复打印。后续可加"调试开关"以完全关闭。
### 摘要、封面裁剪、原文链接等ges/screenshot.png) ### 摘要、封面裁剪、原文链接等
## 2、安装 ## 2、安装
首先,**请确认已关闭了Obsidian的安全模式**。如未关闭,请通过**设置——第三方插件——关闭安全模式**关闭。 首先,**请确认已关闭了Obsidian的安全模式**。如未关闭,请通过**设置——第三方插件——关闭安全模式**关闭。
### 2.1 插件安装 ### 2.1 插件安装
#### 从官方**社区插件市场**安装 #### 从官方**社区插件市场**安装
通过Obsidian**设置——第三方插件——社区插件市场**,输入**NoteToMP**搜索安装。 通过Obsidian**设置——第三方插件——社区插件市场**,输入**Note2Any**搜索安装。
### 2.2 主题资源安装 ### 2.2 主题资源安装
如果采用的是用从插件市场或者Github下载安装的方式在插件安装完成后还需要再下载主题资源。网盘里的安装包已经集成了主题样式无需下载。 如果采用的是用从插件市场或者Github下载安装的方式在插件安装完成后还需要再下载主题资源。网盘里的安装包已经集成了主题样式无需下载。
**1通过设置下载** **1通过设置下载**
为了尽可能保证插件符合官方规范主题和代码高亮需要打开Obsidian的**设置**界面,在底部的**第三方插件**——**Note to MP**——**获取更多主题**手动下载。 为了尽可能保证插件符合官方规范主题和代码高亮需要打开Obsidian的**设置**界面,在底部的**第三方插件**——**Note 2 Any**——**获取更多主题**手动下载。
**2手动下载** **2手动下载**
也可以直接在[Release](https://github.com/sunbooshi/note-to-mp/releases)页面下载`assets.zip`文件,解压后放到`.obsidian/plugins/note-to-mp/assets`目录下。 也可以直接在[Release](https://biboer.cn/gitea/gavin/note2any/releases)页面下载`assets.zip`文件,解压后放到`.obsidian/plugins/note2any/assets`目录下。
### 2.3 常见安装问题 ### 2.3 常见安装问题
**只有默认主题** **只有默认主题**
确认根据**2.2 主题资源安装**里的步骤操作了,然后检查一下插件目录内容,应如下所示: 确认根据**2.2 主题资源安装**里的步骤操作了,然后检查一下插件目录内容,应如下所示:
``` ```
.obsidian/plugins/note-to-mp/ .obsidian/plugins/note2any/
├── assets ├── assets
│ ├── themes.json │ ├── themes.json
│ ├── highlights.json │ ├── highlights.json
@@ -177,36 +177,36 @@ c=+-sqrt(a^2+b^2)
``` ```
```` ````
然后打开NoteToMP插件设置,将**自定义样式**即包含自定义CSS内容的笔记名称粘贴到**自定义CSS笔记**中即可。如果不使用自定义CSS留空即可。 然后打开Note2Any插件设置,将**自定义样式**即包含自定义CSS内容的笔记名称粘贴到**自定义CSS笔记**中即可。如果不使用自定义CSS留空即可。
关于自定义CSS的写法可以参考下面的代码 关于自定义CSS的写法可以参考下面的代码
```css ```css
/* 全局属性 /* 全局属性
* 这里可以设置字体,字体大小,边距,背景颜色等 * 这里可以设置字体,字体大小,边距,背景颜色等
*/ */
.note-to-mp { .note2any {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 段落 */ /* 段落 */
.note-to-mp p { .note2any p {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 一级标题 */ /* 一级标题 */
.note-to-mp h1 { .note2any h1 {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 二级标题 */ /* 二级标题 */
.note-to-mp h2 { .note2any h2 {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 三级标题 */ /* 三级标题 */
.note-to-mp h3 { .note2any h3 {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
@@ -214,38 +214,38 @@ c=+-sqrt(a^2+b^2)
/* 无序列表整体样式 /* 无序列表整体样式
* list-style-type: square|circle|disc; * list-style-type: square|circle|disc;
*/ */
.note-to-mp ul { .note2any ul {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 加粗 */ /* 加粗 */
.note-to-mp strong { .note2any strong {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 斜体 */ /* 斜体 */
.note-to-mp em { .note2any em {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 加粗斜体 */ /* 加粗斜体 */
.note-to-mp em strong { .note2any em strong {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 删除线 */ /* 删除线 */
.note-to-mp del { .note2any del {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 分隔线 /* 分隔线
*/ */
.note-to-mp hr { .note2any hr {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* 图片 /* 图片
*/ */
.note-to-mp img { .note2any img {
/* 注:请在大括号内改写!!! */ /* 注:请在大括号内改写!!! */
} }
/* /*
@@ -288,7 +288,7 @@ c=+-sqrt(a^2+b^2)
例如这篇文章[几个让公众号排版更精致的小技巧,手机上也可以!](https://mp.weixin.qq.com/s/Q4_pV9TW8un3qZ0vrUvD1A)👈️使用的自定义样式如下: 例如这篇文章[几个让公众号排版更精致的小技巧,手机上也可以!](https://mp.weixin.qq.com/s/Q4_pV9TW8un3qZ0vrUvD1A)👈️使用的自定义样式如下:
```css ```css
.note-to-mp { .note2any {
font-family: Optima-regular, Optima, "Microsoft YaHei", PingFangSC-regular, serif; font-family: Optima-regular, Optima, "Microsoft YaHei", PingFangSC-regular, serif;
} }
@@ -313,7 +313,7 @@ section .note-callout-example {
background-color: rgba(90, 185, 131, 0.1); background-color: rgba(90, 185, 131, 0.1);
} }
``` ```
上面的例子,通过`.note-to-mp`指定了文章的字体,通过`h2 strong`单独定义了h2标题下strong的样式这样可以在标题中通过使用粗体增加了一个边框样式。通过`h2`定义了h2标题的底部线条的宽度和文本颜色。这样配合**Olive Dunk**主题就形成了自己的风格。 上面的例子,通过`.note2any`指定了文章的字体,通过`h2 strong`单独定义了h2标题下strong的样式这样可以在标题中通过使用粗体增加了一个边框样式。通过`h2`定义了h2标题的底部线条的宽度和文本颜色。这样配合**Olive Dunk**主题就形成了自己的风格。
### 公众号名片 ### 公众号名片
请参考 https://mp.weixin.qq.com/s/1wYd15Irmv9BPabgp5XMCA 请参考 https://mp.weixin.qq.com/s/1wYd15Irmv9BPabgp5XMCA
@@ -341,7 +341,7 @@ NoteToMP插件支持该语法。
![[文件名称#^段落标记]] ![[文件名称#^段落标记]]
``` ```
在NoteToMP插件中有两种展示文件嵌入内容的样式一种是引用也就是Obsidian默认的方式一种是正文相当于模板的方式。与模板不同的是采用嵌入方式内容会跟随被嵌入文件的内容更改。 在Note2Any插件中有两种展示文件嵌入内容的样式一种是引用也就是Obsidian默认的方式一种是正文相当于模板的方式。与模板不同的是采用嵌入方式内容会跟随被嵌入文件的内容更改。
## 批量发布Batch Publish ## 批量发布Batch Publish

View File

@@ -1,4 +1,4 @@
.note-to-mp { .note2any {
padding: 0 1em; padding: 0 1em;
color: #595959; color: #595959;
font-size: 16px; font-size: 16px;

View File

@@ -22,7 +22,7 @@ else
fi fi
# 2. 目标目录 # 2. 目标目录
PLUGIN_DIR=~/myweb/.obsidian/plugins/note-to-mp PLUGIN_DIR=~/myweb/.obsidian/plugins/note2any
FILES=("main.js" "styles.css" "manifest.json") FILES=("main.js" "styles.css" "manifest.json")
# 3. 遍历文件,逐一备份并覆盖 # 3. 遍历文件,逐一备份并覆盖

View File

@@ -12,6 +12,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
### Changed ### Changed
- README新增图片方向处理说明、Gallery 参数使用示例。 - README新增图片方向处理说明、Gallery 参数使用示例。
- 预览布局:微信与小红书界面改为统一的网格化布局(`wechat-board` / `xhs-board`),组件按区域栅格排列,便于维护与对齐。
### Notes ### Notes
- 若遇到其他 EXIF 方向值(除 1/3/6/8当前保持原样可后续扩展。 - 若遇到其他 EXIF 方向值(除 1/3/6/8当前保持原样可后续扩展。
@@ -35,4 +36,3 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- 发布新版本:更新 `package.json` / `manifest.json` 的版本号;追加 `versions.json`;将当前 Unreleased 条目移动为新的版本号,并添加日期;再创建新的 Unreleased 模板。 - 发布新版本:更新 `package.json` / `manifest.json` 的版本号;追加 `versions.json`;将当前 Unreleased 条目移动为新的版本号,并添加日期;再创建新的 Unreleased 模板。
- 提交信息建议:`feat: ...`, `fix: ...`, `docs: ...`, `refactor: ...` 等 Conventional Commits 风格。 - 提交信息建议:`feat: ...`, `fix: ...`, `docs: ...`, `refactor: ...` 等 Conventional Commits 风格。

View File

@@ -105,7 +105,9 @@ views:
``` ```
10. 默认选择“原创”“允许留言”。 10. 默认选择
- “允许留言” ✅
- “原创”
11. gallery短代码增加是否使用dir中的所有图片的开关。mppickall=1选取dir中的所有图片mppickall=0按“选取图片数”配置选取图片数量。 11. gallery短代码增加是否使用dir中的所有图片的开关。mppickall=1选取dir中的所有图片mppickall=0按“选取图片数”配置选取图片数量。
{{<gallery dir="/img/guanzhan/1" figcaption="毕业展" mppickall=1/>}}{{<load-photoswipe>}} {{<gallery dir="/img/guanzhan/1" figcaption="毕业展" mppickall=1/>}}{{<load-photoswipe>}}
@@ -136,3 +138,7 @@ Orientation : 6 -- 图片左旋90度需右选90才正常。
为了规避这个问题图片不做旋转处理直接转为png上传公众号。解决。因为PNG不带orientation信息。 为了规避这个问题图片不做旋转处理直接转为png上传公众号。解决。因为PNG不带orientation信息。
- 封面图片没有正确旋转。
公众号上传仍然有图片旋转问题同样需要取png图片避免旋转问题

View File

@@ -1,10 +1,11 @@
{ {
"id": "note-to-mp", "id": "note2any",
"name": "NoteToAny", "name": "Note2Any",
"version": "1.3.4", "version": "1.3.4",
"minAppVersion": "1.4.5", "minAppVersion": "1.4.5",
"description": "xiaohongshu/mp publisher ", "description": "xiaohongshu/mp publisher ",
"author": "Gavin chan", "author": "Gavin chan",
"authorUrl": "https://biboer.cn", "authorUrl": "https://biboer.cn",
"isDesktopOnly": false "isDesktopOnly": false,
"fundingUrl": "https://biboer.cn/gitea/gavin/note2any"
} }

View File

@@ -1,8 +1,16 @@
{ {
"name": "note-to-mp", "name": "note2any",
"version": "1.3.0", "version": "1.3.0",
"description": "This is a plugin for Obsidian (https://obsidian.md)", "description": "This is a plugin for Obsidian (https://obsidian.md)",
"main": "main.js", "main": "main.js",
"repository": {
"type": "git",
"url": "https://biboer.cn/gitea/gavin/note2any.git"
},
"homepage": "https://biboer.cn/gitea/gavin/note2any",
"bugs": {
"url": "https://biboer.cn/gitea/gavin/note2any/issues"
},
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "npm run build:bundle --", "build": "npm run build:bundle --",

View File

@@ -64,3 +64,8 @@
## v1.3.10 ## v1.3.10
重构xhs和wechat布局统一使用grid便于维护。 重构xhs和wechat布局统一使用grid便于维护。
## v1.3.11
修改wechat封面旋转问题。对全局配置进行了重构分页显示更加清晰。
封面图片先转位png解决旋转问题。

View File

@@ -200,7 +200,7 @@ export class ArticleRender implements MDRendererCallback {
errorContent(error: any) { errorContent(error: any) {
return '<h1>渲染失败!</h1><br/>' 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://biboer.cn/gitea/gavin/note2any/issues">https://biboer.cn/gitea/gavin/note2any/issues</a>&nbsp;&nbsp;反馈<br/><br/>'
+ '如果方便请提供引发错误的完整Markdown内容。<br/><br/>' + '如果方便请提供引发错误的完整Markdown内容。<br/><br/>'
+ '<br/>Obsidian版本' + apiVersion + '<br/>Obsidian版本' + apiVersion
+ '<br/>错误信息:<br/>' + '<br/>错误信息:<br/>'
@@ -341,11 +341,11 @@ export class ArticleRender implements MDRendererCallback {
try { try {
const globalAny = window as any; const globalAny = window as any;
const now = Date.now(); const now = Date.now();
if (!globalAny.__note2mp_lastPathLog || if (!globalAny.__note2any_lastPathLog ||
globalAny.__note2mp_lastPathLog.path !== file.path || globalAny.__note2any_lastPathLog.path !== file.path ||
now - globalAny.__note2mp_lastPathLog.time > 3000) { now - globalAny.__note2any_lastPathLog.time > 3000) {
console.log('[note2mp] active file path:', file.path); console.log('[note2any] active file path:', file.path);
globalAny.__note2mp_lastPathLog = { path: file.path, time: now }; globalAny.__note2any_lastPathLog = { path: file.path, time: now };
} }
} catch {} } catch {}
const metadata = this.app.metadataCache.getFileCache(file); const metadata = this.app.metadataCache.getFileCache(file);
@@ -381,7 +381,9 @@ export class ArticleRender implements MDRendererCallback {
res.cover = undefined; // 忽略 frontmatter res.cover = undefined; // 忽略 frontmatter
} }
res.thumb_media_id = this.getFrontmatterValue(frontmatter, keys.thumb_media_id); res.thumb_media_id = this.getFrontmatterValue(frontmatter, keys.thumb_media_id);
res.need_open_comment = frontmatter[keys.need_open_comment] ? 1 : undefined; if (frontmatter[keys.need_open_comment] !== undefined) {
res.need_open_comment = frontmatter[keys.need_open_comment] ? 1 : 0;
}
res.only_fans_can_comment = frontmatter[keys.only_fans_can_comment] ? 1 : undefined; res.only_fans_can_comment = frontmatter[keys.only_fans_can_comment] ? 1 : undefined;
res.appid = this.getFrontmatterValue(frontmatter, keys.appid); res.appid = this.getFrontmatterValue(frontmatter, keys.appid);
if (res.appid && !res.appid.startsWith('wx')) { if (res.appid && !res.appid.startsWith('wx')) {
@@ -473,11 +475,14 @@ export class ArticleRender implements MDRendererCallback {
if (base) res.cover = `![[${base}]]`; if (base) res.cover = `![[${base}]]`;
} }
if (res.cover) { 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 {}
} }
} }
} }
} }
if (res.need_open_comment === undefined) {
res.need_open_comment = this.settings.needOpenComment ? 1 : 0;
}
return res; return res;
} }
@@ -717,7 +722,7 @@ export class ArticleRender implements MDRendererCallback {
article_type: 'newspic', article_type: 'newspic',
title: metadata.title || this.title, title: metadata.title || this.title,
content: content, content: content,
need_open_commnet: metadata.need_open_comment || 0, need_open_commnet: metadata.need_open_comment ?? 0,
only_fans_can_comment: metadata.only_fans_can_comment || 0, only_fans_can_comment: metadata.only_fans_can_comment || 0,
image_info: { image_info: {
image_list: imageList, image_list: imageList,

View File

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

View File

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

View File

@@ -8,6 +8,7 @@ import { wxUploadImage } from "./wechat/weixin-api";
import { NMPSettings } from "./settings"; import { NMPSettings } from "./settings";
import { IsWasmReady, LoadWasm } from "./wasm/wasm"; import { IsWasmReady, LoadWasm } from "./wasm/wasm";
import AssetsManager from "./assets"; import AssetsManager from "./assets";
import { convertJpegIfNeeded } from "./exif-orientation";
declare function GoWebpToJPG(data: Uint8Array): Uint8Array; // wasm 返回 Uint8Array declare function GoWebpToJPG(data: Uint8Array): Uint8Array; // wasm 返回 Uint8Array
declare function GoWebpToPNG(data: Uint8Array): Uint8Array; declare function GoWebpToPNG(data: Uint8Array): Uint8Array;
@@ -38,6 +39,18 @@ export async function UploadImageToWx(data: Blob, filename: string, token: strin
await PrepareImageLib(); await PrepareImageLib();
} }
try {
// 公众号端仍然存在基于 EXIF 的旋转问题:
// 统一将待上传的 JPEG 转为 PNG 并忽略 Orientation避免出现倒置/倾斜。
const converted = await convertJpegIfNeeded(data, filename);
if (converted.changed) {
data = converted.blob;
filename = converted.filename;
}
} catch (error) {
console.warn('[UploadImageToWx] convert to PNG failed, fallback to original', error);
}
const watermark = NMPSettings.getInstance().watermark; const watermark = NMPSettings.getInstance().watermark;
if (watermark != null && watermark != '') { if (watermark != null && watermark != '') {
const watermarkData = await AssetsManager.getInstance().readFileBinary(watermark); const watermarkData = await AssetsManager.getInstance().readFileBinary(watermark);

View File

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

View File

@@ -43,7 +43,7 @@ interface PlatformInfo {
* 支持的平台列表 * 支持的平台列表
*/ */
const SUPPORTED_PLATFORMS: PlatformInfo[] = [ const SUPPORTED_PLATFORMS: PlatformInfo[] = [
{ value: 'wechat', label: '微信公众号', icon: '📱' }, { value: 'wechat', label: '公众号', icon: '📱' },
{ value: 'xiaohongshu', label: '小红书', icon: '📔' } { value: 'xiaohongshu', label: '小红书', icon: '📔' }
]; ];

View File

@@ -4,19 +4,19 @@
*/ */
import { App, TextAreaComponent, PluginSettingTab, Setting, Notice, sanitizeHTMLToDom } from 'obsidian'; 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 { wxGetToken, wxEncrypt } from './wechat/weixin-api';
import { cleanMathCache } from './markdown/math'; import { cleanMathCache } from './markdown/math';
import { NMPSettings } from './settings'; import { NMPSettings } from './settings';
import { DocModal } from './doc-modal'; import { DocModal } from './doc-modal';
export class NoteToMpSettingTab extends PluginSettingTab { export class Note2AnySettingTab extends PluginSettingTab {
plugin: NoteToMpPlugin; plugin: Note2AnyPlugin;
wxInfo: string; wxInfo: string;
wxTextArea: TextAreaComponent|null; wxTextArea: TextAreaComponent|null;
settings: NMPSettings; settings: NMPSettings;
constructor(app: App, plugin: NoteToMpPlugin) { constructor(app: App, plugin: Note2AnyPlugin) {
super(app, plugin); super(app, plugin);
this.plugin = plugin; this.plugin = plugin;
this.settings = NMPSettings.getInstance(); this.settings = NMPSettings.getInstance();
@@ -160,17 +160,47 @@ export class NoteToMpSettingTab extends PluginSettingTab {
this.wxInfo = this.parseWXInfo(); this.wxInfo = this.parseWXInfo();
const helpEl = containerEl.createEl('div', { cls: 'setting-help-section' }); const tabs = [
helpEl.createEl('h2', {text: '帮助文档', cls: 'setting-help-title'}); { id: 'style', label: '样式', render: (panel: HTMLElement) => this.renderStyleTab(panel) },
helpEl.createEl('a', {text: 'https://sunboshi.tech/doc', attr: {href: 'https://sunboshi.tech/doc'}}); { id: 'shortcode', label: '短代码', render: (panel: HTMLElement) => this.renderShortcodeTab(panel) },
{ id: 'theme', label: '主题', render: (panel: HTMLElement) => this.renderThemeTab(panel) },
{ id: 'image', label: '图片', render: (panel: HTMLElement) => this.renderImageTab(panel) },
{ id: 'user', label: '用户信息', render: (panel: HTMLElement) => this.renderUserTab(panel) },
];
containerEl.createEl('h2', {text: '插件设置'}); const tabBar = containerEl.createDiv({ cls: 'nmp-settings-tabs' });
const panelsWrapper = containerEl.createDiv({ cls: 'nmp-settings-panels' });
new Setting(containerEl) const panelMap = new Map<string, HTMLElement>();
const buttonMap = new Map<string, HTMLButtonElement>();
const activate = (id: string) => {
buttonMap.forEach((btn, key) => btn.toggleClass('is-active', key === id));
panelMap.forEach((panel, key) => panel.toggleClass('is-active', key === id));
};
tabs.forEach((tab) => {
const button = tabBar.createEl('button', { text: tab.label, cls: 'nmp-settings-tab-button' });
button.onclick = () => activate(tab.id);
buttonMap.set(tab.id, button);
const panel = panelsWrapper.createDiv({ cls: 'nmp-settings-panel', attr: { 'data-tab': tab.id } });
panelMap.set(tab.id, panel);
tab.render(panel);
});
if (tabs.length > 0) {
activate(tabs[0].id);
}
}
private renderStyleTab(panel: HTMLElement): void {
new Setting(panel)
.setName('默认样式') .setName('默认样式')
.addDropdown(dropdown => { .addDropdown(dropdown => {
const styles = this.plugin.assetsManager.themes; const styles = this.plugin.assetsManager.themes;
for (let s of styles) { for (const s of styles) {
dropdown.addOption(s.className, s.name); dropdown.addOption(s.className, s.name);
} }
dropdown.setValue(this.settings.defaultStyle); dropdown.setValue(this.settings.defaultStyle);
@@ -180,11 +210,11 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('代码高亮') .setName('代码高亮')
.addDropdown(dropdown => { .addDropdown(dropdown => {
const styles = this.plugin.assetsManager.highlights; const styles = this.plugin.assetsManager.highlights;
for (let s of styles) { for (const s of styles) {
dropdown.addOption(s.name, s.name); dropdown.addOption(s.name, s.name);
} }
dropdown.setValue(this.settings.defaultHighlight); dropdown.setValue(this.settings.defaultHighlight);
@@ -194,18 +224,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('在工具栏展示样式选择')
.setDesc('建议在移动端关闭,可以增大文章预览区域')
.addToggle(toggle => {
toggle.setValue(this.settings.showStyleUI);
toggle.onChange(async (value) => {
this.settings.showStyleUI = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('链接展示样式') .setName('链接展示样式')
.addDropdown(dropdown => { .addDropdown(dropdown => {
dropdown.addOption('inline', '内嵌'); dropdown.addOption('inline', '内嵌');
@@ -217,7 +236,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('文件嵌入展示样式') .setName('文件嵌入展示样式')
.addDropdown(dropdown => { .addDropdown(dropdown => {
dropdown.addOption('quote', '引用'); dropdown.addOption('quote', '引用');
@@ -229,7 +248,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('数学公式语法') .setName('数学公式语法')
.addDropdown(dropdown => { .addDropdown(dropdown => {
dropdown.addOption('latex', 'latex'); dropdown.addOption('latex', 'latex');
@@ -242,7 +261,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('显示代码行号') .setName('显示代码行号')
.addToggle(toggle => { .addToggle(toggle => {
toggle.setValue(this.settings.lineNumber); toggle.setValue(this.settings.lineNumber);
@@ -250,9 +269,32 @@ export class NoteToMpSettingTab extends PluginSettingTab {
this.settings.lineNumber = value; this.settings.lineNumber = value;
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
}) });
new Setting(containerEl) new Setting(panel)
.setName('启用空行渲染')
.addToggle(toggle => {
toggle.setValue(this.settings.enableEmptyLine);
toggle.onChange(async (value) => {
this.settings.enableEmptyLine = value;
await this.plugin.saveSettings();
});
});
new Setting(panel)
.setName('默认开启评论')
.setDesc('发布到公众号时默认开启评论,可在 frontmatter 使用 need_open_comment 关闭')
.addToggle(toggle => {
toggle.setValue(this.settings.needOpenComment);
toggle.onChange(async (value) => {
this.settings.needOpenComment = value;
await this.plugin.saveSettings();
});
});
}
private renderShortcodeTab(panel: HTMLElement): void {
new Setting(panel)
.setName('Gallery 根路径') .setName('Gallery 根路径')
.setDesc('用于 {{<gallery dir="..."/>}} 短代码解析;需指向本地图片根目录') .setDesc('用于 {{<gallery dir="..."/>}} 短代码解析;需指向本地图片根目录')
.addText(text => { .addText(text => {
@@ -265,7 +307,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
text.inputEl.setAttr('style', 'width: 360px;'); text.inputEl.setAttr('style', 'width: 360px;');
}); });
new Setting(containerEl) new Setting(panel)
.setName('Gallery 选取图片数') .setName('Gallery 选取图片数')
.setDesc('每个 gallery 短代码最多替换为前 N 张图片') .setDesc('每个 gallery 短代码最多替换为前 N 张图片')
.addText(text => { .addText(text => {
@@ -281,7 +323,18 @@ export class NoteToMpSettingTab extends PluginSettingTab {
text.inputEl.setAttr('style', 'width: 120px;'); text.inputEl.setAttr('style', 'width: 120px;');
}); });
new Setting(containerEl) new Setting(panel)
.setName('忽略 frontmatter 封面')
.setDesc('开启后不使用 frontmatter 中 cover/image 字段封面将按正文首图→gallery→默认封面回退')
.addToggle(toggle => {
toggle.setValue(this.settings.ignoreFrontmatterImage);
toggle.onChange(async (value) => {
this.settings.ignoreFrontmatterImage = value;
await this.plugin.saveSettings();
});
});
new Setting(panel)
.setName('默认封面图片') .setName('默认封面图片')
.setDesc('当文章无任何图片/短代码时使用;可填 wikilink 文件名或 http(s) URL') .setDesc('当文章无任何图片/短代码时使用;可填 wikilink 文件名或 http(s) URL')
.addText(text => { .addText(text => {
@@ -293,108 +346,10 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
text.inputEl.setAttr('style', 'width: 360px;'); text.inputEl.setAttr('style', 'width: 360px;');
}); });
new Setting(containerEl)
.setName('忽略 frontmatter 封面')
.setDesc('开启后不使用 frontmatter 中 cover/image 字段封面将按正文首图→gallery→默认封面回退')
.addToggle(toggle => {
toggle.setValue(this.settings.ignoreFrontmatterImage);
toggle.onChange(async (value) => {
this.settings.ignoreFrontmatterImage = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('启用空行渲染')
.addToggle(toggle => {
toggle.setValue(this.settings.enableEmptyLine);
toggle.onChange(async (value) => {
this.settings.enableEmptyLine = value;
await this.plugin.saveSettings();
});
})
// 切图配置区块
containerEl.createEl('h2', {text: '切图配置'});
new Setting(containerEl)
.setName('切图保存路径')
.setDesc('切图文件的保存目录,默认:/Users/gavin/note2mp/images/xhs')
.addText(text => {
text.setPlaceholder('例如 /Users/xxx/images/xhs')
.setValue(this.settings.sliceImageSavePath || '')
.onChange(async (value) => {
this.settings.sliceImageSavePath = value.trim();
await this.plugin.saveSettings();
});
text.inputEl.setAttr('style', 'width: 360px;');
});
new Setting(containerEl)
.setName('切图宽度')
.setDesc('长图及切图的宽度像素默认1080')
.addText(text => {
text.setPlaceholder('数字 >=100')
.setValue(String(this.settings.sliceImageWidth || 1080))
.onChange(async (value) => {
const n = parseInt(value, 10);
if (Number.isFinite(n) && n >= 100) {
this.settings.sliceImageWidth = n;
await this.plugin.saveSettings();
} }
});
text.inputEl.setAttr('style', 'width: 120px;');
});
new Setting(containerEl) private renderThemeTab(panel: HTMLElement): void {
.setName('切图横竖比例') new Setting(panel)
.setDesc('格式:宽:高,例如 3:4 表示竖图16:9 表示横图')
.addText(text => {
text.setPlaceholder('例如 3:4')
.setValue(this.settings.sliceImageAspectRatio || '3:4')
.onChange(async (value) => {
this.settings.sliceImageAspectRatio = value.trim();
await this.plugin.saveSettings();
});
text.inputEl.setAttr('style', 'width: 120px;');
});
new Setting(containerEl)
.setName('渲染图片标题')
.addToggle(toggle => {
toggle.setValue(this.settings.useFigcaption);
toggle.onChange(async (value) => {
this.settings.useFigcaption = value;
await this.plugin.saveSettings();
});
})
new Setting(containerEl)
.setName('Excalidraw 渲染为 PNG 图片')
.setDesc('开启:将 Excalidraw 笔记/嵌入转换为位图 PNG 插入;关闭:保持原始 SVG/矢量渲染(更清晰,体积更小)。')
.addToggle(toggle => {
toggle.setValue(this.settings.excalidrawToPNG);
toggle.onChange(async (value) => {
this.settings.excalidrawToPNG = value;
await this.plugin.saveSettings();
});
})
new Setting(containerEl)
.setName('水印图片')
.addText(text => {
text.setPlaceholder('请输入图片名称')
.setValue(this.settings.watermark)
.onChange(async (value) => {
this.settings.watermark = value.trim();
await this.plugin.saveSettings();
})
.inputEl.setAttr('style', 'width: 320px;')
})
new Setting(containerEl)
.setName('获取更多主题') .setName('获取更多主题')
.addButton(button => { .addButton(button => {
button.setButtonText('下载'); button.setButtonText('下载');
@@ -411,7 +366,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl) new Setting(panel)
.setName('清空主题') .setName('清空主题')
.addButton(button => { .addButton(button => {
button.setButtonText('清空'); button.setButtonText('清空');
@@ -420,8 +375,9 @@ export class NoteToMpSettingTab extends PluginSettingTab {
this.settings.resetStyelAndHighlight(); this.settings.resetStyelAndHighlight();
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
}) });
new Setting(containerEl)
new Setting(panel)
.setName('全局CSS属性') .setName('全局CSS属性')
.setDesc('只能填写CSS属性不能写选择器') .setDesc('只能填写CSS属性不能写选择器')
.addTextArea(text => { .addTextArea(text => {
@@ -433,9 +389,10 @@ export class NoteToMpSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}) })
.inputEl.setAttr('style', 'width: 520px; height: 60px;'); .inputEl.setAttr('style', 'width: 520px; height: 60px;');
}) });
const customCSSDoc = '使用指南:<a href="https://sunboshi.tech/customcss">https://sunboshi.tech/customcss</a>'; const customCSSDoc = '使用指南:<a href="https://sunboshi.tech/customcss">https://sunboshi.tech/customcss</a>';
new Setting(containerEl) new Setting(panel)
.setName('自定义CSS笔记') .setName('自定义CSS笔记')
.setDesc(sanitizeHTMLToDom(customCSSDoc)) .setDesc(sanitizeHTMLToDom(customCSSDoc))
.addText(text => { .addText(text => {
@@ -446,11 +403,11 @@ export class NoteToMpSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
await this.plugin.assetsManager.loadCustomCSS(); await this.plugin.assetsManager.loadCustomCSS();
}) })
.inputEl.setAttr('style', 'width: 320px;') .inputEl.setAttr('style', 'width: 320px;');
}); });
const expertDoc = '使用指南:<a href="https://sunboshi.tech/expert">https://sunboshi.tech/expert</a>'; const expertDoc = '使用指南:<a href="https://sunboshi.tech/expert">https://sunboshi.tech/expert</a>';
new Setting(containerEl) new Setting(panel)
.setName('专家设置笔记') .setName('专家设置笔记')
.setDesc(sanitizeHTMLToDom(expertDoc)) .setDesc(sanitizeHTMLToDom(expertDoc))
.addText(text => { .addText(text => {
@@ -461,18 +418,99 @@ export class NoteToMpSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
await this.plugin.assetsManager.loadExpertSettings(); await this.plugin.assetsManager.loadExpertSettings();
}) })
.inputEl.setAttr('style', 'width: 320px;') .inputEl.setAttr('style', 'width: 320px;');
});
}
private renderImageTab(panel: HTMLElement): void {
new Setting(panel)
.setName('切图保存路径')
.setDesc('切图文件的保存目录,默认:/Users/gavin/note2any/images/xhs')
.addText(text => {
text.setPlaceholder('例如 /Users/xxx/images/xhs')
.setValue(this.settings.sliceImageSavePath || '')
.onChange(async (value) => {
this.settings.sliceImageSavePath = value.trim();
await this.plugin.saveSettings();
});
text.inputEl.setAttr('style', 'width: 360px;');
}); });
new Setting(panel)
.setName('切图宽度')
.setDesc('长图及切图的宽度像素默认1080')
.addText(text => {
text.setPlaceholder('数字 >=100')
.setValue(String(this.settings.sliceImageWidth || 1080))
.onChange(async (value) => {
const n = parseInt(value, 10);
if (Number.isFinite(n) && n >= 100) {
this.settings.sliceImageWidth = n;
await this.plugin.saveSettings();
}
});
text.inputEl.setAttr('style', 'width: 120px;');
});
new Setting(panel)
.setName('切图横竖比例')
.setDesc('格式:宽:高,例如 3:4 表示竖图16:9 表示横图')
.addText(text => {
text.setPlaceholder('例如 3:4')
.setValue(this.settings.sliceImageAspectRatio || '3:4')
.onChange(async (value) => {
this.settings.sliceImageAspectRatio = value.trim();
await this.plugin.saveSettings();
});
text.inputEl.setAttr('style', 'width: 120px;');
});
new Setting(panel)
.setName('渲染图片标题')
.addToggle(toggle => {
toggle.setValue(this.settings.useFigcaption);
toggle.onChange(async (value) => {
this.settings.useFigcaption = value;
await this.plugin.saveSettings();
});
});
new Setting(panel)
.setName('Excalidraw 渲染为 PNG 图片')
.setDesc('开启:将 Excalidraw 笔记/嵌入转换为位图 PNG 插入;关闭:保持原始 SVG/矢量渲染。')
.addToggle(toggle => {
toggle.setValue(this.settings.excalidrawToPNG);
toggle.onChange(async (value) => {
this.settings.excalidrawToPNG = value;
await this.plugin.saveSettings();
});
});
new Setting(panel)
.setName('水印图片')
.setDesc('可填写文件名或 URL')
.addText(text => {
text.setPlaceholder('例如 watermark.png')
.setValue(this.settings.watermark)
.onChange(async (value) => {
this.settings.watermark = value.trim();
await this.plugin.saveSettings();
})
.inputEl.setAttr('style', 'width: 320px;');
});
}
private renderUserTab(panel: HTMLElement): void {
let descHtml = '详情说明:<a href="https://sunboshi.tech/subscribe">https://sunboshi.tech/subscribe</a>'; let descHtml = '详情说明:<a href="https://sunboshi.tech/subscribe">https://sunboshi.tech/subscribe</a>';
if (this.settings.isVip) { if (this.settings.isVip) {
descHtml = '<span style="color:rgb(245, 70, 85);font-weight: bold;">👑永久会员</span><br/>' + descHtml; descHtml = '<span style="color:rgb(245, 70, 85);font-weight: bold;">👑永久会员</span><br/>' + descHtml;
} }
else if (this.settings.expireat) { else if (this.settings.expireat) {
const timestr = this.settings.expireat.toLocaleString(); const timestr = this.settings.expireat.toLocaleString();
descHtml = `有效期至:${timestr} <br/>${descHtml}` descHtml = `有效期至:${timestr} <br/>${descHtml}`;
} }
new Setting(containerEl)
new Setting(panel)
.setName('注册码AuthKey') .setName('注册码AuthKey')
.setDesc(sanitizeHTMLToDom(descHtml)) .setDesc(sanitizeHTMLToDom(descHtml))
.addText(text => { .addText(text => {
@@ -483,14 +521,14 @@ export class NoteToMpSettingTab extends PluginSettingTab {
this.settings.getExpiredDate(); this.settings.getExpiredDate();
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}) })
.inputEl.setAttr('style', 'width: 320px;') .inputEl.setAttr('style', 'width: 320px;');
}).descEl.setAttr('style', '-webkit-user-select: text; user-select: text;') }).descEl.setAttr('style', '-webkit-user-select: text; user-select: text;');
let isClear = this.settings.wxInfo.length > 0; let isClear = this.settings.wxInfo.length > 0;
let isRealClear = false; let isRealClear = false;
const buttonText = isClear ? '清空公众号信息' : '保存公众号信息'; const buttonText = isClear ? '清空公众号信息' : '保存公众号信息';
new Setting(containerEl)
new Setting(panel)
.setName('公众号信息') .setName('公众号信息')
.addTextArea(text => { .addTextArea(text => {
this.wxTextArea = text; this.wxTextArea = text;
@@ -501,8 +539,7 @@ export class NoteToMpSettingTab extends PluginSettingTab {
}) })
.inputEl.setAttr('style', 'width: 520px; height: 120px;'); .inputEl.setAttr('style', 'width: 520px; height: 120px;');
}) })
.addButton(button => {
new Setting(containerEl).addButton(button => {
button.setButtonText(buttonText); button.setButtonText(buttonText);
button.onClick(async () => { button.onClick(async () => {
if (isClear) { if (isClear) {
@@ -535,7 +572,11 @@ export class NoteToMpSettingTab extends PluginSettingTab {
button.setButtonText('测试中...'); button.setButtonText('测试中...');
await this.testWXInfo(); await this.testWXInfo();
button.setButtonText('测试公众号'); button.setButtonText('测试公众号');
}) });
}) });
//
const helpEl = panel.createEl('div', { cls: 'setting-help-section' });
helpEl.createEl('h2', { text: '帮助文档', cls: 'setting-help-title' });
helpEl.createEl('a', { text: 'https://sunboshi.tech/doc', attr: { href: 'https://sunboshi.tech/doc' } });
} }
} }

View File

@@ -32,6 +32,7 @@ export class NMPSettings {
excalidrawToPNG: boolean; excalidrawToPNG: boolean;
isLoaded: boolean = false; isLoaded: boolean = false;
enableEmptyLine: boolean = false; enableEmptyLine: boolean = false;
needOpenComment: boolean = true;
enableMarkdownImageToWikilink: boolean = true; // 自动将 ![alt](path/file.ext) 转为 ![[file.ext]] enableMarkdownImageToWikilink: boolean = true; // 自动将 ![alt](path/file.ext) 转为 ![[file.ext]]
// gallery 相关配置:根目录前缀 & 选取图片数量 // gallery 相关配置:根目录前缀 & 选取图片数量
galleryPrePath: string; galleryPrePath: string;
@@ -81,6 +82,7 @@ export class NMPSettings {
this.excalidrawToPNG = false; this.excalidrawToPNG = false;
this.expertSettingsNote = ''; this.expertSettingsNote = '';
this.enableEmptyLine = false; this.enableEmptyLine = false;
this.needOpenComment = true;
this.enableMarkdownImageToWikilink = true; this.enableMarkdownImageToWikilink = true;
// 默认值:用户原先硬编码路径 & 前 2 张 // 默认值:用户原先硬编码路径 & 前 2 张
this.galleryPrePath = '/Users/gavin/myweb/static'; this.galleryPrePath = '/Users/gavin/myweb/static';
@@ -98,7 +100,7 @@ export class NMPSettings {
} }
]; ];
// 切图配置默认值 // 切图配置默认值
this.sliceImageSavePath = '/Users/gavin/note2mp/images/xhs'; this.sliceImageSavePath = '/Users/gavin/note2any/images/xhs';
this.sliceImageWidth = 1080; this.sliceImageWidth = 1080;
this.sliceImageAspectRatio = '3:4'; this.sliceImageAspectRatio = '3:4';
this.xhsPreviewWidth = 540; this.xhsPreviewWidth = 540;
@@ -131,6 +133,7 @@ export class NMPSettings {
expertSettingsNote, expertSettingsNote,
ignoreEmptyLine, ignoreEmptyLine,
enableMarkdownImageToWikilink, enableMarkdownImageToWikilink,
needOpenComment,
galleryPrePath, galleryPrePath,
galleryNumPic, galleryNumPic,
defaultCoverPic, defaultCoverPic,
@@ -160,6 +163,7 @@ export class NMPSettings {
if (excalidrawToPNG !== undefined) settings.excalidrawToPNG = excalidrawToPNG; if (excalidrawToPNG !== undefined) settings.excalidrawToPNG = excalidrawToPNG;
if (expertSettingsNote) settings.expertSettingsNote = expertSettingsNote; if (expertSettingsNote) settings.expertSettingsNote = expertSettingsNote;
if (ignoreEmptyLine !== undefined) settings.enableEmptyLine = !!ignoreEmptyLine; if (ignoreEmptyLine !== undefined) settings.enableEmptyLine = !!ignoreEmptyLine;
if (needOpenComment !== undefined) settings.needOpenComment = !!needOpenComment;
if (enableMarkdownImageToWikilink !== undefined) settings.enableMarkdownImageToWikilink = !!enableMarkdownImageToWikilink; if (enableMarkdownImageToWikilink !== undefined) settings.enableMarkdownImageToWikilink = !!enableMarkdownImageToWikilink;
if (galleryPrePath) settings.galleryPrePath = galleryPrePath; if (galleryPrePath) settings.galleryPrePath = galleryPrePath;
if (galleryNumPic !== undefined && Number.isFinite(galleryNumPic)) settings.galleryNumPic = Math.max(1, parseInt(galleryNumPic)); if (galleryNumPic !== undefined && Number.isFinite(galleryNumPic)) settings.galleryNumPic = Math.max(1, parseInt(galleryNumPic));
@@ -197,6 +201,7 @@ export class NMPSettings {
'excalidrawToPNG': settings.excalidrawToPNG, 'excalidrawToPNG': settings.excalidrawToPNG,
'expertSettingsNote': settings.expertSettingsNote, 'expertSettingsNote': settings.expertSettingsNote,
'ignoreEmptyLine': settings.enableEmptyLine, 'ignoreEmptyLine': settings.enableEmptyLine,
'needOpenComment': settings.needOpenComment,
'enableMarkdownImageToWikilink': settings.enableMarkdownImageToWikilink, 'enableMarkdownImageToWikilink': settings.enableMarkdownImageToWikilink,
'galleryPrePath': settings.galleryPrePath, 'galleryPrePath': settings.galleryPrePath,
'galleryNumPic': settings.galleryNumPic, 'galleryNumPic': settings.galleryNumPic,

View File

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

View File

@@ -183,7 +183,7 @@ export class XiaohongshuPreview {
this.articleHTML = articleHTML; this.articleHTML = articleHTML;
this.currentFile = file; this.currentFile = file;
new Notice('正在分页...'); //new Notice('正在分页...');
// 创建临时容器用于分页 // 创建临时容器用于分页
const tempContainer = document.createElement('div'); const tempContainer = document.createElement('div');
@@ -200,7 +200,7 @@ export class XiaohongshuPreview {
// 在分页前先应用主题与高亮,确保测量使用正确样式 // 在分页前先应用主题与高亮,确保测量使用正确样式
this.applyThemeCSS(); this.applyThemeCSS();
this.pages = await paginateArticle(tempContainer, this.settings); this.pages = await paginateArticle(tempContainer, this.settings);
new Notice(`分页完成:共 ${this.pages.length}`); //new Notice(`分页完成:共 ${this.pages.length} 页`);
this.currentPageIndex = 0; this.currentPageIndex = 0;
// 初次渲染时应用当前主题 // 初次渲染时应用当前主题
@@ -460,7 +460,7 @@ export class XiaohongshuPreview {
private async persistSettings(): Promise<void> { private async persistSettings(): Promise<void> {
try { try {
const plugin = (this.app as any)?.plugins?.getPlugin?.('note-to-mp'); const plugin = (this.app as any)?.plugins?.getPlugin?.('note2any');
if (plugin?.saveSettings) { if (plugin?.saveSettings) {
await plugin.saveSettings(); await plugin.saveSettings();
} }
@@ -520,7 +520,7 @@ export class XiaohongshuPreview {
if (!this.articleHTML) return; if (!this.articleHTML) return;
const totalBefore = this.pages.length || 1; const totalBefore = this.pages.length || 1;
const posRatio = (this.currentPageIndex + 0.5) / totalBefore; // 以当前页中心作为相对位置 const posRatio = (this.currentPageIndex + 0.5) / totalBefore; // 以当前页中心作为相对位置
new Notice('重新分页中...'); //new Notice('重新分页中...');
const tempContainer = document.createElement('div'); const tempContainer = document.createElement('div');
tempContainer.innerHTML = this.articleHTML; tempContainer.innerHTML = this.articleHTML;
@@ -539,7 +539,7 @@ export class XiaohongshuPreview {
this.currentPageIndex = 0; this.currentPageIndex = 0;
} }
this.renderCurrentPage(); this.renderCurrentPage();
new Notice(`重新分页完成:共 ${this.pages.length}`); //new Notice(`重新分页完成:共 ${this.pages.length} 页`);
} catch (e) { } catch (e) {
console.error('重新分页失败', e); console.error('重新分页失败', e);
new Notice('重新分页失败'); new Notice('重新分页失败');

View File

@@ -183,6 +183,53 @@ label:hover { color: var(--c-primary); }
box-shadow: 0 2px 6px rgba(30, 136, 229, 0.2); box-shadow: 0 2px 6px rgba(30, 136, 229, 0.2);
} }
.nmp-settings-tabs {
display: flex;
gap: 8px;
margin-top: 16px;
border-bottom: 1px solid var(--c-border);
padding-bottom: 8px;
flex-wrap: wrap;
}
.nmp-settings-tab-button {
border: none;
border-radius: 6px;
padding: 6px 14px;
font-size: 13px;
font-weight: 500;
color: var(--c-text-muted);
background: transparent;
cursor: pointer;
transition: all 0.2s ease;
}
.nmp-settings-tab-button:hover {
color: var(--c-primary);
background: rgba(30, 136, 229, 0.08);
}
.nmp-settings-tab-button.is-active {
color: var(--c-primary);
background: white;
box-shadow: var(--shadow-sm);
}
.nmp-settings-panels {
margin-top: 16px;
}
.nmp-settings-panel {
display: none;
gap: 12px;
flex-direction: column;
}
.nmp-settings-panel.is-active {
display: flex;
flex-direction: column;
}
/* focus 规则见与 .upload-input:focus 的组合声明 */ /* focus 规则见与 .upload-input:focus 的组合声明 */
.msg-view { .msg-view {
@@ -351,10 +398,10 @@ label:hover { color: var(--c-primary); }
"cover-select cover-select cover-select cover-select cover-input cover-input" "cover-select cover-select cover-select cover-select cover-input cover-input"
"style-label style-select highlight-label highlight-select highlight-select highlight-select" "style-label style-select highlight-label highlight-select highlight-select highlight-select"
"content content content content content content"; "content content content content content content";
gap: 5px; gap: 12px;
background: var(--grad-toolbar); background: var(--grad-toolbar);
border-radius: 12px; border-radius: 12px;
padding: 5px; padding: 16px;
box-shadow: var(--shadow-sm); box-shadow: var(--shadow-sm);
min-height: 0; min-height: 0;
} }

View File

@@ -8,7 +8,7 @@
- 标题取frontmatter的title属性。 - 标题取frontmatter的title属性。
- 图片保存路径可配置,默认为/Users/gavin/note2mp/images/xhs。 - 图片保存路径可配置,默认为/Users/gavin/note2any/images/xhs。
- 图片名取frontmatter的slug属性如: slug: mmm文章长图命名为mmm.png如切为3张图片则切图图片名按顺序依次为mmm_1.png,mmm_2.png,mmm_3.png - 图片名取frontmatter的slug属性如: slug: mmm文章长图命名为mmm.png如切为3张图片则切图图片名按顺序依次为mmm_1.png,mmm_2.png,mmm_3.png
@@ -56,6 +56,28 @@
- 点击"全部页切图"把所有html页面转为png图片图片保存路径和命名按此前设置。 - 点击"全部页切图"把所有html页面转为png图片图片保存路径和命名按此前设置。
3. 目前xhs模式发布功能未实现因为没有登录。
整合xhs登陆和发布功能。![登录项目](https://biboer.cn/gitea/gavin/xhslogin/src/branch/main/README.md)
- 在“用户配置”tab中增加“小红书用户名”配置项默认13357108011。 **后续可能需要维护多账号**
- xhslogin项目XHS_PHONE=13357108011 XHS_AUTO_CLOSE=1 npm run publish -- --title "恢复功能测试" --content "验证恢复核心功能后保留优化的代码" --images "/Users/gavin/myweb/static/img/ibook笔记.png" --visibility private --collection 自嗨 --timestamp
其中:
- 参数XHS_PHONE为“小红书用户名”配置项。
- title取markdown文章的title
- content取markdown文章frontmatter中的description信息如果没有description或内容为空取markdown正文前2段段以空行隔离不超过300字[n]段1+段2>n取段1段1+段2+段3>n取段1段2 ……)
- images取小红书切图结果按文章次序。
- visibility在小红书模式下预览页的工具栏中增加"公开"checkbox默认为不选即private。
- collection在小红书模式下预览页的工具栏中增加下拉框选择下拉框内容从登录小红书自动获取。
- timestamp是调试使用默认使用
❓ 重构后无法运行原因是obsidian中playwright环境没有。
❌ 要用xhslogin 的 Playwright 逻辑,就必须把 Playwright 当成外部依赖加载(运行前安装 playwright 和浏览器内核)。 如果一定要彻底摆脱 Playwright只能回到 webview 方案,重新实现一次自动化流程,与其说“利用现成 Chromium”不如说“自己写网页自动化框架”工作量很大。
**改变思路**
xhslogin改造成MCP server部署在远端服务器上。插件中只要实现mcp client就可以了。
这样xhslogin项目没有必要整合到note2any中。
4. 选中内容,右键发布到不同平台。发布时调用渲染,发布到特定的栏目中,比如网站中某个区块的“闪念集”。
## 问题 ## 问题
1. "发布平台"首次选“小红书”时,预览页面没有加载当前文章。 1. "发布平台"首次选“小红书”时,预览页面没有加载当前文章。
@@ -118,12 +140,25 @@ SOLVEobsidian控制台打印信息定位在哪里阻塞AI修复。
10. 新建docs文件夹把除了README和todolist以外的markdown文件放到docs中。 10. 新建docs文件夹把除了README和todolist以外的markdown文件放到docs中。
11. `![img](/img/img.png)` -- 不应该渲染为图片链接
## 经验 ## 经验
1. 在不确定AI是否理解或者需求是否准确的情况下先用codex chat模式提问看回答确定AI理解是否准确。 1. 在不确定AI是否理解或者需求是否准确的情况下先用codex chat模式提问看回答确定AI理解是否准确。
尤其对于较大规模的重构需求,这点很重要 ‼️ 。 尤其对于较大规模的重构需求,这点很重要 ‼️ 。
例如:
这个思路有问题。我提供命令行只是对参数做说明,这些参数实际上是函数参数。
我需要把xhslogin的功能代码无缝的整合进现有项目中而不是通过命令行传参的方式实现。
这么做的同时,保持结构和模块清晰。
请再提供思路,我来审核下。
2. 复杂页面codex生成的css可能无比复杂不便于维护修改。 2. 复杂页面codex生成的css可能无比复杂不便于维护修改。
自己写布局demo原型让codex参考布局修改(原来元素美化的css可保留)。 自己写布局demo原型让codex参考布局修改(原来元素美化的css可保留)。
demo原型可以手绘后拍照让chatgpt生成在此基础上自己修改。 demo原型可以手绘后拍照让chatgpt生成在此基础上自己修改。
## 思路
1. 网上图片模版让AI快速生成css themes主题。快速套用。‼
**样式和功能必须结构样式必须可以0基础快速选择让用户可以选择足够多样式(AI生成)。**

4
x
View File

@@ -105,8 +105,8 @@
box-sizing: border-box; box-sizing: border-box;
} }
/* 若内部 section.note-to-mp 主题没有撑开,确保文本可见基色 */ /* 若内部 section.note2any 主题没有撑开,确保文本可见基色 */
.wechat-article-wrapper .note-to-mp { .wechat-article-wrapper .note2any {
background: transparent; background: transparent;
} }