安装 nodejs(link:https://nodejs.org/en/)
安装 git(link:https://git-scm.com/)
打开 cmd 命令行,输入
D:
cd D:/hexo
npm install hexo-cli -g
//卸载
npm uninstall hexo-cli
hexo init blog
cd blog
npm install #安装 package.json 中的依赖包
npm install hexo-deployer-git --save #安装 deploy 插件,用于部署到 GitHub
hexo generate #可简写为 hexo g 生成静态文件,会在当前目录下生成一个新的叫做 public 的文件夹
hexo server #可简写为 hexo s 启动本地 web 服务,用于博客的预览
hexo deploy #可简写为 hexo d 部署播客到远端(比如 github, heroku 等平台)
打开浏览器,输入 http://localhost:4000
在 blog 目录下运行
git clone https://github.com/iissnan/hexo-theme-next themes/next #将 next 主题下载到 themes 文件夹下
//更新主题
git pull
打开 blog 目录下的配置文件_config.xml,修改
theme: next #next 即为主题名称
hexo clean #清理 hexo 缓存
hexo s #重新启动本地 web 服务器
主题的其他设置见 next 主题 官网(link:http://theme-next.iissnan.com/) .
打开 blog 目录下的配置文件_config.xml,修改
deploy:
type: git
repo: https://github.com/jonesun/jonesun.github.io.git
branch: master
name: jone sun
email: sunjoner7@gmail.com
执行命令
hexo d
完成部署,过程中需要 github 账号/密码
/.deploy_git
/public
git init
git add .
# 若出现`warning: LF will be replaced by CRLF in`
# 执行:
# git config --global core.autocrlf false
git commit -m "first commit"
git remote add origin https://github.com/jonesun/jonesun.github.io.git
git push -u origin master
# 此时可能会出错 failed to push some refs to git 出现错误的主要原因是 github 中的 README.md 文件不在本地代码目录中,可以通过如下命令进行代码合并
# git pull --rebase origin master
# 此时再执行语句
# git push -u origin master
git pull
hexo new <新的文章>
hexo g
hexo s
git add . #不添加被删除的文件,`git add -A`会添加所有修改.
git commit -m "更新描述"
git remote add origin https://github.com/jonesun/blog.git
git push origin master
hexo d
npm install -g hexo-cli
git clone https://github.com/jonesun/blog.git
rm -rf node_modules && npm install --force
hexo g
hexo s
hexo d请确保 Next 主题版本为 NexT-7.1.2 及以上
npm install hexo-generator-baidu-sitemap --save
npm install hexo-generator-sitemap --save
# 自动生成 sitemap
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
hexo g 生成后进入 public 目录,你会发现里面有 sitemap.xml 和 baidusitemap.xml 两个文件,这就是生成的站点地图。里面包含了网站上所有页面的链接,搜索引擎通过这两个文件来抓取网站页面:
sitemap.xml 用来提交给 Google
baidusitemap.xml 用来提交给百度
google_site_verification: 7MWmpu7Y_liZprzsvd1MxYuG1tRYQ7V1eK9_rLcHmB0
打开谷歌搜索,输入:
//换成自己的域名,查看结果
site: https://jonesun.github.io/
首先注册百度账号,完善个人信息,然后打开 站长平台(link:https://ziyuan.baidu.com/site) , 添加网站,得到验证代码后,在主题配置文件_config.yml 把验证代码写上:
baidu_site_verification: code-SeFMiHxes9
安装插件
npm install hexo-baidu-url-submit --save
在主题配置文件_config.yml 加入:
baidu_url_submit:
count: 5 ## 提交最新的五个链接
host: jonesun.github.io ## 百度站长平台中注册的域名
token: wxEYCMr7JzpSUEfi ## 准入秘钥
path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里
使用草稿新建的文章就不会发布,会存放在/source/_drafts 路径下:
hexo new draft <title>
发布草稿,会把/source/_drafts 下的文章移到/source/_posts 下:
hexo publish <title>
安装 hexo-symbols-count-time
npm install hexo-symbols-count-time --save
next 主题中_config.yml 中配置
symbols_count_time:
separated_meta: true # 是否另起一行(true 的话不和发表时间等同一行)
item_text_post: true # 首页文章统计数量前是否显示文字描述(本文字数、阅读时长)
item_text_total: false # 页面底部统计数量前是否显示文字描述(站点总字数、站点阅读时长)
awl: 4 # Average Word Length
wpm: 275 # Words Per Minute(每分钟阅读词数)
suffix: mins.
如果显示为阅读时长 NaN:aN, 执行 hexo clean 即可。
在 Hexo 更新至 5.x 版本,Next 更新至 7.x 版本后,会出现文章的中文目录点击跳转失效的 bug,参见 Github Issues(link:https://github.com/theme-next/hexo-theme-next/pull/1540/files)
排版布局和翻译风格上可以参考了阮一峰老师的 中文技术文档的写作规范(link:https://github.com/ruanyf/document-style-guide)
更多 Hexo 相关配置,可参考 官网(link:https://hexo.io/zh-cn/docs/)

