配置环境

  • Node.js
  • Git
  • Github
  • Hexo

我的建议是首先删除Mac自带的node.js,因为版本太老以免出错,反正我是出错了全部删除重新装的,删除命令如下:

  1. sudo rm /usr/local/bin/npm
  2. sudo rm /usr/local/share/man/man1/node.1
  3. sudo rm /usr/local/lib/dtrace/node.d
  4. sudo rm -rf ~/.npm
  5. sudo rm -rf ~/.node-gyp
  6. sudo rm /opt/local/bin/node
  7. sudo rm /opt/local/include/node
  8. sudo rm -rf /opt/local/lib/node_modules

删除完毕之后去官网下载node.js地址:https://nodejs.org/ 下载默认安装之后npm自带也同时安装好了

准备好之后我们开始安装hexo,命令如下:

  1. sudo npm install -g hexo

安装好Hexo之后,初始化hexo,在初始化之前切换到你所在的博客目录,命令如下:

  1. cd /Users/edwin/Documents/blog
  2. hexo init
  3. blog目录结构
  4.  
  5.  |-- _config.yml 配置文件
  6.  |-- db.json
  7.  |-- package.json
  8.  |-- node_modules
  9.  |-- public
  10.  |-- source 资源文件(务必保存)
  11.  |-- scaffolds
  12.  |-- themes

生产静态页面,命令如下:

  1. hexo g

启动本地服务,访问http://localhost:4000 命令如下:

  1. hexo server

配置hexo-deployer-git,命令如下:

  1. npm install hexo-deployer-git --save

修改_config.yml文件,修改内容如下:
可参考官网文档:https://hexo.io/zh-cn/docs/configuration.html

  1. deploy:
  2. type: git
  3. repository: https://github.com/why168/why168.github.io.git
  4. branch: master

在Github上部署blog,命令如下:
执行完毕之后即可访问 https://why168.github.io/

  1. hexo deploy

总结

一些常用命令:

  1. hexo new "postName" #新建文章
  2. hexo new page "pageName" #新建页面
  3. hexo generate #生成静态页面至public目录
  4. hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
  5. hexo deploy #将.deploy目录部署到GitHub
  6. hexo help #查看帮助
  7. hexo version #查看Hexo的版本

每次部署的步骤,命令如下:

  1. hexo clean
  2. hexo g -d

我给童鞋们看下我的_config.yml配置文件:

  1. # Hexo Configuration
  2. ## Docs: https://hexo.io/docs/configuration.html
  3. ## Source: https://github.com/hexojs/hexo/
  4. # Site
  5. title: Edwin's Blog
  6. subtitle: Edwin's Blog to Android
  7. description: Android,PHP,IOS,JavaScript
  8. author: Edwin
  9. language:
  10. - zh-tw
  11. - en
  12. timezone: Asia/Shanghai
  13. # URL
  14. ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
  15. url: http://github.com/why168
  16. root: /
  17. permalink: :year/:month/:day/:title/:id/:category
  18. permalink_defaults: https://github.com/why168/why168.github.io
  19. # Directory
  20. source_dir: source
  21. public_dir: public
  22. tag_dir: tags
  23. archive_dir: archives
  24. category_dir: categories
  25. code_dir: downloads/code
  26. i18n_dir: :lang
  27. skip_render:
  28. # Writing
  29. new_post_name: :title.md # File name of new posts
  30. default_layout: post
  31. titlecase: false # Transform title into titlecase
  32. external_link: true # Open external links in new tab
  33. filename_case: 0
  34. render_drafts: false
  35. post_asset_folder: true # 文章资源文件夹
  36. relative_link: false
  37. future: true
  38. highlight:
  39. enable: true
  40. line_number: true
  41. auto_detect: false
  42. tab_replace:
  43. # Category & Tag
  44. default_category: 未分类
  45. category_map:
  46. tag_map:
  47. # Date / Time format
  48. ## Hexo uses Moment.js to parse and display date
  49. ## You can customize the date format as defined in
  50. ## http://momentjs.com/docs/#/displaying/format/
  51. date_format: YYYY-MM-DD
  52. time_format: HH:mm:ss
  53. # Pagination
  54. ## Set per_page to 0 to disable pagination
  55. per_page: 5
  56. pagination_dir: page
  57. # Extensions
  58. ## Plugins: https://hexo.io/plugins/
  59. ## Themes: https://hexo.io/themes/
  60. theme: landscape
  61. # Deployment
  62. ## Docs: https://hexo.io/docs/deployment.html
  63. deploy:
  64. user: Edwin.Wu # 使用者名称
  65. port: 22 # 默认值 22
  66. delete: true # 除远程主机上的旧文件 true
  67. verbose: true # 显示调试信息 true
  68. ignore_errors: true # 忽略错误 false
  69. type: git
  70. repository: https://github.com/why168/why168.github.io.git
  71. branch: master
  72. message: 网站更新:{{ now('YYYY-MM-DD HH:mm:ss') }} # 自定义提交信息 (默认为 Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }})

引用