【问题标题】:Hugo Theme with "featuredpath"带有“特色路径”的雨果主题
【发布时间】:2018-05-05 23:09:20
【问题描述】:

我正在尝试使用 hugo 和 this theme。从 repo 中的示例站点我可以看到,帖子特色图片的配置方式如下:

featured = "pic.jpg"
featuredalt = "Pic 2"
featuredpath = "date"

这需要我将pic.jpg 放入static/img/YEAR/MONTH。 有人可以解释一下,这条路径是如何从featuredpath = "date" 组装起来的吗?还有其他选择吗?也许相对于 source.md 文件?模板魔法发生在here,但没有包含date

【问题讨论】:

    标签: hugo static-site


    【解决方案1】:

    你在正确的轨道上。您注意到涉及layouts/post/featured.html。但请注意这一行:

    {{ partial "img-path" . }}
    

    这意味着这里插入了名为img-path 的部分。所以我们会跳过它。如果你查看/layouts/partials/img-path.html,你会在第 7 行看到这条评论:

     if path is date then it will format the directory to year/date i.e. 2006/01
    

    然后您会看到第 18-24 行,它们创建了以日期为中心的图像路径:

    {{ $.Scratch.Set "path" "/img/" }}
    {{ if eq $structType "shortcode" }}
      {{ $.Scratch.Add "path" (.Page.Date.Format "2006/01") }}
    {{ else }}
      {{ $.Scratch.Add "path" (.Date.Format "2006/01") }}
    {{ end }}
    

    在一些相关的说明中,我发现Hugo forums 对于获得有关此类问题的快速反馈很有价值。

    其他很棒的资源包括博客(例如 Régis Philibertentry by the Future Imperfect theme's creator 的博客)和 Hugo documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-11
      • 2018-09-04
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多