Hexo个人博客
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5.7 KiB

title abbrlink date tags categories keywords description cover
使用Hexo搭建个人博客 332630035 2024-02-29 15:10:58 <nil> <nil> <nil> <nil> <nil>

我之前的博客网站都是在自己的NAS中放的,使用CND使得可以使用80和443端口访问家里NAS的博客,但是因为DDNS每天要断开一段时间,家里偶尔会停电,导致百度和Google的收录效果奇差。无奈值得放弃在NAS放置个人博客。

不在NAS中放置博客后,我最终采用了使用纯静态网页Hexo的方式,并且将静态网也放在了OSS中,本篇主要介绍Hexo个人博客的搭建,OSS的设置放在下一篇。

搭建Hexo

需要安装nodejs,到nodejs官方网站下载最新的node并安装。

随后打开命令提示符,找到合适的位置依次输入如下命令:

npm config set registry https://registry.npmmirror.com/
cnpm install -g hexo

随后创建个人博客文件夹并进入文件夹

md 个人博客
cd 个人博客
hexo init
hexo server

不出意外的话,此时我们就可以使用localhost:4000来访问博客了。

安装主题

Hexo默认的主题并不一定符合我们的审美,在这里推荐下butterfly主题,也是我目前在用的 如图,从butterflygithub地址下载主题后,解压并改名为butterfly后放在themes文件夹下。

随后修改根目录的_config.yml文件,将theme改为butterfly:

theme: butterfly

然后使用命令安装插件

npm install hexo-renderer-pug hexo-renderer-stylus --save

为了后续升级方便,我们在 hexo 的根目录创建一个文件 _config.butterfly.yml,并把butterfly目录的 _config.yml 所有内容复制到 _config.butterfly.yml 去。

网站配置

这里只给出一些基础的配置。

网站名称等配置

根据博客信息自行修改,其中url必须为博客所对应域名。

# Site
title: 牧尘的NAS小站
subtitle: '最好用的NAS使用技巧'
description: 'NAS折腾不完全指南,定期分享一些好玩的东西,不定期记录生活。'
keywords:
author: 牧尘
language: zh-CN
timezone: ''

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://www.dreamlyn.cn

配置文章链接

不修此配置博客也能正常使用,但当文章名为中文时,链接中容易出现中文,不利于百度收录 首先我们安装 hexo-abbrlink 插件

npm install hexo-abbrlink --save

随后修改配置

permalink: :abbrlink.html
permalink_defaults:
abbrlink:
  alg: crc32      #support crc16(default) and crc32
  rep: dec        #support dec(default) and hex
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

添加分类和标签中英文映射。

如果我们的分类或者标签中使用了中文,那么在网页中可能会出现中文url,不利于seo,在此我们进行映射

# Category & Tag
default_category: uncategorized
category_map:
  Linux基础: linux
  网络基础: network
  NAS基础: nasbase
  NAS服务: nasservice
  技术随笔: other
tag_map:
  Linux基础: linux
  网络: network
  NAS技术: nas
  反向代理: rproxy
  影音系统: video

新建分类页

  1. 前往 Hexo 博客的根目录
  2. 输入 hexo new page categories
  3. 你会找到 source/categories/index.md 这个文件
  4. 修改这个文件,添加 type: "categories"
---
title: 分类
date: 2018-01-05 00:00:00
type: "categories"
---

新建分类页

  1. 前往 Hexo 博客的根目录
  2. 输入 hexo new page tags
  3. 你会找到 source/tags/index.md 这个文件
  4. 修改这个文件,添加 type: "tags"
---
title: 标签
date: 2018-01-05 00:00:00
type: "tags"
orderby: random
order: 1
---

新建友情链接页面

  1. 前往 Hexo 博客的根目录
  2. 输入 hexo new page link
  3. 你会找到 source/link/index.md 这个文件
  4. 修改这个文件,添加 type: "link"
---
title: 友情链接
date: 2022-02-22 10:34:50
type: 'link'
random: true
---

# 申请格式
>< 博客名称 + 博客地址 + 博客Logo + 博客简介 >
>博客名称:
>博客地址:
>博客Logo:
>博客简介:
>(在评论中留言即可)

关于Hexo的配置还有很多,本文无法全部列出,其余配置请参照butterfy提供的中文文档,小伙伴们有哪些配置不清楚的可以在评论区留言。

其他常用插件

添加sitemap

安装依赖

λ cnpm install hexo-generator-sitemap --save #sitemap.xml适合提交给谷歌搜素引擎
λ cnpm install hexo-generator-baidu-sitemap --save #baidusitemap.xml适合提交百度搜索引擎

然后在Hexo配置文件_config.yml中添加以下代码

# google 百度收录
sitemap:
  path: sitemap.xml
baidusitemap:
  path: baidusitemap.xml

百度主动推送

安装依赖

λ cnpm install hexo-baidu-url-submit --save

然后在Hexo配置文件_config.yml中添加以下代码

baidu_url_submit:
  count: 3 ## 比如3,代表提交最新的三个链接
  host: www.dreamlyn.cn ## 在百度站长平台中注册的域名
  token: your_token ## 请注意这是您的秘钥, 请不要发布在公众仓库里!
  path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里

生成订阅

安装依赖

λ cnpm install hexo-generator-feed --save

然后在Hexo配置文件_config.yml中添加以下代码

#RSS 订阅
feed:
  type: atom
  path: atom.xml
  limit: 20
  hub: