hexo添加头条站长自动收录(js提交)

将头条站长自动收录js代码添加到 head 标签,提高页面收录的可能性

版本

hexo 5.3.0
next 7.8.0

步骤

头条站长js代码

头条站长-自动收录

自动收录里面应该看到js提交代码,复制 push.js? 后面的值

1
2
3
4
5
6
7
8
9
<script>
(function(){
var el = document.createElement("script");
el.src = "https://sf1-scmcdn-tos.pstatp.com/goofy/ttzz/push.js?复制我";
el.id = "ttzz";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})(window)
</script>

主题配置

使用的主题: next

_config.yml

打开 themes/next/_config.yml 主题配置文件, 在 baidu_analytics 下面添加

1
2
3
4
5
# Baidu Analytics
baidu_analytics:

# Toutiao Analytics
toutiao_analytics: 这里填入 push.js? 之后的值

注意冒号 : 后面要有一个空格

toutiao-analytics.swig

themes/next/layout/_third-party/analytics/ 目录下创建 toutiao-analytics.swig 文件,写入(不需修改)

1
2
3
4
5
6
7
8
9
10
11
{%- if theme.toutiao_analytics %}
<script{{ pjax }}>
(function(){
var el = document.createElement("script");
el.src = "https://sf1-scmcdn-tos.pstatp.com/goofy/ttzz/push.js?{{ theme.toutiao_analytics }}";
el.id = "ttzz";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})(window)
</script>
{%- endif %}

index.swig

themes/next/layout/_third-party/analytics/index.swig 文件中添加(不需修改)

1
{% include 'toutiao-analytics.swig' %}

测试

执行 hexo s ,在网站的 head 标签能看到 头条script标签 就成功了

部署到云服务器后, 在网站按 Fn + F5 刷新