Skip to content

Commit

Permalink
feat(books): add to the book note the actual percentage read
Browse files Browse the repository at this point in the history
Close #41
  • Loading branch information
Edo78 committed Jan 31, 2022
1 parent 1ef0654 commit a3482b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/koreader-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export class KOReaderMetadata {
bookmarks,
doc_props: { title },
doc_props: { authors },
percent_finished,
} = jsonMetadata;
if (Object.keys(highlight).length && Object.keys(bookmarks).length) {
metadatas[`${title} - ${authors}`] = {
title,
authors,
// highlight,
bookmarks,
percent_finished,
};
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class KOReader extends Plugin {
checkCallback: (checking: boolean) => {
if (this.settings.enbleResetImportedNotes) {
if (!checking) {
this.resetSyncList();
this.settings.importedNotes = {};
this.settings.enbleResetImportedNotes = false;
this.saveSettings();
}
Expand All @@ -184,11 +184,6 @@ export default class KOReader extends Plugin {
await this.saveData(this.settings);
}

private async resetSyncList() {
this.settings.importedNotes = {};
await this.saveSettings();
}

private getObjectProperty(object: { [x: string]: any }, path: string) {
if (path === undefined || path === null) {
return object;
Expand Down Expand Up @@ -314,18 +309,24 @@ Page: <%= it.page %>
path: string;
managedBookTitle: string;
title: string;
percent_finished: number;
}) {
const { path, title, managedBookTitle } = dataview;
const { path, title, managedBookTitle, percent_finished } = dataview;
const frontMatter = {
cssclass: 'koreader-sync-dataview',
[KOREADERKEY]: {
type: 'koreader-sync-dataview',
managed_title: managedBookTitle,
data: {
title,
percent_finished,
},
},
};

const defaultTemplate = `# Title: <%= it.title %>
<progress value="${percent_finished}" max="100"> </progress>
\`\`\`dataviewjs
const title = dv.current()['koreader-sync'].managed_title
dv.pages().where(n => {
Expand Down Expand Up @@ -390,6 +391,7 @@ return n['koreader-sync'] && n['koreader-sync'].type == 'koreader-sync-note' &&
path,
managedBookTitle,
title: data[book].title,
percent_finished: data[book].percent_finished * 100,
});
}

Expand Down
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Book {
authors: string;
bookmarks: Bookmarks;
highlight: any;
percent_finished: number;
}

export interface Books {
Expand Down

0 comments on commit a3482b9

Please sign in to comment.