ppoffice / hexo-theme-minos

A simple and retro styled Hexo theme, concentrated more on your ideas.
http://ppoffice.github.io/hexo-theme-minos
MIT License
765 stars 202 forks source link

如何添加百度统计 #46

Closed ghost closed 6 years ago

ghost commented 6 years ago

由于网上的文章都是针对某个主题,所以它不适合我。我也曾效仿你的其他作品从而进行设置,可惜依然不行。 想请问一下对于该主题如何添加百度统计?就像Google统计那样,可以在主题配置文件中通过“id”进行一键设置。

ppoffice commented 6 years ago

@taiyuanhang 流程简述

  1. 在/layout/plugins/目录下新建插件文件,如baidu-analytics.ejs
  2. 将百度统计代码复制到其中,并注意用<%= get_config('plugins.baidu-analytics.tracking_id') %>函数替换掉自己的ID。函数中的plugins.baidu-analytics.tracking_id为配置项名称,可以自定义,但要与下面步骤中的配置文件保持一致
  3. 在主题配置文件中添加相应的配置,如
    plugins:
        baidu-analytics:
            tracking_id: xxxxx...

函数说明

  1. has_config(config_name): 检测主题配置文件中是否存在某配置项
  2. get_config(config_name): 获取配置项的值

具体实现可以参照 https://github.com/ppoffice/hexo-theme-minos/blob/master/layout/plugins/google-analytics.ejs

ghost commented 6 years ago

@ppoffice 已解决,谢谢。