0%

Hexo 常用操作

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

安装 Hexo

  • 安装 Git

  • 安装 Node.js

  • 安装 Hexo

1
$ npm install -g hexo-cli
  • 用 Git 一键部署 Hexo
1
$ npm install hexo-deployer-git --save

基本命令

  • Create a new post
1
2
3
4
$ hexo new "My New Post"

// 在指定位置新建文章
hexo new --path 生活/旅行/杭州 "杭州"

More info: Writing

  • Run server
1
$ hexo server

More info: Server

  • Generate static files
1
$ hexo generate

More info: Generating

  • Deploy to remote sites
1
$ hexo deploy

More info: Deployment

常用设置

Next 常用设置 1

Next 常用设置 2 (标准)

Hexo 常用设置

如何设置阅读全文

  1. 在文章中使用 <!-- more --> 手动进行截断,Hexo 提供的方式 ** 推荐 **
  2. 在文章的 front-matter 中添加 description,并提供文章摘录

主题配置文件优先级

Hexo 的站点配置优先级最高,其次是主题配置:Hexo 在合并主题配置时,Hexo 配置文件中的 theme_config 的优先级最高,其次是 _config.[theme].yml 文件,最后是位于主题目录下的 _config.yml 文件。

访问人数统计

将 _config.[theme].yml 中的 busuanzi 的 counter 改成 enable

添加评论

Gitalk: Gitalk relies on the md5 value of the page path for tagging, the comments will not be loaded correctly if a page’s permalink is changed. 因为这样的局限性,所以放弃 Gitalk,因为文章目录可能会改变。

经测试发现 valine 也是一样和固定链接绑定,所以用这两个效果一样,考虑到数据安全问题,改用 Gitalk。

Gitalk 做本地测试的时候把 Homepage URL 和 Authorization callback URL 改成 http://localhost:4000/ 即可。

评论系统再次切换成 valine,Gitalk 实在不方便,需要注册登陆。

更改头像

替换主题配置文件下的 avatar: /images/avatar_2.gif, 文件放在 themes/next/source/images

插入图片

可以直接在 source(默认根目录)下建立 images 文件夹,然后用绝对路径 ![](/images/1.jpg)(/ 代表根目录 source)
或者打开选项 post_asset_folder(在外层_config.yml 里),使用 hexo new 的时候会生成资源文件夹,然后安装插件 npm install hexo-asset-image –save,这样就可以直接使用相对路径显示图片 ![](1.jpg) (post_asset_folder 选项打开图片才能显示)

引用站内文章

文件名这一项要带上目录名,比如 HelloWorld.md 这个文件放在_posts/hello 这个目录,那你引用的时候需要跟上目录名,否则会引用不到。

1
2
3
{% post_link hello/文件名(不要后缀) 文章别名(可选) %}

{% post_link 语言/C++/C++-地图 C++ 地图 %}