Hexo基于node.js,可用于生成静态博客,结合github和Mac,可以专注创作了。
深入学习见文末引用。
hexo安装
brew install node
sudo npm install hexo-cli -g #全局安装
创建博客
Hexo使用命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| hexo init <folder> hexo new [layout] <title> hexo new page <title> hexo generate -d -w hexo publish [layout] <filename> hexo server -p -s -l --draft 连草稿也生成预览 hexo deploy -g hexo render <file1> [file2] ... -o hexo migrate <type> hexo clean hexo list <type>
|
hexo landscape-plus主题
git clone https://github.com/xiangming/landscape-plus.git themes/landscape-plus
#修改hexo的配置文件_config.yml
theme:landscape-plus
deploy
#使用git前先安装
npm install hexo-deployer-git --save
国内github-page百度抓不到,参见hexo同步托管到gitcafe和github配置
技巧
#在_config.yml里面配置
category_map:
工具集: tools
技术集: technique
tag_map:
Java: java
JavaScript: js
css: css
html5: html5
plugin
- hexo-generator-sitemap
- hexo-generator-feed
1 2 3 4 5
| npm install hexo-generator-sitemap npm install hexo-generator-baidu-sitemap npm install hexo-generator-feed npm install hexo-console-optimize
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
plugins: - hexo-generator-feed - hexo-generator-sitemap - hexo-generator-baidu-sitemap - hexo-console-optimize
feed: type: atom path: atom.xml limit: 20
baidusitemap: path:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| vim themes\modernist\layout\_partial\baidu_tongji.ejs # 添加 <% if (theme.baidu_tongji){ %> <script type="text/javascript"> # 你的百度统计代码 </script> <% } %> # 注册并登录百度统计获取你的统计代码。并设置关闭显示百度图标
vim themes\modernist\layout\_partial\head.ejs # 在『/head』之前增加:
<%- partial('baidu_tongji') %> # 重新生成并部署你的站点。 vim themes/landscape-plus/_config.yml # menu下加 rss: /atom.xml
# Duoshuo duoshuo_shortname: XXX
# Baidu tongji baidu_tongji: true
|
相比较而言,swiftype更个性化,但是搜索结果只是基于页面内容是否包含,没有百度智能。参考
脚本批量修改下吧~~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
function listDir($dir) { static $res = array(); if (!file_exists($dir) || !is_dir($dir)) { return array(); } $dirHandle = opendir($dir); while ($file = readdir($dirHandle)) { if ($file !== '.' && $file !== '..') { $tmp = $dir . "/" . $file; if (is_dir($tmp)) { listDir($tmp); } else if (stripos($file, ".md") !== false) { $res[] = $tmp; } }; }; closedir($dirHandle); return $res; }
$path = '/pathto/blog/source/_posts'; $files = listDir($path); foreach ($files as $file) { file_put_contents($file, preg_replace('/^(#+)([^#\s]+)/m', '$1 $2', file_get_contents($file))); } echo 'ok';
|
- 升级错误(至3.2.2)
- hexo-console-optimize
3.2.2开始hexo-console-optimize却少依赖不能成功,按提示缺少的安装可以成功,但已放弃使用
- hexo-generator-feed
另外hexo-generator-feed会有报错提示,但不影响使用
3.2.2不需设置此节点,不然所有plugin也要写
hexo3.2.2 package.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| { "name": "hexo-site", "version": "0.0.0", "private": true, "hexo": { "version": "3.2.2" }, "dependencies": { "hexo": "^3.2.2", "hexo-deployer-git": "^0.2.0", "hexo-generator-archive": "^0.1.4", "hexo-generator-baidu-sitemap": "^0.1.2", "hexo-generator-category": "^0.1.3", "hexo-generator-feed": "^1.1.0", "hexo-generator-index": "^0.2.0", "hexo-generator-sitemap": "^1.1.2", "hexo-generator-tag": "^0.2.0", "hexo-migrator-rss": "^0.1.2", "hexo-renderer-ejs": "^0.2.0", "hexo-renderer-marked": "^0.2.11", "hexo-renderer-stylus": "^0.3.1", "hexo-server": "^0.2.0", "hexo-tag-bootstrap": "0.0.8", "minimatch": "^3.0.2" } }
|
update
移除影响访问速度的字体
传送门
如果是landscape-plus主题,source-code-pro
字体的css在themes/landscape-plus/layout/_partial/head.ejs
atom编辑器+atom-hexo
好用不多说!
atom
atom-hexo
参考自:
hexo-your-blog
深入学习,请看官方文档
如有疑问,请文末留言交流或邮件:newbvirgil@gmail.com
本文链接 : https://newbmiao.github.io/2015/06/16/hexo-on-your-github.html