个人博客的一些配置

Butterfly 主题配置

大部分可参考官方文档 Butterfly 文檔(一) 快速開始 | Butterfly

主题修改:直接修改官方的第一个文档中让在博客文件夹根目录下创建的_config.butterfly.yml文件就行

写作模板的 Front-matter

可直接修改 scaffolds 文件夹中的 post 文件,这样新建文章时就可以直接使用新模板

1
2
3
4
5
6
7
8
9
10
11
12
---
title: {{ title }}
date: {{ date }}
updated:
tags:
categories:
description:
top_img: transparent
cover:
copyright:
---

  • updated 更新日期

  • tags 是标签,多个标签结构如下

    1
    2
    3
    tags:
    - tag1
    - tag2
  • categories 分类

  • description 文章的摘要

  • cover 文章的封面图片

  • copyright 文章版权,设成 false 是不加版权信息,空白就是加版权信息

可参考文档 wzpan/hexo-generator-search: A plugin to generate search data for Hexo.

在博客根目录运行 npm install hexo-generator-search --save

然后在博客的配置文件 _config.yml 中最后加入

1
2
3
4
5
6
search:
path: search.xml
field: post
format: html
limit: 1000
# 后两条和官方文档不一样,我参照第二个视频改的

其他就按照官方文档配置

Butterfly 主题 TOC 目录一级标题无法跳转的 BUG

就直接不在文章里使用一级标题,因为文章标题就是 h1 标签。

加载博客时会有蓝色背景一闪,解决方法

在主题文件夹中 themes\butterfly\source\css\_layout\head.styl 找到这个文件,删除掉 background-color: $light-blue 就好了

链接持久化

在博客根目录运行 npm install hexo-abbrlink --save

然后配置 _config.yml 文件,在permalink下添加这些(permalinkurl下面)

1
2
3
4
5
# permalink 
permalink: archives/:abbrlink.html
abbrlink:
alg: crc32 # 算法 crc16(default) and crc32
rep: hex # 进制 dec(default) and hex

搜索引擎收录(Google)

  1. 安装 sitemap ,之前博客搭建已经安装过了,如果没安装请运行
1
npm install hexo-generator-sitemap --save
  1. 然后配置 _config.yml 文件,url 为 https://自己的域名 ,并添加上
1
2
sitemap:
path: sitemap.xml
  1. 进入网站欢迎使用 Google Search Console,输入网址前缀 https://自己的域名
  2. 下载 html 文件至 source 文件夹内,上传至仓库
  3. 搜索 https://自己的域名/刚下的文件名.html ,能搜索到就正确了
  4. 返回 Google Search Console 界面点击验证

如果第一种方法一直验证失败也可以选择其他方法。失败原因可能是 html 文件被主题渲染了而不是原样输出

这里我选择最后一种 DNS TXT 验证,Google Search Console 会自动跳转到 Cloudflare 界面添加记录,很简单

  1. 返回 Google Search Console 进入资源管理界面,选择左侧站点地图(Sitemaps)
  2. 输入 sitemap.xml 点击提交

一些失败原因

状态显示无法抓取 - 显示没有 robots.txt 文件

Google Search Console 进入资源管理界面,选择左侧设置查看抓取失败原因

显示没有 robots.txt 文件

解决方法:

  1. 将 cloudflare 中 AI Crawl Control > Robots.txt > Cloudflare managed 关闭

  2. 新建文件 source/robots.txt 内容如下

    1
    2
    3
    4
    5
    User-agent: *
    Allow: /

    Sitemap: https://你的博客域名/sitemap.xml

  3. 重新上传,等待成功

  4. 还是不行,就谷歌搜索看看能否解决问题(或者换一个.com的域名),或者等一个月左右再查看

参考链接