hexo注意事项

2017.6.28 - 银川 hexo

1.在命令行下的安装步骤:

npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server

浏览器打开http://localhost:4000进行预览

2.下载next主题

git clone https://github.com/iissnan/hexo-theme-next.git

将主题放到blog/themes目录下,重命名为next,然后修改blog/_config.yml,theme: next

3.生成

hexo g #generate  

此时会生成一个public文件夹,也可以将里面的内容放到tomcat/ROOT进行预览

4.新建文章

hexo n #new  
Usage: hexo new [layout] <title>

Description:
Create a new post.

Arguments:
  layout  Post layout. Use post, page, draft or whatever you want.
  title   Post title. Wrap it with quotations to escape.

Options:
  -p, --path     Post path. Customize the path of the post.
  -r, --replace  Replace the current post if existed.
  -s, --slug     Post slug. Customize the URL of the post.  

会在blog/source/_posts内生成文章

5.如何保存.md文件源码

如果按照上面的流程,最终生成整个网站的html,然后推送到gh-pages里面,而源码只会保存在本地。 那如何保存源码呢?可以使用Travis CI来进行持续集成发布,或者用一个repository放源码,一个放生成的html网站如

--  blog
        +   node_modules
        +   public
        +   scaffolds
        +   source
        +   themes
        +   themesSourse
        +   .gitattributes
        +   .gitignore
        +   _config.yml
        +   copyPublic.bat
        +   db.json
        +   package.json
        +   README.md

--  blog.github.io
        +   2019
        +   about
        +   archives
        +   css
        +   fonts
        +   images
        +   js
        +   links
        +   page
        +   .gitattributes
        +   index.html
        +   README.md

然后新建文章,生成page的html网站后(hexo g),写一个批处理拷贝到发布的reposigory里,如copy.bat:

@echo off 
echo y|xcopy D:\AGithub\blog\public\*.* D:\AGithub\blog\blog.github.io\ /s /e /y

注意:几个常用的命令

1.生成项目
$ hexo init <folder>
$ cd <folder>
$ npm install

2.hexo clean
$ D:\AGithub\andy>hexo clean
$ INFO  Deleted database.
$ INFO  Deleted public folder.

3.$ hexo g
$ hexo g #或hexo generate

$ D:\AGithub\andy>hexo g
$ INFO  Start processing
$ WARN  ===============================================================
$ WARN  ========================= ATTENTION! ==========================
$ WARN  ===============================================================
$ WARN   NexT repository is moving here: https://github.com/theme-next
$ WARN  ===============================================================
$ WARN   It's rebase to v6.0.0 and future maintenance will resume there
$ WARN  ===============================================================
$ INFO  Files loaded in 1.37 s
$ INFO  Generated: index.html
$ INFO  Generated: archives/index.html
$ ...
$ INFO  Generated: lib/three/three.min.js
$ INFO  114 files generated in 1.35 s

4.hexo s
$ hexo s #或hexo server

$ D:\AGithub\andy>hexo s
$ INFO  Start processing
$ WARN  ===============================================================
$ WARN  ========================= ATTENTION! ==========================
$ WARN  ===============================================================
$ WARN   NexT repository is moving here: https://github.com/theme-next
$ WARN  ===============================================================
$ WARN   It's rebase to v6.0.0 and future maintenance will resume there
$ WARN  ===============================================================
$ INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

现在打开http://localhost:4000就可以看到预览界面

6.发布到GitHub Pages的设置

在respository里面的Setting->GitHub Pages,选择Source,一般选择master,还可以设置Custom domain指定域名指向本网站

7.加上宝贝回家的页面

在根目录下新建一个404.html页面,内容如下:

<script type="text/javascript" src="http://www.qq.com/404/search_children.js" homepageurl="http://nongdonghui.github.io" homepagename="Back To Home"></script>

参考文章:

相关阅读