update at 2025-10-08 09:18:20
This commit is contained in:
151
src/settings.ts
151
src/settings.ts
@@ -1,28 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2025 Sun Booshi
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
if (ignoreFrontmatterImage !== undefined) {
|
||||
settings.ignoreFrontmatterImage = ignoreFrontmatterImage;
|
||||
}
|
||||
if (Array.isArray(batchPublishPresets)) {
|
||||
settings.batchPublishPresets = batchPublishPresets;
|
||||
}n the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
/**
|
||||
* 文件:settings.ts
|
||||
* 作用:插件全局设置模型(单例)与序列化/反序列化逻辑。
|
||||
* 内容:
|
||||
* - 默认值初始化
|
||||
* - loadSettings: 反序列化存储数据并兼容旧字段
|
||||
* - allSettings: 统一导出用于持久化
|
||||
* - 会员 / 授权信息校验(isAuthKeyVaild)
|
||||
* - 批量发布预设 / 图片处理 / 样式控制等选项
|
||||
*/
|
||||
|
||||
import { wxKeyInfo } from './weixin-api';
|
||||
@@ -63,6 +47,10 @@ export class NMPSettings {
|
||||
folders?: string[];
|
||||
filenameKeywords?: string[];
|
||||
}>;
|
||||
// 切图相关配置
|
||||
sliceImageSavePath: string; // 切图保存路径
|
||||
sliceImageWidth: number; // 切图宽度(像素)
|
||||
sliceImageAspectRatio: string; // 横竖比例,格式 "3:4"
|
||||
|
||||
private static instance: NMPSettings;
|
||||
|
||||
@@ -108,6 +96,10 @@ export class NMPSettings {
|
||||
filenameKeywords: []
|
||||
}
|
||||
];
|
||||
// 切图配置默认值
|
||||
this.sliceImageSavePath = '/Users/gavin/note2mp/images/xhs';
|
||||
this.sliceImageWidth = 1080;
|
||||
this.sliceImageAspectRatio = '3:4';
|
||||
}
|
||||
|
||||
resetStyelAndHighlight() {
|
||||
@@ -116,16 +108,15 @@ export class NMPSettings {
|
||||
}
|
||||
|
||||
public static loadSettings(data: any) {
|
||||
if (!data) {
|
||||
return
|
||||
}
|
||||
if (!data) return;
|
||||
|
||||
const {
|
||||
defaultStyle,
|
||||
defaultHighlight,
|
||||
showStyleUI,
|
||||
linkStyle,
|
||||
embedStyle,
|
||||
showStyleUI,
|
||||
lineNumber,
|
||||
defaultHighlight,
|
||||
authKey,
|
||||
wxInfo,
|
||||
math,
|
||||
@@ -143,75 +134,39 @@ export class NMPSettings {
|
||||
defaultCoverPic,
|
||||
ignoreFrontmatterImage,
|
||||
batchPublishPresets = [],
|
||||
sliceImageSavePath,
|
||||
sliceImageWidth,
|
||||
sliceImageAspectRatio
|
||||
} = data;
|
||||
|
||||
const settings = NMPSettings.getInstance();
|
||||
if (defaultStyle) {
|
||||
settings.defaultStyle = defaultStyle;
|
||||
}
|
||||
if (defaultHighlight) {
|
||||
settings.defaultHighlight = defaultHighlight;
|
||||
}
|
||||
if (showStyleUI !== undefined) {
|
||||
settings.showStyleUI = showStyleUI;
|
||||
}
|
||||
if (linkStyle) {
|
||||
settings.linkStyle = linkStyle;
|
||||
}
|
||||
if (embedStyle) {
|
||||
settings.embedStyle = embedStyle;
|
||||
}
|
||||
if (lineNumber !== undefined) {
|
||||
settings.lineNumber = lineNumber;
|
||||
}
|
||||
if (authKey) {
|
||||
settings.authKey = authKey;
|
||||
}
|
||||
if (wxInfo) {
|
||||
settings.wxInfo = wxInfo;
|
||||
}
|
||||
if (math) {
|
||||
settings.math = math;
|
||||
}
|
||||
if (useCustomCss !== undefined) {
|
||||
settings.useCustomCss = useCustomCss;
|
||||
}
|
||||
if (baseCSS) {
|
||||
settings.baseCSS = baseCSS;
|
||||
}
|
||||
if (watermark) {
|
||||
settings.watermark = watermark;
|
||||
}
|
||||
if (useFigcaption !== undefined) {
|
||||
settings.useFigcaption = useFigcaption;
|
||||
}
|
||||
if (customCSSNote) {
|
||||
settings.customCSSNote = customCSSNote;
|
||||
}
|
||||
if (excalidrawToPNG !== undefined) {
|
||||
settings.excalidrawToPNG = excalidrawToPNG;
|
||||
}
|
||||
if (expertSettingsNote) {
|
||||
settings.expertSettingsNote = expertSettingsNote;
|
||||
}
|
||||
if (ignoreEmptyLine !== undefined) {
|
||||
settings.enableEmptyLine = ignoreEmptyLine;
|
||||
}
|
||||
if (enableMarkdownImageToWikilink !== undefined) {
|
||||
settings.enableMarkdownImageToWikilink = enableMarkdownImageToWikilink;
|
||||
}
|
||||
if (galleryPrePath) {
|
||||
settings.galleryPrePath = galleryPrePath;
|
||||
}
|
||||
if (galleryNumPic !== undefined && Number.isFinite(galleryNumPic)) {
|
||||
settings.galleryNumPic = Math.max(1, parseInt(galleryNumPic));
|
||||
}
|
||||
if (defaultCoverPic !== undefined) {
|
||||
settings.defaultCoverPic = String(defaultCoverPic).trim();
|
||||
}
|
||||
if (ignoreFrontmatterImage !== undefined) {
|
||||
settings.ignoreFrontmatterImage = !!ignoreFrontmatterImage;
|
||||
}
|
||||
if (defaultStyle) settings.defaultStyle = defaultStyle;
|
||||
if (defaultHighlight) settings.defaultHighlight = defaultHighlight;
|
||||
if (showStyleUI !== undefined) settings.showStyleUI = showStyleUI;
|
||||
if (linkStyle) settings.linkStyle = linkStyle;
|
||||
if (embedStyle) settings.embedStyle = embedStyle;
|
||||
if (lineNumber !== undefined) settings.lineNumber = lineNumber;
|
||||
if (authKey) settings.authKey = authKey;
|
||||
if (wxInfo) settings.wxInfo = wxInfo;
|
||||
if (math) settings.math = math;
|
||||
if (useCustomCss !== undefined) settings.useCustomCss = useCustomCss;
|
||||
if (baseCSS) settings.baseCSS = baseCSS;
|
||||
if (watermark) settings.watermark = watermark;
|
||||
if (useFigcaption !== undefined) settings.useFigcaption = useFigcaption;
|
||||
if (customCSSNote) settings.customCSSNote = customCSSNote;
|
||||
if (excalidrawToPNG !== undefined) settings.excalidrawToPNG = excalidrawToPNG;
|
||||
if (expertSettingsNote) settings.expertSettingsNote = expertSettingsNote;
|
||||
if (ignoreEmptyLine !== undefined) settings.enableEmptyLine = !!ignoreEmptyLine;
|
||||
if (enableMarkdownImageToWikilink !== undefined) settings.enableMarkdownImageToWikilink = !!enableMarkdownImageToWikilink;
|
||||
if (galleryPrePath) settings.galleryPrePath = galleryPrePath;
|
||||
if (galleryNumPic !== undefined && Number.isFinite(galleryNumPic)) settings.galleryNumPic = Math.max(1, parseInt(galleryNumPic));
|
||||
if (defaultCoverPic !== undefined) settings.defaultCoverPic = String(defaultCoverPic).trim();
|
||||
if (ignoreFrontmatterImage !== undefined) settings.ignoreFrontmatterImage = !!ignoreFrontmatterImage;
|
||||
if (Array.isArray(batchPublishPresets)) settings.batchPublishPresets = batchPublishPresets;
|
||||
if (sliceImageSavePath) settings.sliceImageSavePath = sliceImageSavePath;
|
||||
if (sliceImageWidth !== undefined && Number.isFinite(sliceImageWidth)) settings.sliceImageWidth = Math.max(100, parseInt(sliceImageWidth));
|
||||
if (sliceImageAspectRatio) settings.sliceImageAspectRatio = sliceImageAspectRatio;
|
||||
|
||||
settings.getExpiredDate();
|
||||
settings.isLoaded = true;
|
||||
}
|
||||
@@ -241,6 +196,10 @@ export class NMPSettings {
|
||||
'galleryNumPic': settings.galleryNumPic,
|
||||
'defaultCoverPic': settings.defaultCoverPic,
|
||||
'ignoreFrontmatterImage': settings.ignoreFrontmatterImage,
|
||||
'batchPublishPresets': settings.batchPublishPresets,
|
||||
'sliceImageSavePath': settings.sliceImageSavePath,
|
||||
'sliceImageWidth': settings.sliceImageWidth,
|
||||
'sliceImageAspectRatio': settings.sliceImageAspectRatio,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user