配置环境
- Node.js
- Git
- Github
- Hexo
我的建议是首先删除Mac自带的node.js,因为版本太老以免出错,反正我是出错了全部删除重新装的,删除命令如下:
sudo rm /usr/local/bin/npmsudo rm /usr/local/share/man/man1/node.1sudo rm /usr/local/lib/dtrace/node.dsudo rm -rf ~/.npmsudo rm -rf ~/.node-gypsudo rm /opt/local/bin/nodesudo rm /opt/local/include/nodesudo rm -rf /opt/local/lib/node_modules
删除完毕之后去官网下载node.js地址:https://nodejs.org/ 下载默认安装之后npm自带也同时安装好了
准备好之后我们开始安装hexo,命令如下:
sudo npm install -g hexo
安装好Hexo之后,初始化hexo,在初始化之前切换到你所在的博客目录,命令如下:
cd /Users/edwin/Documents/bloghexo initblog目录结构||-- _config.yml 配置文件|-- db.json|-- package.json|-- node_modules|-- public|-- source 资源文件(务必保存)|-- scaffolds|-- themes
生产静态页面,命令如下:
hexo g
启动本地服务,访问http://localhost:4000 命令如下:
hexo server
配置hexo-deployer-git,命令如下:
npm install hexo-deployer-git --save
修改_config.yml文件,修改内容如下:
可参考官网文档:https://hexo.io/zh-cn/docs/configuration.html
deploy:type: gitrepository: https://github.com/why168/why168.github.io.gitbranch: master
在Github上部署blog,命令如下:
执行完毕之后即可访问 https://why168.github.io/
hexo deploy
总结
一些常用命令:
hexo new "postName" #新建文章hexo new page "pageName" #新建页面hexo generate #生成静态页面至public目录hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)hexo deploy #将.deploy目录部署到GitHubhexo help #查看帮助hexo version #查看Hexo的版本
每次部署的步骤,命令如下:
hexo cleanhexo g -d
我给童鞋们看下我的_config.yml配置文件:
# Hexo Configuration## Docs: https://hexo.io/docs/configuration.html## Source: https://github.com/hexojs/hexo/# Sitetitle: Edwin's Blogsubtitle: Edwin's Blog to Androiddescription: Android,PHP,IOS,JavaScriptauthor: Edwinlanguage:- zh-tw- entimezone: Asia/Shanghai# URL## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'url: http://github.com/why168root: /permalink: :year/:month/:day/:title/:id/:categorypermalink_defaults: https://github.com/why168/why168.github.io# Directorysource_dir: sourcepublic_dir: publictag_dir: tagsarchive_dir: archivescategory_dir: categoriescode_dir: downloads/codei18n_dir: :langskip_render:# Writingnew_post_name: :title.md # File name of new postsdefault_layout: posttitlecase: false # Transform title into titlecaseexternal_link: true # Open external links in new tabfilename_case: 0render_drafts: falsepost_asset_folder: true # 文章资源文件夹relative_link: falsefuture: truehighlight:enable: trueline_number: trueauto_detect: falsetab_replace:# Category & Tagdefault_category: 未分类category_map:tag_map:# Date / Time format## Hexo uses Moment.js to parse and display date## You can customize the date format as defined in## http://momentjs.com/docs/#/displaying/format/date_format: YYYY-MM-DDtime_format: HH:mm:ss# Pagination## Set per_page to 0 to disable paginationper_page: 5pagination_dir: page# Extensions## Plugins: https://hexo.io/plugins/## Themes: https://hexo.io/themes/theme: landscape# Deployment## Docs: https://hexo.io/docs/deployment.htmldeploy:user: Edwin.Wu # 使用者名称port: 22 # 默认值 22delete: true # 除远程主机上的旧文件 trueverbose: true # 显示调试信息 trueignore_errors: true # 忽略错误 falsetype: gitrepository: https://github.com/why168/why168.github.io.gitbranch: mastermessage: 网站更新:{{ now('YYYY-MM-DD HH:mm:ss') }} # 自定义提交信息 (默认为 Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }})
