Lawtee News

h2dcc commented on h2dcc/moments: Issue #1

在设置模板过程中,需要留意以下几个问题:
  1. 页面构建缓存。可能导致页面内容可能无法更新。
    {{ $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 输出数据是最新的内容在后边,需要倒过来。
    {{ 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个小时。
<time>  
     {{ (.created_at | time.AsTime).Add 28800e9 | time.Format "2006-01-02 15:04" }}
</time>