2

我的Hugo第一篇:评论、网站统计

 1 year ago
source link: https://petrie.github.io/2022/05/%E6%88%91%E7%9A%84hugo%E7%AC%AC%E4%B8%80%E7%AF%87%E8%AF%84%E8%AE%BA%E7%BD%91%E7%AB%99%E7%BB%9F%E8%AE%A1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

文章

我的Hugo第一篇:评论、网站统计

2022年05月23日      666 字 - 2 分钟

一、支持评论

先看配置改动 9e9acc
Disqus 的交互设计太傻X了。
如何正确获取你需要配置的内容,见下面的导引:
首页->Get Start -> I want to install Disqus on my site -> Website Name。
这个Website Name 就是你需要再配置文件填入的内容

参考资料,Hugo官方文档: 点击

二、配置Google Analytics

先看配置改动 894ac5 如何获取配置内容,见如下操作步骤: 进入配置首页

第一步:点击"Create Property"

img.png

第二步:填入名称,选择时区和货币

img_1.png

第三部:选择行业分类

img_2.png

第四部:选择平台:Web

img_3.png

第五步:填入网站地址和流名称

img_4.png

第六部:获取ID
右上角的MEASUREMENT ID即为需要填入配置文件的内容

img_5.png
按以上流程配置完后,刷新页面
进入 Google Analytics 首页 ,查看 View realtime部分不为0则说明接入成功了

三、配置日期格式、文章字数、阅读时长

1、日期格式配置:

#file:config.toml
[params]
    date_format = "2006年01月2日" #日期格式调整的配置

2、字数、时长配置:
2.1 先更新配置文件

#file:config.toml
[params]
    show_reading_time = true #支持显示文章字数和阅读市场的配置

此时文章标题下方已经可以显示了,但是还是英文,如何调整问中文呢?

2.2 关键字汉化
首先,将配置文件:themes/ananke/i18n/zh.toml 复制到 i18n/zh.toml

├── i18n
│   └── zh.toml
└── themes
    └── ananke
        ├── i18n
        │   ├── en.toml
        │   └── zh.toml #复制它到 i18n/zh.toml

并且更新配置文件,此时才会应用i18n/zh.toml的配置

#file:config.toml
DefaultContentLanguage = "zh"

但这个时候仍然是中文,这是因为i18n/zh.toml配置没有覆盖全
在其尾巴添加如下配置:

#file:config.toml
[readingTime]
other = "{{ .Count }} 分钟"

[wordCount]
other = "{{ .Count }} 字"

此时可以看到已经是中文了 ,但是还有问题,此时的字数统计是不准确的。

#file:content:/posts/example.md
isCJKLanguage: true

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK