在设置模板过程中,需要留意以下几个问题:

  1. 页面构建缓存。可能导致页面内容可能无法更新。
1
2
3
4
5
6
    {{ $url := "https://api.github.com/repos/user/moments/issues/1/comments" }}
    {{ $opts := dict 
        "headers" (dict "User-Agent" "Hugo Static Site Generator")
        "cache" 300
        "cacheKey" (printf "gh-comments-%s" (now.Format "2006-01-02-15:04"))
    }}
  1. 内容排序。 github issue api 输出数据是最新的内容在后边,需要倒过来。
1
2
3
4
    {{ with resources.GetRemote $url $opts }}
        {{ if and .Content (ne .Content "") }}
            {{ $comments := .Content | transform.Unmarshal (dict "format" "json") }}
            {{ $sortedComments := sort $comments "created_at" "desc" }} 
  1. 时间格式。github issue 默认使用 UTC 时间,中国的话,需要在基准上加8个小时。
1
2
3
<time>  
     {{ (.created_at | time.AsTime).Add 28800e9 | time.Format "2006-01-02 15:04" }}
</time>
刚看到博友圈微信群中有群友问如何在静态博客添加朋友圈/说说这类功能,我第一反应是可以用一个无头CMS单独管理和发表这个页面,但打开PageCMS试了下,发现其实也很麻烦。于是想到跨站引用。这不,试了下 Github Issue 发现很完美。
Built with Hugo, Powered by Github.
全站约 345 篇文章 合计约 984173 字
本站已加入BLOGS·CN