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

修改blogdown分类RSS模板:解决标题错误复数化问题

title: Adventures in Shinylive
author: Tobias Fellinger
date: '2024-01-27'
slug: adventures-in-shinylive
categories:

  • R
    tags:
  • R
  • shiny
  • web-r
  • shinylive

This will be a blogpost about porting a shiny app to shinylive.

## caving分类文章示例
```yaml
---
title: example caving post
author: Tobias Fellinger
date: '2024-01-27'
slug: example-caving-post
categories:
  - caving
tags:
  - caving
---

this is a test

配置文件config.yaml内容

baseurl: /
languageCode: en-US
title: "Tobias Fellinger's Blog"
theme: hugo-lithium
googleAnalytics: ''
disqusShortname: ''
ignoreFiles:
  - \.Rmd$
  - \.Rmarkdown$
  - _cache$
permalinks:
  post: /:year/:month/:day/:slug/
menu:
  main:
    - name: About
      url: /about/
    - name: R
      url: /r/
    - name: Caving
      url: /caving/
params:
  MathJaxCDN: //cdnjs.cloudflare.com/ajax/libs
  MathJaxVersion: 2.7.5
  description: A website built through Hugo and blogdown.
  favicon: favicon.ico
  highlightjsCDN: //cdnjs.cloudflare.com/ajax/libs
  highlightjsLang:
    - r
    - yaml
  highlightjsTheme: github
  highlightjsVersion: 9.12.0
  logo:
    alt: Logo
    height: 50
    url: logo.png
    width: 50
markup:
  defaultMarkdownHandler: goldmark
  goldmark:
    renderer:
      unsafe: yes
  highlight:
    codeFences: no

解决方案

1. 无法通过配置文件直接修改

Hugo对分类RSS标题的复数化处理是模板层面的逻辑,无法通过config.yaml直接调整,必须自定义RSS模板。

2. 正确的模板路径

你需要创建分类/标签通用的术语页面RSS模板,路径为:

layouts/_default/terms.rss.xml

这个路径符合Hugo的模板查找优先级,会被分类页面的RSS生成逻辑识别,之前尝试的路径不符合规则所以未生效。

3. 模板修改步骤

  1. 复制主题自带的RSS模板(位置:themes/hugo-lithium/layouts/_default/rss.xml)到上述路径。
  2. 找到模板中设置标题的代码段,原代码类似:
    <title>{{ .Title }} on {{ .Site.Title }}</title>
    
    这里的.Title会自动对分类名做复数化处理,替换为以下任意一种格式:
    • 若要实现「R posts on ...」:
      <title>{{ .Name }} posts on {{ .Site.Title }}</title>
      
    • 若要实现「Posts in R on ...」:
      <title>Posts in {{ .Name }} on {{ .Site.Title }}</title>
      
    .Name会获取分类的原始名称,不会被复数化。

4. 验证修改

修改完成后,重启blogdown::serve_site(),访问对应的分类RSS地址(如http://localhost:4321/caving/index.xml),即可看到更新后的标题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 05:07:23