Files
note2any/src/expert-settings.ts
2025-10-08 09:18:20 +08:00

64 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 文件expert-settings.ts
* 作用:高级设置弹窗 / 功能开关逻辑。
*/
import { parseYaml } from "obsidian";
export interface ExpertSettings {
render?: {
h1?: string | number | object;
h2?: string | number | object;
h3?: string | number | object;
code?: number;
callout?: object | undefined;
},
frontmatter: {
title: string;
author: string;
digest: string;
content_source_url: string;
cover: string;
thumb_media_id: string
need_open_comment: string;
only_fans_can_comment: string;
appid: string;
theme: string;
highlight: string;
crop: string;
}
}
export const defaultExpertSettings: ExpertSettings = {
render: undefined,
frontmatter: {
title: '标题',
author: '作者',
digest: '摘要',
content_source_url: '原文地址',
cover: '封面',
thumb_media_id: '封面素材ID',
need_open_comment: '打开评论',
only_fans_can_comment: '仅粉丝可评论',
appid: '公众号',
theme: '样式',
highlight: '代码高亮',
crop: '封面裁剪',
}
};
export function expertSettingsFromString(content: string): ExpertSettings {
content = content.replace(/```yaml/gi, '').replace(/```/g, '');
let parsed = parseYaml(content) as Partial<ExpertSettings>;
if (!parsed || typeof parsed !== 'object') {
parsed = {};
}
return {
render: parsed.render,
frontmatter: {
...defaultExpertSettings.frontmatter,
...(parsed.frontmatter || {})
}
};
}