You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jekyll中按“出版年份”排序展示CSV文献数据的技术问题

Jekyll 文献CSV工作流问题解决方案

1. 带空格字段的调用与排序

Jekyll Liquid语法中,带空格的CSV字段不能用.点语法访问,必须改用方括号语法:

  • 访问字段:{{ card["Publication year"] }}
  • 倒序排序:在Liquid循环前先处理数据,用带引号的字段名指定排序键
    {% assign sorted_articles = site.data.references | where: "Item type", "Journal Article" | sort: "Publication year" | reverse %}
    

2. 实现年份斜体效果

不要给变量名加下划线,而是在Liquid变量外层包裹Markdown斜体标记:

*{{ card["Publication year"] }}*

3. CSV编码导致首列无法提取

这通常是CSV文件带有UTF-8 BOM(字节顺序标记)导致的,解决步骤:

  • 用VS Code/Notepad++打开_data/references.csv
  • 切换编码为「UTF-8 无BOM」
  • 重新保存文件后上传到GitHub

4. Google Scholar CSV分号分隔符问题

Google Scholar导出的CSV默认用分号分隔,Jekyll默认解析逗号分隔的CSV,需在_config.yml中添加配置:

csv_separator: ";"

配置后即可正常调用card.Authors等字段。

完整的Publications页面代码

在publications.md中直接写入以下代码,无需额外_includes组件:

# Publications

{% assign journal_articles = site.data.references | where: "Item type", "Journal Article" | sort: "Publication year" | reverse %}
{% for article in journal_articles %}
- *{{ article["Publication year"] }}* {{ article.Title }} | {{ article.Journal }}
  - {{ article.Authors }}
{% endfor %}

如果文献有DOI或链接字段,还可以给标题添加跳转:

- *{{ article["Publication year"] }}* [{{ article.Title }}]({{ article.DOI | prepend: "https://doi.org/" | default: "#" }}) | {{ article.Journal }}

内容的提问来源于stack exchange,提问作者brocktree

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 04:05:15