step 1. 在github新建page
登录GitHub,注册自定义用户名如wangbinbin0326;
在主页右下角创建New repository,name必须和用户名一致如wangbinbin0326.github.io;
点击新建的repository(wangbinbin0326.github.io),然后点击
launch automatic page generator
,选择自己喜欢的page 模板,创建后10分钟左右可以访问。http://wangbinbin0326.github.io/ 此时访问的是默认模板在gh-pages 这个branch;注意:我们需要修改这个branch,page 才可以显示我们hexo创建的博客,
wangbinbin0326.github.io ---> setting ---> GitHub Pages ---> master branch
。
step 2. 安装Hexo
- 安装准备:
- 系统 win7 64bit
- hexo 3.2.2
- node.js 安装完成后添加Path环境变量,使npm命令生效。新版已经会自动配置Path
- GitHub Windows
- 安装Hexo
配置好GitHub window后,双击桌面上的Git Shell,输入npm命令即可安装
12345678910111213141516171819202122232425 $ npm install hexo-cli -ghexo-util@0.6.0 postinstall C:\Users\binbiwan\AppData\Roaming\npm\node_modules\hexo-cli\node_modules\hexo-utilnpm run build:highlightC:\Users\binbiwan\AppData\Roaming\npm\hexo -> C:\Users\binbiwan\AppData\Roaming\npm\node_modules\hexo-cli\bin\hexohexo-cli@1.0.2 C:\Users\binbiwan\AppData\Roaming\npm\node_modules\hexo-cli├── object-assign@4.1.0├── abbrev@1.0.9├── minimist@1.2.0├── bluebird@3.4.6├── tildify@1.2.0 (os-homedir@1.0.2)├── chalk@1.1.3 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, strip-ansi@3.0.1, has-ansi@2.0.0)├── hexo-util@0.6.0 (html-entities@1.2.0, striptags@2.1.1, camel-case@3.0.0, cross-spawn@4.0.2, highlight.js@9.7.0)├── hexo-log@0.1.2 (bunyan@1.8.1)└── hexo-fs@0.1.6 (graceful-fs@4.1.9, escape-string-regexp@1.0.5, chokidar@1.6.0)──────────────────────────────────────────────────────────────────────────────────────────────$ npm install hexo --save├── swig@1.4.2 (optimist@0.6.1, uglify-js@2.4.24)├── hexo-log@0.1.2 (bunyan@1.8.1)├── nunjucks@2.5.2 (asap@2.0.5, yargs@3.32.0, chokidar@1.6.0)├── moment@2.13.0├── cheerio@0.20.0 (entities@1.1.1, dom-serializer@0.1.0, css-select@1.2.0, htmlparser2@3.8.3, jsdom@7.2.2)├── hexo-util@0.6.0 (striptags@2.1.1, html-entities@1.2.0, camel-case@3.0.0, cross-spawn@4.0.2, highlight.js@9.7.0)├── lodash@4.16.4└── warehouse@2.2.0 (graceful-fs@4.1.9, is-plain-object@2.0.1, JSONStream@1.2.1, cuid@1.3.8)>
安装Hexo插件git
12 $ npm install hexo-deployer-git --save>创建站点BlogHexo
1234 $ hexo init BlogHexo$ cd BlogHexo$ npm install>配置站点BlogHexo
1234567891011121314 编辑站点BlogHexo目录下的_config.ymltitle: Tony Blogsubtitle: 迈小步,不停步description: 终会有属于自己的一片天空!author: Tony Wanglanguage: zh-Hanstimezone:url: http://wangbinbin0326.github.io/theme: nextdeploy:type: gitrepo: https://github.com/wangbinbin0326/wangbinbin0326.github.io.gitbranch: master>更改站点BlogHexo的主题NEXT
1234567891011121314 $ pwd/c/git/BlogHexo/BlogHexo/themesgit clone https://github.com/iissnan/hexo-theme-next themes/next$ mv hexo-theme-next next编辑NEXT主题目录下的配置文件_config.ymlmenu:home: 注意这地有个空格符archives: archivestags: /tagsavatar: https://wangbinbin0326.github.io/images/job/myself.jpgauto_excerpt:enable: truelength: 150>写Blog
123456789101112131415 $ hexo new post Oracle-DB-概述$ pwd/c/git/BlogHexo/BlogHexo/source/_posts$ ll-rw-r--r-- 1 binbiwan 1049089 3948 十月 13 01:15 Oracle-DB-概述.md编辑Oracle-DB-概述.md这个文件,使用Markdown格式$ hexo g$ hexo gINFO Start processingINFO Files loaded in 1.83 sINFO Generated: archives/2016/index.htmlINFO Generated: tags/DBA/index.htmlINFO Generated: tags/Oracle/index.htmlINFO Generated: index.html>查看blog
1234 $ hexo sINFO Start processingINFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.>提交Blog到github
1234567891011121314151617181920212223242526272829303132333435363738394041424344 ──────────────────────────────────────────────────────────────────────────────────────────────1. 确保 git remote 是git@github.com, 这种方式连接$ git remote -vorigin git@github.com:wangbinbin0326/wangbinbin0326.github.io.git (fetch)origin git@github.com:wangbinbin0326/wangbinbin0326.github.io.git (push)$ git remote remove origingit remote add origin git@github.com:wangbinbin0326/wangbinbin0326.github.io.git$ git remote -vorigin git@github.com:wangbinbin0326/wangbinbin0326.github.io.git (fetch)origin git@github.com:wangbinbin0326/wangbinbin0326.github.io.git (push)──────────────────────────────────────────────────────────────────────────────────────────────2. 确保使用桌面上的github登录,会生成以下两个文件C:\Users\binbiwan\.ssh> pwdC:\Users\binbiwan\.sshC:\Users\binbiwan\.ssh> lsDirectory: C:\Users\binbiwan\.sshMode LastWriteTime Length Name---- ------------- ------ -----a--- 2016/10/13 16:18 1679 github_rsa-a--- 2016/10/13 16:18 405 github_rsa.pub──────────────────────────────────────────────────────────────────────────────────────────────3. 确保提交blog代码时,打开Git Shell运行,否则会报错如下错误,nothing to commit, working directory cleanbash: /dev/tty: No such device or addresserror: failed to execute prompt script (exit code 1)fatal: could not read Username for 'https://github.com': Invalid argumentFATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.htmlError: bash: /dev/tty: No such device or addresserror: failed to execute prompt script (exit code 1)fatal: could not read Username for 'https://github.com': Invalid argumentC:\git\BlogHexo\BlogHexo [master +4 ~2 -1 !]> hexo dINFO Deploying: gitINFO Clearing .deploy_git folder...INFO Copying files from public folder...warning: LF will be replaced by CRLF in 2016/10/11/DBA职责/index.html.The file will have its original line endings in your working directory.warning: LF will be replaced by CRLF in 2016/10/12/Oracle-DB-概述/index.html.The file will have its original line endings in your working directory.Branch master set up to track remote branch master from https://github.com/wangbinbin0326/wangbinbin0326.github.io.git.To https://github.com/wangbinbin0326/wangbinbin0326.github.io.gitf3b58e1..bb12b42 HEAD -> masterINFO Deploy done: git>
step 3. 优化blog
- 创建标签云页面
- 新建一个页面,命名为 tags 。命令如下:
hexo new page "tags"
- 编辑刚新建的页面,将页面的类型设置为 tags ,主题将自动为这个页面显示标签云。
title: All tags date: 2014-12-22 12:39:04 type: "tags"
- 在菜单中添加链接。编辑主题的 _config.yml ,添加 tags 到 menu 中,如下:
menu: home: / archives: /archives tags: /tags
- hexo next 添加分类页
- 新建一个页面,命名为 categories 。命令如下:
hexo new page categories
- 编辑刚新建的页面,将页面的类型设置为 categories ,主题将自动为这个页面显示所有分类。
title: 分类 date: 2014-12-22 12:39:04 type: "categories"
- 在菜单中添加链接。编辑主题的 _config.yml ,将 menu 中的 categories: /categories 注释去掉,如下:
menu: home: / categories: /categories archives: /archives tags: /tags
- hexo中有Front-matter这个概念,是文件最上方以 — 分隔的区域,用于指定个别文件的变量。举个栗子,在hexo new post article时会生成article.md文件,文件生成好的文章属性。在其中添加categories属性,再部署之后就可以在分类页看到分类了。
--- title: Oracle-DB-概述 date: 2016-10-12 17:12:40 tags: Oracle categories: Database ---
- hexo next 设置背景图片
12345678910111213141516 将背景图片放到改目录下backgroud.jpgC:\git\BlogHexo\BlogHexo\themes\next\source\images编辑改文件C:\git\BlogHexo\BlogHexo\themes\next\source\css\_custom\custom.styl// Custom styles.body{background-image:url(/images/backgroud.jpg);background-repeat: no-repeat;background-attachment:fixed;background-position:50% 50%;}footer{color: #eee;}注:此方法push git 上,背景色无法显示,>
step 4. 运到的问题
- TypeError: Cannot set property ‘lastIndex’ of undefined error, and error message as below
--- highlight: enable: true line_number: true auto_detect: false --true改为false tab_replace: ---