hexo+github搭建个人博客

github pages搭建博客

1) hexo安装
官网有命令(https://hexo.io/zh-cn/)

2)创建博客文件夹
这里博客文件夹名字为:my-blog;
这里的文件夹和github仓库文件,不是一个,github仓库文件是hexo 推送过去,因此本地博客文件夹最好再单独建立一个github仓库作备份。

hexo init my-blog
cd my-blog  
npm install

3)本地启动预览
hexo server
http://localhost:4000

4)生成静态网站
hexo g

5)部署到github pages

1.创建一个同名仓库,创建页面:https://github.com/new
2. 安装部署插件
    npm install hexo-deployer-git --save
3. 修改 _config.yml 末尾,添加部署配置:
    deploy:
    type: git
    repo: https://github.com/yourusername/yourusername.github.io.git
    branch: main  # 或 master,与你仓库默认分支一致
4. 部署
    hexo clean
    hexo generate
    hexo deploy
    # 简写命令
    hexo g -d
5.访问
    https://yourusername.github.io

github pages域名绑定

  1. 购买域名
    .com、.net老牌顶级域名比较通用,尤其是做国外广告插入分配权重较高,价格较贵;
    .tech新顶级域名,第一年较便宜,后面会很贵,一般比.com等老牌域名便宜;

    阿里云域名购买网站:https://wanwang.aliyun.com/domain

  2. 域名解析

域名解析控制台:https://dc.console.aliyun.com/next/index?spm=5176.27097949.J_9138996270.6.766d4b594XWKpv#/domain-list/all

点击解析

  1. 本地public文件夹,或者github仓库增加CNAME文件,内容为域名比如www.codepapper.com(在本地文件夹的public目录,hexo clean时该文件夹会更新CNAME会消失,导致域名绑定失效,需要重新创建)

常用的命令

部署成功后,安装包的在hexoblog路径
hexo g 生成静态网页
hexo d 部署到github
hexo clean 清楚hexo缓存,即清除public文件夹
hexo g –d 生成并部署

https://blog.csdn.net/weixin_42365530/article/details/107750003
https://zhuanlan.zhihu.com/p/60578464

hexo主题商店
https://hexo.io/themes/

Author

skzeng

Posted on

2025-05-17

Updated on

2025-07-19

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.

You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.