Hexo博客框架相关汇总

创建一个HEXO博客

hexo命令链接

  • 执行命令

    sudo su

  • 安装npm的镜像,以后cnpm代替npm使用

    npm install -g cnpm --registry=https://registry.npm.taobao.org

  • 安装hexo-cli博客框架

    cnpm install -g hexo-cli

  • 创建一个新的文件夹blog,cd到当前文件夹

    cd 文件夹路径

  • 初始化hexo博客

    sudo hexo init

  • 启动本地服务器,本地直接能访问了

    hexo s

  • 新建文章,文章路径 blog/source/_posts

    hexo n “新建一篇文章”

  • 新建插件hexo-deployer-git

    cnpm intall --save hexo-deployer-git

  • 在blog/_config.yml底端编辑

    deploy:
    type: git
    repo: https://github.com/wlw2688/wangliwen.github.io.git
    branch: master

  • 部署到远端

    hexo d

  • 平时修改常用命令

    hexo clean //清理
    hexo g //生成
    hexo s //启动本地服
    hexo d //部署远端

HEXO更换主题

  1. 下载最新的主题,放到blog/themes文件夹下
  2. 在 blog/_config.yml 编辑

    #pure就是新主题的文件夹名字
    theme: pure

HEXO新建分类、标签等

  1. 用命令行新建一个页面:(页面名称可以任意)

    hexo new page “tages”

  2. 打开 /source/tages/index.md,设置其类型 type 值为“tages”

    title: tags
    date: 2019-07-26 00:33:58
    type: “tags”

  3. 打开 /themes/主题/_config.yml,把tages标签那项取消注释即可,下面的是已经取消注释了的。

    menu:
    主页: /
    #随笔: /tags/随笔/
    #分类: /categories
    #归档: /archives
    标签: /tags

hexo写文章相关

  • hexo引用本地自己的文章

    _config.yml 中有个permalink的设置。比如你设成 :category/:title/ 路径就是分类/标题,而不是按时间来做路径了,这个是可以随意配置的。
    如下:
    [自定义名字](/category/文件名/)
    注意:如果_posts内部有文件夹的话需要添加文件夹路径
    [自定义名字](/category/文件夹名../文件名/)

  • hexo插入图片

    1. 在hexo根目录下执行如下命令
      cnpm install hexo-asset-image
    2. 命令创建新的文章,在 source/_posts 中会生成文章 post_name.md 和同名
      hexo n article_name
  • hexo图片布局

    <div style="width:70%;margin-bottom:15px;">{% asset_img 图片名字.jpg %}</div>

错误整理

  • 出现Cannot GET/xxx错误便意味着xxx文件未被找到
    1. 判断public目录下xxx文件是否存在。
      (我的错误是 Cannot GET /,因此在public目录下寻找index.html是否存在。)

    2. 如果说index.html不存在,那么执行hexo c,hexo g重新生成一次,回到步骤1。

    3. 步骤2执行完后index.html仍不存在,执行npm audit fix,查看是否少了什么组件,通过npm install hexo-xxx-xxx 安装即可。
      (我的hexo缺少了hexo-generator-index组件,因此执行npm install hexo-generator-index即可)

    4. 步骤3完成之后,执行hexo c,hexo g重新生成静态文件。