MAC下搭建我的博客

安装homebrewhtml

 

[plain]  view plain  copy
  1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"  

 

安装nodejsnode

 

[plain]  view plain  copy
  1. brew install node  

 

在安装nodejs过程当中,提示以下警告:git

 

[plain]  view plain  copy
  1. You have Xcode 8 installed without the CLT;  

根据提示进行安装github

 

安装hexonpm

 

[plain]  view plain  copy
  1. sudo npm install -g hexo  


建立文件夹浏览器

 

 

[plain]  view plain  copy
  1. mkdir blog  
  2. cd blog  
  3. hexo init  

此时blog文件下出现了不少文件和文件夹,以下图所示:ruby

 

生成一套静态网页服务器

 

[plain]  view plain  copy
  1. hexo generate /** 生成一套静态网页 **/  
  2. hexo server /** 在服务器上运行 **/  

在浏览器上运行http://localhost:4000就能看到以下的网站首页:hexo

撰写博客app

进入终端,使用cd命令进入到有Hexo框架的目录里面,输入:

 

[plain]  view plain  copy
  1. hexo new post "个人第一篇博客"  

随后出现以下的消息:

 

 

[plain]  view plain  copy
  1. INFO  Created: ~/blog/source/_posts/个人第一篇博客.md  

证实建立文章成功,“个人第一篇博客”这个md文件会建立在source/_posts/的文件下。该md文件在自动生成时会带有一些属性:

 

title:     定义了博文的标题

date:   定义了创做博文的时间

tags:   定义了博文的标签

除了这个三个属性之外咱们还能够扩展一些属性:

update:  定义了最后修改的时间

comments:定义可否评论此博文(默认为true)

categories: 定义了博文的种类

配置文件  --  _config.yml说明

Hexo的每个功能的配置文件都是_config.yml, 具体说明看下面的注解:

 

[plain]  view plain  copy
  1. # Hexo Configuration  
  2. ## Docs: https://hexo.io/docs/configuration.html  
  3. ## Source: https://github.com/hexojs/hexo/  
  4.   
  5. # Site                 ##修改以适应搜索引擎的收录  
  6. title: Hexo            ##定义网站的标题  
  7. subtitle:              ##定义网站的副标题  
  8. description:           ##定义网站的描述  
  9. author: jason jwl      ##定义网站的负责人  
  10. language:              ##定义网站的语言,默认zh-Hans  
  11. timezone:              ##定义网站的时区  
  12.   
  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://yoursite.com   ##定义网站访问的域名  
  16. root: /      ##定义所在Web文件夹在哪一个目录  
  17. permalink: :year/:month/:day/:title/  ##定义时间格式  
  18. permalink_defaults:  
  19.   
  20. # Directory  
  21. source_dir: source   ##定义从哪一个文件夹获取博客资料  
  22. public_dir: public   ##定义生成静态网站到哪一个文件夹  
  23.   
  24. archive_dir: archives  
  25. category_dir: categories  
  26. code_dir: downloads/code  
  27. i18n_dir: :lang  
  28. skip_render:  
  29.   
  30. # Writing  
  31. new_post_name: :title.md # File name of new posts  
  32. default_layout: post  
  33. titlecase: false # Transform title into titlecase  
  34. external_link: true # Open external links in new tab  
  35. filename_case: 0  
  36. render_drafts: false  
  37. post_asset_folder: false  
  38. relative_link: false  
  39. future: true  
  40. highlight:  
  41.   enable: true  
  42.   line_number: true  
  43.   auto_detect: false  
  44.   tab_replace:  
  45.   
  46. # Category & Tag  
  47. default_category: uncategorized  
  48. category_map:  
  49. tag_map:  
  50.   
  51. # Date / Time format  
  52. ## Hexo uses Moment.js to parse and display date  
  53. ## You can customize the date format as defined in  
  54. ## http://momentjs.com/docs/#/displaying/format/  
  55. date_format: YYYY-MM-DD  
  56. time_format: HH:mm:ss  
  57.   
  58. # Pagination  
  59. ## Set per_page to 0 to disable pagination  
  60. per_page: 10  ##定义每一页多少条博客  
  61. pagination_dir: page  
  62.   
  63. # Extensions  
  64. ## Plugins: https://hexo.io/plugins/  
  65. ## Themes: https://hexo.io/themes/  
  66. theme: landscape  ##定义使用的主题  
  67.   
  68. # Deployment  
  69. ## Docs: https://hexo.io/docs/deployment.html  
  70. deploy:  
  71.   type:  

注意:

另外修改这些属性时,请注意格式,属性和值要空一个格,好比theme: landscape。

 

本地同步github

在github上new Repository,并命名为xxxxx.github.io(xxxxx是你github的帐号名),而后把本地项目提交到github的远程项目。具体操做步骤能够参考我之前写的一篇博客:http://blog.csdn.net/jasonjwl/article/details/49682217。而后在浏览器上输入xxxxx.github.io就能访问本身的博客了。

同步到github,发现网站访问不了。而且github给我发了一封邮件,以下所示:

 

经测试不是主题的问题。

我的建议不经过手动同步github,优先考虑经过修改_config.yml让hexo帮助咱们同步github,方便快捷,配置以下所示:

 

[plain]  view plain  copy
  1. deploy:  
  2.   type: git  
  3.   repo: https://github.com/xxx/xxx.github.io.git  
  4.   branch: master  
  5.   xxx为我的github的name  

配置完后,运行 

 

[plain]  view plain  copy
  1. hexo deploy  

或者

 

[plain]  view plain  copy
  1. hexo d  

如出现如下的错误:

 

[plain]  view plain  copy
  1. ERROR Deployer not found: git  

请运行如下命令进行安装:

 

[plain]  view plain  copy
  1. npm install hexo-deployer-git --save  

再次运行hexo deploy。工程同步成功!

当你增长新的文章或者插件时,能够经过如下三个命令进行同步操做:

 

[plain]  view plain  copy
  1. hexo clean  
  2. hexo generate  
  3. hexo deploy  



 文章引用博客大神的,这里作一个保存笔记,侵删。

相关文章
相关标签/搜索