首先要感谢给我们免费提供二级域名和云服务器的 github 还有提供框架 Hexo和主题 next(再见 next,你好 Butterfly:官方demo或者 官方配置方法, 魔性修改)。在最后还有一些小技巧的汇总方便查阅,其中包括 mathjax,git 的配置,pip 和 npm的国内镜像加速设置。(将 win10 下 WSL Ubuntu20.04 作为唯一开发环境,将 VScode 作为唯一开发工具。) 换主题了不再更新, 请移步到: butterfly 主题配置

本站 .com 域名不用备案,只需实名制即可

每次迁移都要处理 Github SSL,deploy Save,mathjax渲染, Nunjucks报错处理(对应修改local Search, feed)

Hexo环境搭建

  1. 小丁教程:安装 Hexo 并上传到 git 上(这里超详细
  2. 注意 一定要把github上Pages功能打开 才行(最后enable HTTPs)
  3. 主题 next安装
  4. 安装 nmp 和 pip 的 post_link note 国内加速
  5. mathjax渲染
  6. Windows 下安装 markdown IDE: sublime3 + Typora
  7. Typora 写公式快捷键 ctrl + shift + m
  8. hexo文章加密 方式1方式2
  9. 部署代码到 Coding 并把源代码提交到Coding(账号是手机号)
  10. Bing 提交链接

这次大更新的说明 (2020/3/12)

因为我之前的失误,导致 markdown 源文件丢失,又因为备份更新的时间比较久,导致了我两年没有更新博客,所以这次我配置 hexo 的时候,有讲源码提交到 github 上去。可是最后我还是选择了 next5.1.4 主题,而没有更新到 next7.7.2

老博客地址:https://dna049.github.io/ (绑定账号:FDU校邮

这次迁移的工作量是巨大,但是很有意义的:

  1. 我把博文中个人生活部分加密了
  2. http 升级到 https(超级简单)
  3. 域名 dna049.com 到 2022 年过期,记得到时候续费
  4. 加了百度统计,leanCould 文章数量统计,打赏,不蒜子统计博客访问量
  5. 加了 背景圆角设置(sidebar不是圆角很难受,被 枫糖帮助解决),标签云彩色 Tags 和 logo
  6. 加了 友链 方式一(方式二容易出问题)
  7. 复习一下之前写的博文,熟练一下语法(markdown, C++, Python, Latex),顺带查错
  8. 删除了一点现在看来没什么意思的博文
  9. 知道保存好自己修改过的 next 主题。
  10. 增加 RSS 功能RSS 使用说明

Hexo功能介绍

  1. 内部引用:
  2. 创建新文件夹: hexo new page newdir
  3. hexo 中渲染 mathjax: 看这里
  4. 设置 文章置顶
  5. 安装主题next更新到稳定的 版本 5.1.4配置 (不用看教程就能配置),不建议更新到最新版本很不稳定
  6. 显示更新时间: 找到 next 主题的 _config.yml在里面查找 update 会找到一个 updated_at 的属性改为 true 即可看到更新时间
  7. next中添加爱心
  8. next主题记得设置tags文件夹下的index.md
  9. next隐藏部分博文
  10. next5.1.4 的问题
  11. Nunjucks 报错处理

mathjax 示例

The Quadratic Formula

The Lorenz Equations

The Cauchy-Schwarz Inequality

A Cross Product Formula

\displaystyle 可以让行内公式有行间公式的视觉效果

git 上传源代码到私有仓库

在博客所用的 github 账号下再建立一个私有仓库,然后,在 blog 目录下相应修改 .gitignore 的内容,并在 blog 目录下执行下面git命令:

1
2
3
4
5
6
git init
git add .
# git remote rm origin
git remote add origin https://github.com/dna049/dna049Source.git # 只需添加一次
git commit -m "first commit"
git push -u origin master # -u 一次之后就可以直接用 git push提交了

一键提交源代码

可以正常更新后,在 blog 目录下新建一个 updateSourceCode.py 文件:

1
2
3
4
5
6
7
8
9
# update source code
import os
#os.system('git init')
os.system('git add .')
#os.system('git remote add origin https://github.com/dna049/dna049Source.git')
# 上面是github 下面是 Coding
#os.system('git remote add origin https://e.coding.net/dna049/dna049Source.git')
os.system('git commit -m "update"')
os.system('git push origin master')

以后每次在 blog 目录下执行 py update.py 就可以了。

如何快速从GitHub下载文件

nmp 安装国内镜像:

npm config set registry https://registry.npm.taobao.org

pip 安装的国内镜像在后面加(也可以一劳永逸,就是麻烦了点):

-i https://pypi.tuna.tsinghua.edu.cn/simple

pip 本地安装

  • tar.gz 文件: pip install *.tar.gz
  • 解压好的source 文件:pip install -e filePath -i ...,加 -i 是防止要安装依赖包

Windows 文件比较: FC A.py B.py

Hexo + git 教程:

准备工作:

  • 安装git

  • 安装Node.js (选择自动安装依赖包)

  • nmp添加国内镜像源: npm config set registry https://registry.npm.taobao.org

  • 安装hexonpm install -g hexo-cli

以下所有跟 github 相关的内容都建议早上操作

搭建hexo:

新建一个blog文件夹,进入blog目录,依次输入

1
2
3
4
5
hexo init
nmp install
hexo clean #可选
hexo g
hexo s

在浏览器输入网址: localhost:4000 看到 HelloWorld 说明成功了。

部署到 github

登录 github ,创建 yourname/yourname.github.io 仓库, 进入该仓库 setting,下拉到 Github Page

设置 master branch,Custom domain(可选),Enforce HTTPS

git 命令行进入 blog 目录,执行下面操作:

1
2
ssh-keygen -t rsa -C yourmail@example.com #建议不设置密码,按回车
clip < ~/.ssh/id_rsa.pub # 复制公钥到系统粘贴板

去 github 账号的 setting 中添加 ssh key(复制到 key 就可以了)

检测是否成功: ssh -T git@github.com

设置全局用户信息:

1
2
git config --global user.name yourname
git config --global user.email yourmail@example.com

_config.yml (最后一行)设置:

1
2
3
deploy:
type: git
repository: git@github.com:yourname/yourname.github.io.git

执行:npm install hexo-deployer-git --save

然后执行: hexo g -d 就可以去 http(s)://yourname.github.io 看到自己的博客了。

配置 _config.yml

填写 site 信息, 设置 url , 建议 permalink 改为 :title/,设置 # Pagination 下的 per_page: 0

配置主题,配好了修改 _config.yml 的 theme 为当前主题

2022 年 2 月把主题更新到最新版本