diff --git a/manifest.json b/manifest.json
index 4c80b31..5717ac3 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"id": "obsidian-weread-plugin",
"name": "Weread",
- "version": "0.10.0",
+ "version": "0.11.0",
"minAppVersion": "0.12.0",
"description": "This is obsidian plugin for Tencent weread.",
"author": "hankzhao",
diff --git a/package.json b/package.json
index c50a1ff..6a118ec 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "obsidian-weread-plugin",
- "version": "0.10.0",
+ "version": "0.11.0",
"description": "This is a community plugin for tencent weread (https://r.qq.com)",
"main": "main.ts",
"scripts": {
diff --git a/src/assets/templateInstructions.html b/src/assets/templateInstructions.html
index 51450ba..f05879d 100644
--- a/src/assets/templateInstructions.html
+++ b/src/assets/templateInstructions.html
@@ -15,7 +15,7 @@
可用变量
{{isbn}} - ISBN
{{category}} - 分类
{{publisher}} - 出版社
- {{finish}} - 是否读完(还未支持)
+ {{readInfo}} - 阅读信息, 点击查看详情
划线变量(chapterHighlights)
diff --git a/src/parser/parseResponse.ts b/src/parser/parseResponse.ts
index 638ad72..c8bec0b 100644
--- a/src/parser/parseResponse.ts
+++ b/src/parser/parseResponse.ts
@@ -67,6 +67,7 @@ export const parseHighlights = (
const chapterInfo = highlightData.chapters
.filter((chapter) => chapter.chapterUid === highlight.chapterUid)
.first();
+ const intentMarkText = addIndentToParagraphs(highlight.markText)
return {
bookmarkId: highlight.bookmarkId?.replace(/_/gi, '-'),
created: highlight.createTime,
@@ -78,12 +79,29 @@ export const parseHighlights = (
style: highlight.style,
colorStyle: highlight.colorStyle,
chapterTitle: chapterInfo?.title || '未知章节',
- markText: highlight.markText,
- reviewContent: reviewContent
+ markText: intentMarkText,
+ reviewContent: addIndentToParagraphs(reviewContent)
};
});
};
+
+const addIndentToParagraphs = (content: string): string =>{
+ if(content === undefined || content == ""){
+ return content;
+ }
+ // 将字符串按换行符分割成段落数组
+ const paragraphs = content.split('\n');
+
+ // 遍历段落数组,从第二个段落开始前面加上两个空格
+ for (let i = 1; i < paragraphs.length; i++) {
+ paragraphs[i] = ' ' + paragraphs[i];
+ }
+
+ // 将段落数组重新组合成一个字符串
+ return paragraphs.join('\n');
+ }
+
export const parseArticleHighlightReview = (
chapters: Chapter[],
highlights: Highlight[],
diff --git a/src/settingTab.ts b/src/settingTab.ts
index 647d8a7..4c06f01 100644
--- a/src/settingTab.ts
+++ b/src/settingTab.ts
@@ -47,6 +47,7 @@ export class WereadSettingsTab extends PluginSettingTab {
this.subFolderType();
this.convertTagToggle();
this.saveArticleToggle();
+ this.saveReadingInfoToggle();
this.showEmptyChapterTitleToggle();
this.dailyNotes();
const dailyNotesToggle = get(settingsStore).dailyNotesToggle;
@@ -128,6 +129,17 @@ export class WereadSettingsTab extends PluginSettingTab {
});
});
}
+ private saveReadingInfoToggle(): void {
+ new Setting(this.containerEl)
+ .setName('保存阅读元数据?')
+ .setDesc('开启此选项会阅读数据写入frontmatter')
+ .addToggle((toggle) => {
+ return toggle.setValue(get(settingsStore).saveReadingInfoToggle).onChange((value) => {
+ settingsStore.actions.setSaveReadingInfoToggle(value);
+ this.display();
+ });
+ });
+ }
private convertTagToggle(): void {
new Setting(this.containerEl)
.setName('将标签转换为双链?')
diff --git a/src/settings.ts b/src/settings.ts
index 6852994..da1528d 100644
--- a/src/settings.ts
+++ b/src/settings.ts
@@ -23,6 +23,7 @@ interface WereadPluginSettings {
showEmptyChapterTitleToggle: boolean;
convertTags: boolean;
saveArticleToggle: boolean;
+ saveReadingInfoToggle: boolean;
}
const DEFAULT_SETTINGS: WereadPluginSettings = {
@@ -44,7 +45,9 @@ const DEFAULT_SETTINGS: WereadPluginSettings = {
notesBlacklist: '',
showEmptyChapterTitleToggle: false,
convertTags: false,
- saveArticleToggle: true
+ saveArticleToggle: true,
+ saveReadingInfoToggle: true,
+
};
const createSettingsStore = () => {
@@ -218,6 +221,12 @@ const createSettingsStore = () => {
});
};
+ const setSaveReadingInfoToggle = (saveReadingInfoToggle: boolean) => {
+ store.update((state) => {
+ state.saveReadingInfoToggle = saveReadingInfoToggle;
+ return state;
+ });
+ };
return {
subscribe: store.subscribe,
initialise,
@@ -237,7 +246,8 @@ const createSettingsStore = () => {
setNoteBlacklist,
setEmptyChapterTitleToggle,
setConvertTags,
- setSaveArticleToggle
+ setSaveArticleToggle,
+ setSaveReadingInfoToggle,
}
};
};
diff --git a/src/utils/frontmatter.ts b/src/utils/frontmatter.ts
index 56d4714..8c71b2e 100644
--- a/src/utils/frontmatter.ts
+++ b/src/utils/frontmatter.ts
@@ -1,14 +1,16 @@
import { Notice, parseYaml, stringifyYaml, TFile } from 'obsidian';
import type { Notebook } from '../models';
import { formatTimeDuration, formatTimestampToDate } from './dateUtil';
+import { settingsStore } from '../settings';
+import { get } from 'svelte/store';
type FrontMatterContent = {
doc_type: string;
bookId: string;
- author: string;
- cover: string;
noteCount: number;
reviewCount: number;
+ author?: string;
+ cover?: string;
readingStatus?: string;
progress?: string;
readingTime?: string;
@@ -34,24 +36,31 @@ export const buildFrontMatter = (
const frontMatter: FrontMatterContent = {
doc_type: frontMatterDocType,
bookId: noteBook.metaData.bookId,
- author: noteBook.metaData.author,
- cover: noteBook.metaData.cover,
reviewCount: noteBook.metaData.reviewCount,
noteCount: noteBook.metaData.noteCount
};
- const readInfo = noteBook.metaData.readInfo;
- if (readInfo) {
- frontMatter.readingStatus = ReadingStatus[readInfo.markedStatus];
- frontMatter.progress =
- readInfo.readingProgress === undefined ? '-1' : readInfo.readingProgress + '%';
- frontMatter.totalReadDay = readInfo.totalReadDay;
- frontMatter.readingTime = formatTimeDuration(readInfo.readingTime);
- frontMatter.readingDate = formatTimestampToDate(readInfo.readingBookDate);
- if (readInfo.finishedDate) {
- frontMatter.finishedDate = formatTimestampToDate(readInfo.finishedDate);
+ const saveReadingInfoToggle = get(settingsStore).saveReadingInfoToggle;
+
+ if (saveReadingInfoToggle) {
+ frontMatter.author = noteBook.metaData.author,
+ frontMatter.cover = noteBook.metaData.cover
+
+ const readInfo = noteBook.metaData.readInfo;
+ if (readInfo) {
+ frontMatter.readingStatus = ReadingStatus[readInfo.markedStatus];
+ frontMatter.progress =
+ readInfo.readingProgress === undefined ? '-1' : readInfo.readingProgress + '%';
+ frontMatter.totalReadDay = readInfo.totalReadDay;
+ frontMatter.readingTime = formatTimeDuration(readInfo.readingTime);
+ frontMatter.readingDate = formatTimestampToDate(readInfo.readingBookDate);
+ if (readInfo.finishedDate) {
+ frontMatter.finishedDate = formatTimestampToDate(readInfo.finishedDate);
+ }
+
}
+
}
let existFrontMatter = Object();
if (existFile) {