【已解决】修改 微信读书/weread 插件模板 显示所有章节标题

采用这个大佬的模板的weread模板(我做了一点格式上的修改)
【模板特点】在没有高亮或是笔记的情况下的章节,是不显示该章节的标题的
【我的需求】但是我是希望显示所有章节标题的,无论是否有高亮划批注
【尝试】我试了改了几次,但是都不行:rofl:;同时尝试打开weread插件中的设置“展示空白章节的标题”,也是不行(可能是这个模板把默认设置的功能关闭了?)

请问有大佬知道应该怎么修改呀?感谢感谢~

以下是模板的代码:

---
isbn: {{metaData.isbn}}
category: {{metaData.category}}
lastReadDate: {{metaData.lastReadDate}}
出版社: {{metaData.publisher}}
出版时间: {{metaData.publishTime}}
原书链接: {{metaData.pcUrl}}
---

# 书名:[{{metaData.title}}]({{metaData.pcUrl}})

> [!abstract]- 《{{metaData.title}}》
> - ![{{metaData.title}}|200]({{metaData.cover}})
> - 简介:{{metaData.intro | replace('\r\n', '') | replace('\n', '')}}
> - 划线数量:{{metaData.noteCount}} 
> - 笔记数量:{{metaData.reviewCount}}

# 本书评论
{% if bookReview.bookReviews %}{% for bookReview in bookReview.bookReviews %}
## 书评 No.{{loop.index}}

{{bookReview.mdContent}}{% endfor%}{% endif %}

# 笔记

{%- set allNotes = [] -%}
{%- for highlightItem in chapterHighlights -%}
{%- for highlight in highlightItem.highlights -%}
{%- set allNotes = allNotes.concat({'type': 'highlight', 'data': highlight, 'range': highlight.range.split("-")[0] | int}) -%}{%- endfor -%}{%- endfor -%}
{%- for reviewitem in bookReview.chapterReviews -%}
{%- for review in reviewitem.reviews -%}
{%- set allNotes = allNotes.concat({'type': 'review', 'data': review,'range': review.range.split("-")[0] | int}) -%}{%- endfor -%}
{%- for chapterReview in reviewitem.chapterReviews -%}
{%- set allNotes = allNotes.concat({'type': 'chapterReview', 'data': chapterReview}) -%}{%- endfor -%}{%- endfor -%}
{%- set allNotes = allNotes|sort(attribute='data.chapterUid')|groupby('data.chapterUid') -%}
{% for chapterUid, notes in allNotes %}
## {{notes[0].data.chapterTitle}}
{%- for note in notes|sort(attribute='range') %}
{% if note.type == 'highlight' and not note.data.reviewContent %}
###### 🟢高亮

{% for line in note.data.markText.split('\n') %}
> {{line | trim}}{% endfor %}{% elif note.type == 'review' %}
###### 📝笔记

{% for line in note.data.abstract.split('\n') %}> {{line | trim}}{% endfor %}
{% for line in note.data.content.split('\n') %}
- 📌{{line | trim}}{% endfor %}{% elif note.type == 'chapterReview' %}
###### 🗣章节评论

{% for line in note.data.content.split('\n') %} - {{line | trim}}{% endfor %}
{%- endif %}
{%- endfor %}
{% endfor %}

这种情况可以考虑先弄个有全章节名的模板, 再比对你希望用的这模板, 看看差在哪

同一个页面我找了个 ref 他这个能显示全章节名 (即使该章无任何笔记划线)

左侧他的, 右侧你改的 (格式加了缩进不重要)

估计就差在 {% for chapter1 in chapterHighlights %}

  • 他: 先把章节名展示出来了, 不管有没有笔记划线
  • 你: 收集 allNotes 时, 因为大部分章节的 highlightItem.highlights 根本没东西, 于是 allNotes 里啥也收集不到

没完整实验, 大概率问题就出在这

非常感谢!
问题已解决
这是最终版的

---
isbn: {{metaData.isbn}}
category: {{metaData.category}}
lastReadDate: {{metaData.lastReadDate}}
出版社: {{metaData.publisher}}
出版时间: {{metaData.publishTime}}
原书链接: {{metaData.pcUrl}}
---

# 书名:[{{metaData.title}}]({{metaData.pcUrl}})

> [!abstract]- 《{{metaData.title}}》
> - ![{{metaData.title}}|200]({{metaData.cover}})
> - 简介:{{metaData.intro | replace('\r\n', '') | replace('\n', '')}}
> - 划线数量:{{metaData.noteCount}} 
> - 笔记数量:{{metaData.reviewCount}}

# 本书评论
{% if bookReview.bookReviews %}{% for bookReview in bookReview.bookReviews %}
## 书评 No.{{loop.index}}

{{bookReview.mdContent}}{% endfor%}{% endif %}

# 笔记

{%- set allNotes = [] -%}

{%- for highlightItem in chapterHighlights -%}
{%- if  highlightItem.highlights.length>0 -%} 
{%- for highlight in highlightItem.highlights -%} 
{%- set allNotes = allNotes.concat({'type': 'highlight', 'data': highlight, 'range': highlight.range.split("-")[0] | int}) -%}
{%- endfor -%}
{%- else -%} 
{%- set allNotes = allNotes.concat({'type': '0', 'data': highlightItem, 'range': '0' }) -%}
{%- endif -%}
{%- endfor -%}

{%- for reviewitem in bookReview.chapterReviews -%}
{%- for review in reviewitem.reviews -%}
{%- set allNotes = allNotes.concat({'type': 'review', 'data': review,'range': review.range.split("-")[0] | int}) -%}{%- endfor -%}
{%- for chapterReview in reviewitem.chapterReviews -%}
{%- set allNotes = allNotes.concat({'type': 'chapterReview', 'data': chapterReview}) -%}{%- endfor -%}{%- endfor -%}
{%- set allNotes = allNotes|sort(attribute='data.chapterUid')|groupby('data.chapterUid') -%}
{% for chapterUid, notes in allNotes %}
## {{notes[0].data.chapterTitle}}
{%- for note in notes|sort(attribute='range') %}
{% if note.type == 'highlight' and not note.data.reviewContent %}
###### 🟢高亮
{% for line in note.data.markText.split('\n') %}
> {{line | trim}}{% endfor %}{% elif note.type == 'review' %}
###### 📝笔记

{% for line in note.data.abstract.split('\n') %}
> {{line | trim}}{% endfor %}
{% for line in note.data.content.split('\n') %}
- 📌{{line | trim}}{% endfor %}{% elif note.type == 'chapterReview' %}
###### 🗣章节评论

{% for line in note.data.content.split('\n') %} - {{line | trim}}{% endfor %}
{%- endif %}
{%- endfor %}
{% endfor %}
1 个赞