给Pelican驱动的博客添加上Isso评论系统
Le Thu 13 February 2025
Pelican是静态博客系统,Isso是评论系统。
要让Pelican支持Isso,需要一个支持Isso的Pelican主题。 如果主题不支持,则需要修改主题。
Pelican的默认主题是notmyidea,这个主题没有加入Isso的支持。
pelicanconf.py配置文件中加入:
ISSO_SERVER = "https://isso.example.com"
覆盖article.html模板。
THEME_TEMPLATES_OVERRIDES = ["templates"]
将主题中的article.html模板文件复制到上述配置的目录template中。
修改这个文件,加入下述代码。
{% if ISSO_SERVER and SITEURL and article.status != "draft" %}
<!-- Isso Start -->
<script data-isso="{{ISSO_SERVER}}"
src="{{ISSO_SERVER}}/js/embed.min.js"></script>
<section id="isso-thread"></section>
<!-- Isso End -->
{% endif %}
经此修改后,评论系统的代码被加入到发布版的文章中。草稿、预发布版本中不显示评论系统。
参考了:
这篇文章给出的方案是,修改{テーマフォルダ}/templates/article.html
<!-- Isso Start -->
<script data-isso="//isso.example.com/"
src="//isso.example.com/js/embed.min.js"></script>
<section id="isso-thread"></section>
<!-- Isso End -->
其他需要考虑的问题:
要使用Isso,需要一个Isso服务器。Isso服务器可以自己搭建,也可以使用第三方提供的服务。
可以整体复制主题,也可以只复制特定的模板文件。 本文复制了特定的模板文件。
如何找到默认的主题路径:
ls /path-to-venv/**/site-packages/pelican/themes/not*/templates
上述命令可能会输出多个结果,选择其中一个即可。
ls ../myenv/**/site-packages/pelican/themes/not*/templates
../myenv/lib64/python3.9/site-packages/pelican/themes/notmyidea/templates:
analytics.html article.html author.html base.html category.html disqus_script.html index.html period_archives.html taglist.html translations.html
archives.html article_infos.html authors.html categories.html comments.html github.html page.html tag.html tags.html twitter.html
../myenv/lib/python3.9/site-packages/pelican/themes/notmyidea/templates:
analytics.html article.html author.html base.html category.html disqus_script.html index.html period_archives.html taglist.html translations.html
archives.html article_infos.html authors.html categories.html comments.html github.html page.html tag.html tags.html twitter.html
确保自己在合适的工作目录下。此处在pelicanconf.py所在的目录下。
$ pwd
/workspace/blog.cloudstudio.icu
如果没有template文件夹,则需要创建。 复制相关文件。
mkdir template
cp ../myenv/lib/python3.9/site-packages/pelican/themes/notmyidea/templates/article.html template/article.html._tmp_copy
上述的._tmp_copy是不必要的后缀,在此防止覆盖现有文件。
实际修改中,需要修改template/article.html文件。
注意:不恰当的操作可能会覆盖您的现有文件。执行任何命令前请先检查命令的正确性,并做好备份,避免不必要的损失。
参考了以下资料,特此鸣谢:
- https://docs.getpelican.com/en/latest/faq.html#can-i-override-individual-templates-without-forking-the-whole-theme