所以,我的目标是添加内嵌标签,然后能够在单独的页面上调用这些标签。我最终能够结合 Jekyll 和 Python 来做到这一点。我将所有原始帖子保存在“topublish”文件夹中。在每篇文章的开头,我都包含一个前端标签 defs_used: so:
---
layout: post
title: xxxx
date: 2017-07-11 17:50:00
categories: ['Reading Notes']
defs_used:
---
当我记笔记并遇到定义时,我会这样做
In this chapter of Marx, we learn about commodity fetishism, which can be described below.
<def>commodity fetishism: the perception of the social relationships involved
in production as economic relationships among the money and commodities
exchanged in market trade</def>
完成后,我运行 python 脚本来搜索定义并将它们写入 defs_used: 类别。该脚本将更新的帖子保存在“_posts”文件夹中:
import os
import re
files = [f for f in os.listdir("_topublish") if f.endswith('.markdown')]
for posts in files:
print(posts)
with open("_topublish/"+posts,"r") as post1:
post = post1.read()
defs = re.findall("<def>(.*?)</def>",post)
replacement = "defs_used:\n"
for definition in defs:
replacement = replacement+"\n "+definition
newpost = post.replace("defs_used:\n",replacement)
newname = posts.replace('.markdown','-defs.markdown')
print newpost
with open("_posts/"+newname,'w') as w:
w.write(newpost)
这会收集所有定义并将它们放入标签中,如下所示:
---
layout: post
title: xxxx
date: 2017-07-11 17:50:00
categories: ['Reading Notes']
defs_used:
commodity fetishism: the perception of the social relationships involved in production as economic relationships among the money and commodities exchanged in market trade
---
在一个新页面上,我创建了一个定义表,如下所示:
<table>
<tr>
<th>Link</th>
<th>Title</th>
<th>Date</th>
<th>Term</th>
<th>Definition</th>
</tr>
{% for post in site.posts %}
{% for def in post.defs_used %}
<tr>
<th>Access here[{{post.url}}]</th>
<th>{{ post.title}}</th>
<th>{{ post.date}}</th>
<th>{{ def[0] }}</th>
<th>{{ def[1] }}</th>
</tr>
{% endfor %}
{% endfor %}
我仍然遇到的唯一问题是返回页面的链接不起作用,因为降价在 HTML 样式表中的功能不太正确。除此之外,这效果很好。我有一个来自所有阅读笔记的所有定义的运行列表,并且只需要在发布之前运行“python defs.py”!所以有我自己的问题的答案...