Skip to main content

如何使用hexo搭建个人博客

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start#

Create a new post#

hexo new "My New Post"

More info: Writing

Run server#

hexo server

More info: Server

Generate static files#

hexo generate

More info: Generating

Deploy to remote sites#

hexo deploy

如何搭建自己的博客网站#

平台: github/gitee

代码工程应为youname.github.io, 如此依赖便可直接访问 https://yourname.github.io/

打开GitHub Pages,即可访问。建议使用master存放开发代码, gp-pages存放用于访问的静态资源。

More info: Deployment

发布#

方式1#

安装hexo-deployer-git, 配置_config.yml中的

deploy:
type: git
repo: https://github.com/username/username.github.io.git
branch: gh-pages

命令

"deploy": "hexo deploy",

方式2: gh-pages#

  • chalk
  • progress

方式3: Travis CI 持续发布#

操作步骤:

language: node_js
node_js:
- lts/*
cache:
directories:
- node_modules
branches:
only:
- master
before_install:
- export TZ='Asia/Beijing'
install:
- npm install
script:
- npm run build
after_script:
- cd ./public
- git init
- git config user.name "username"
- git config user.email "username@163.com"
- git add .
- git commit -m "Travis CI Auto Builder at $(date +'%Y-%m-%d %H:%M:%S')"
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages

注意: git init 后没有分支, 在git add . 后默认创建mater分支

也可以直接执行npm run deploy, 注意先设置token, 否则运行会失败

选择主题#

当前使用主题: Melody

修改配置文件_config.yml

theme: melody

常见问题#

build资源为空#

错误提示

(node:5510) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5510) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:5510) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:5510) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:5510) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:5510) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency

原因: node v14下存在的bug, 尝试其他版本

参考:

配置travis_ci