zhaohongxuan / obsidian-weread-plugin

Obsidian Weread Plugin is a plugin to sync Weread(微信读书) hightlights and annotations into your Obsidian Vault.
MIT License
1.25k stars 65 forks source link

模板分享 #56

Closed seyeeL closed 2 years ago

seyeeL commented 2 years ago
---
isbn: {{metaData.isbn}}
category: {{metaData.category}}
---
## Meta
> [!abstract] {{metaData.title}}
> - ![ {{metaData.title}}|200]({{metaData.cover}})
> - 书名: {{metaData.title}}
> - 作者: {{metaData.author}}
> - 简介: {{metaData.intro}}
> - 出版时间 {{metaData.publishTime}}
> - ISBN: {{metaData.isbn}}
> - 分类: {{metaData.category}}
> - 出版社: {{metaData.publisher}}

{% if bookReview.bookReviews %}{% for bookReview in bookReview.bookReviews %}
{% if loop.first %}{% if bookReview.mdContent.length %}#本书评论{% endif %}{% endif %}
{% if bookReview.mdContent.length %}- {{bookReview.mdContent}} ^{{bookReview.reviewId}}
[[{{bookReview.createTime.slice(0, 10)}}]]{{bookReview.createTime.slice(10, 16)}}
{% endif %}{% endfor%}{% endif %}

{% for chapter in bookReview.chapterReviews %}{% if chapter.reviews or chapter.chapterReview %}{% if  chapter.chapterReviews %}{% for chapterReview in chapter.chapterReviews %}- {{chapterReview.content}} ^{{chapterReview.reviewId}}
[[{{chapterReview.createTime.slice(0, 10)}}]]{{chapterReview.createTime.slice(10, 16)}} 
{% endfor%}
{%endif %}{% if chapter.reviews %}{%for review in chapter.reviews %}
{% endfor %} {%endif %} {% endif %} {% endfor %}

{% for chapter in chapterHighlights %}{% if loop.first %}## highlights{% endif %}
### {{chapter.chapterTitle}}
{% for highlight in chapter.highlights %}{% if highlight.reviewContent %}
- {{ highlight.markText |trim }} — created on [[{{highlight.createTime.slice(0, 10)}}]]{{highlight.createTime.slice(10, 16)}}  ^{{highlight.chapterUid}}-{{highlight.range}}
{% set regExp = r/\#/g %}{% if regExp.test(highlight.reviewContent) === false %}#读书笔记{% endif %} {{highlight.reviewContent}}
{% else %}
- {{ highlight.markText |trim }}  — created on [[{{highlight.createTime.slice(0, 10)}}]]{{highlight.createTime.slice(10, 16)}}  ^{{highlight.chapterUid}}-{{highlight.range}}
{% endif %} {% endfor %}{% endfor %}

一些说明:

  1. 在微信读书上我会把整本书的评论和阅读记录写到序或者第一章,这样在微信读书里的某本书看所有笔记的时候,就能第一时间看到我对这本书的评价(如果写了的话),所以同理同步的配置也是这样写的,也就是meta信息下的第一段。
  2. 在微信读书上写过的评论,基本上也是划了线的,我不介意有两条记录。这样同步后的就是按章节同步高亮和想法,没有把高亮和想法分成两部分,同时,同步的想法前面会加上#读书笔记 的标签,但有微信上有些想法我也是会手动写标签的,比如#书单之类的,那么原本想法里已经有标签了,前面就不加#读书笔记了。 {% set regExp = r/\#/g %}{% if regExp.test(highlight.reviewContent) === false %}#读书笔记{% endif %} 这是那个判断条件,条件是想法里不包含#的才加上#读书笔记,可以根据自己的需求修改正则条件。
  3. 因为不喜欢同步一些空的文字,比如我某本书没有写本书评论,就不想空有个#本书评论的标签下面没内容,{% if loop.first %}{% if bookReview.mdContent.length %}#本书评论{% endif %}{% endif %}这个就是做判断用的,loop.first 是个变量,代表循环里的第一次
  4. 我对日期进行了处理,将日期和时间拆成两部分,日期加上双链,这样就可以在日记的反链里看到我当天的读书记录。created on [[{{highlight.createTime.slice(0, 10)}}]]{{highlight.createTime.slice(10, 16)}}是这一段,不喜欢的可以去掉 image

一张效果图:

image

这个模版改了好多版,现在这版还挺满意的,也满足了一定的强迫症,欢迎交流更多有意思的技巧

imaskcat commented 9 months ago

日期格式能否自定义呀? 比如:[[2024-01-01-星期一]]

另外,Nunjucks模板能不能支持自定义过滤器? 比如我想添加一个自定义日期格式的过滤器,不知道在哪里添加。