Skip to content

Commit 9602abc

Browse files
committed
Update default book-page header template
New default ships author / full-title / series / category:: #Books / summary / tags, with #Books as a constant category tag so every synced book is grouped together. Note: the backfill in bootstrap only fires on blank fields, so existing users with a previously-stored default will need to run "Sync KOReader Highlights: reset templates to defaults" (or edit the field manually) to pick up the new default.
1 parent 1afcef5 commit 9602abc

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,31 @@ heading:
8383
- Title collisions get disambiguated as `<title> — <authors>` or
8484
`<title> (n)`.
8585

86-
- **Page-level properties** (set via Logseq's structured
86+
- **Page-level properties** (defined by the customisable
87+
Book-page header template and written via Logseq's structured
8788
`createPage(name, properties, opts)` API so Logseq escapes them
88-
natively):
89-
- `title::` — full original title, including any colons.
89+
natively). The default template produces:
9090
- `author::` — each KOReader author rendered as its own
9191
`[[wikilink]]`. Names containing `Last, First` commas are split
9292
only on KOReader's `\n` separator, never on commas inside a name.
93+
- `full-title::` — full original title, including any colons.
9394
- `series::` — single `[[wikilink]]` from `doc_props.series`
9495
when present.
96+
- `category:: #Books` — a constant tag so every synced book is
97+
grouped under the `Books` page.
98+
- `summary::` — the full `doc_props.description`, with HTML tags
99+
stripped, named/numeric HTML entities decoded, and Lua escapes
100+
resolved. Not truncated.
95101
- `tags::` — comma-joined `[[wikilinks]]`, sourced from
96102
`doc_props.keywords` (or `doc_props.subject` as fallback).
97103
Split on `;`, `,`, and newlines so KOReader's multi-line
98104
keyword form (`Philosophy\<newline>Life`) yields two distinct
99105
tags.
100-
- `summary::` — the full `doc_props.description`, with HTML tags
101-
stripped, named/numeric HTML entities decoded, and Lua escapes
102-
resolved. Not truncated.
103106

104107
All values are sanitised before being written: newlines collapsed,
105108
duplicate `::` neutralised, whitespace trimmed. Empty values cause
106-
their property line to drop out entirely.
109+
their property line to drop out entirely. Edit the Book-page
110+
header template setting to add, remove, or rename any of these.
107111

108112
- **Highlights / notes / bookmarks** (KOReader stores all three in
109113
the `annotations` table; the renderer disambiguates by which
@@ -214,12 +218,12 @@ In Logseq → Plugins → Sync KOReader Highlights → ⚙:
214218
remembered yet), to avoid disrupting the user.
215219
- **Book page header template** *(Mustache)* — defines the
216220
page-level properties on each book page. Pre-filled with a
217-
default that produces the standard `title`/`author`/`series`/
218-
`tags`/`summary` properties. Add, remove, or rename properties
219-
by editing the template; the rendered output is parsed
220-
line-by-line as `key:: value` pairs and written through
221-
Logseq's structured `createPage` properties API for safe
222-
escaping (same path whether you keep the default or
221+
default that produces `author`, `full-title`, `series`,
222+
`category:: #Books`, `summary`, and `tags`. Add, remove, or
223+
rename properties by editing the template; the rendered output
224+
is parsed line-by-line as `key:: value` pairs and written
225+
through Logseq's structured `createPage` properties API for
226+
safe escaping (same path whether you keep the default or
223227
customise). Lines that don't match `key:: value` are dropped,
224228
so empty Mustache sections (`{{#series}}…{{/series}}`) collapse
225229
cleanly. Variables: `{{title}}`, `{{authors}}`,

src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const SETTINGS_SCHEMA: SettingSchemaDesc[] = [
4040
title: 'Book page header template (Mustache)',
4141
description:
4242
'Mustache template defining the page-level properties on each book page. ' +
43+
'Default produces author / full-title / series / category (#Books) / summary / tags. ' +
4344
'Render output is parsed line-by-line as `key:: value` pairs and written via Logseq\'s structured `createPage` properties API for safe escaping (the same path is used whether you keep the default or customise). ' +
4445
'Lines that don\'t match `key:: value` are dropped — empty Mustache sections (e.g. `{{#series}}…{{/series}}`) collapse cleanly. ' +
4546
'Variables: {{title}}, {{authors}} (comma-joined plain text), {{authorsLinked}} (each as [[wikilink]]), ' +

src/render.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import { KoreaderHighlight, KoreaderSidecar } from './sidecar'
1717
* structured page-level properties are skipped to avoid duplication.
1818
* The user then owns the property syntax.
1919
*/
20-
export const DEFAULT_BOOK_HEADER_TEMPLATE = `title:: {{title}}
21-
{{#authorsLinked}}author:: {{authorsLinked}}{{/authorsLinked}}
20+
export const DEFAULT_BOOK_HEADER_TEMPLATE = `{{#authorsLinked}}author:: {{authorsLinked}}{{/authorsLinked}}
21+
full-title:: {{title}}
2222
{{#seriesLinked}}series:: {{seriesLinked}}{{/seriesLinked}}
23-
{{#tagsLinked}}tags:: {{tagsLinked}}{{/tagsLinked}}
24-
{{#summary}}summary:: {{summary}}{{/summary}}`
23+
category:: #Books
24+
{{#summary}}summary:: {{summary}}{{/summary}}
25+
{{#tagsLinked}}tags:: {{tagsLinked}}{{/tagsLinked}}`
2526

2627
export const DEFAULT_HIGHLIGHTS_HEADING_TEMPLATE = `Highlights synced from [[KOReader]]`
2728

0 commit comments

Comments
 (0)