引用
- (官方帮助)
依赖
#安装hexo
npm install hexo -g
#安装hexo命令行模块
npm install hexo-cli -g
#创建blog目录
hexo init blog
cd blog
#初始化
npm install
#安装server插件
npm install hexo-server --save
#git插件
npm install hexo-deployer-git --save
#feed
npm install hexo-generator-feed@1.0.2 --save
#sitemap
npm install hexo-generator-sitemap@1.0.1 --save
hexo init后目录结构
.
├── db.json #json格式的静态常量数据库
├── _config.yml #网站配置
├── package.json #插件依赖
├── scaffolds #文章模板
├── scripts #脚本文件夹
├── source #资源文件夹
| ├── _drafts #草稿
| └── _posts #要发布的源文章
└── themes #主题
下载blog中的图片
写了一个py脚本搞定 https://gist.github.com/wujiyu115/707691f95713c69fde01 把blog文中的图片下载下来放到source目录中,以wp-content目录为根目录,域名不变的前提下文章中的链接都需要再更新
常用命令
hexo new [layout] <title> --hexo n #建立新文章,默认在_posts下,layout="draft"时发布的是草稿
hexo publish <filename> --hexo p #将_drafts下的文件放到_posts下,也就是发布草稿
hexo generate --hexo g #生成静态文件
hexo clean --hexo c #清理缓存
hexo server --hexo s #启动服务器
hexo deploy --hexo d #部署到远程
部署步骤
如果是直接写完整篇文章,部署的步骤。
#创建文章 hexo new post <filename> #生成文章 hexo generate #发布 hexo deploy
如果有草稿的话可以这样
#创建草稿 hexo new draft "new draft" #编辑好草稿好后发布草稿 hexo publish <filename> #预览草稿 hexo server --drafts #发布 hexo deploy
_config.xml
###部署类型设置git
#hexo 3.0 部署类型不再是github,_config.yml 中修改,同时部署到github和gitcafe
deploy:
- type: git
repo: https://github.com/wujiyu115/wujiyu115.github.com.git,master
- type: git
repo: https://gitcafe.com/wujiyu115/farwmarth.git,gitcafe-pages
安装主题
#定位到根目录
git clone https://github.com/iissnan/hexo-theme-next themes/next
#更改根目录_config.yml
theme: next
language: zh-Hans
next主题
hexo源文章和主题管理
github
建立主仓库管理文章叫hexo
- fork一下
next
主题新仓库叫next
- 然后在
hexo
仓库中themes
中添加submodule
这样主题和源文章分开管理.hexo
仓库只托管源文章.
管理主题
- 自己的
next
仓库持有两个远程别名,自有的fork的origin
,另外一个是官方next主题别名为upstream
. - 自己对主题的修改推送到fork的
origin
仓库中 要更新官方的新版本时,从upstream中pull下来进行合并。
git submodule add https://github.com/wujiyu115/hexo-theme-next.git themes/next cd themes/next git remote add upstream https://github.com/iissnan/hexo-theme-next.git
hexo
仓库更新子项目
git clone https://github.com/wujiyu115/hexo.git hexo
cd hexo
git submodule update --recursive --init
删除submodule
git submodule deinit <path_to_submodule-name>
git rm --cached <path_to_submodule>
rm -rf .git/modules/<path_to_submodule>
域名绑定
github
https://help.github.com/articles/tips-for-configuring-an-a-record-with-your-dns-provider/
- ping wujiyu115.github.io记录下IP地址
- CNAME 在仓库根目录下添加一个CNAM文件,没有后缀名,里面内容为你的域名(如:test.com),不需要添加http/www等前缀
- 添加 DNS Service记录
- 清理浏览器缓存
chrome://net-internals#dns
点击clear host cache
gitcafe
https://gitcafe.com/GitCafe/Help/wiki/Pages-%E7%9B%B8%E5%85%B3%E5%B8%AE%E5%8A%A9#wiki
- 将用于 Pages 服务站点的自定义域名使用 CNAME 记录指向 gitcafe.io。
技巧
新建一个不依赖模板的HTML页面
如果你是不想hexo g时被模板改变你的html的话,可在在文件头加layout: false
例如新建一个404页面
layout: false
title: "404"
date: 2015-02-05 20:03:48
---
<html>
<body>
<h1>404 Page Not Found</h1>
</body>
</html>
coding上单项目部署公钥
#测试密钥是否部署成功
ssh -i /data/publish/xxx_rsa -T git@git.coding.net
问题
出现 Cannot GET /
npm install hexo-server --save
- 注意冒号后面都要添加一个半角空格 之后才是设置参数
hexo中source目录的js被渲染
hexo会把hexo/source下的文件全部渲染,放在source目录的js也会被渲染出错,
解决办法就是将js文件放到主题的source目录中,如themes/next/source中
解决hexo神烦的DTraceProviderBindings MODULE_NOT_FOUND
npm install hexo --no-optional
npm uninstall hexo
npm install hexo --no-optional
npm uninstall hexo-cli -g
npm install hexo-cli -g
提交出现fatal:multiple stage entries for merged file
的问题.
在hexo主目录中执行如下操作解决。
rm .git/index
git add -A
git commit