0%

hexo博客搭建,我的参考资料及说明

coco的hexo博客:这个是我的个人博客,自己有个服务器,就放在了服务器上一份。下面是我参考的文章,如果踩过坑,说明了一下。

next主题

配置

  • 摘要
    建议使用 < !– more –>(即第一种方式),除了可以精确控制需要显示的摘录内容以外, 这种方式也可以让 Hexo 中的插件更好的识别。
    自动形成摘要,在主题配置文件中添加
    auto_excerpt:

    enable: true
    length: 150
  • 创建 “关于我” 页面
    新建一个 about 页面:
    hexo new page "about"
    菜单显示 about 链接,在主题的 _configy.yml 设置中将 menu 中 about 前面的注释去掉即可。

    menu:
    home: /
    archives: /archives
    tags: /tags
    about: /about

  • 创建分类页面

  • 一键生成md头格式
    首先在/scaffolds/post.md文件中添加:

    ---
    title: {{ title }}
    date: {{ date }}
    tags:
    categories:
    copyright: true
    permalink: 01
    top: 0
    ---

    然后使用 hexo new就可以一键生成新文章的头格式了,不用手动去搬运或者书写。相当方便。

  • 设定置顶/顺序
    vim node_modules/hexo-generator-index/lib/generator.js 改成下面

    'use strict';
    var pagination = require('hexo-pagination');
    module.exports = function(locals){
      var config = this.config;
      var posts = locals.posts;
        posts.data = posts.data.sort(function(a, b) {
            if(a.top && b.top) { // 两篇文章top都有定义
                if(a.top == b.top) return b.date - a.date; // 若top值一样则按照文章日期降序排
                else return b.top - a.top; // 否则按照top值降序排
            }
            else if(a.top && !b.top) { // 以下是只有一篇文章top有定义,那么将有top的排在前面(这里用异或操作居然不行233)
                return -1;
            }
            else if(!a.top && b.top) {
                return 1;
            }
            else return b.date - a.date; // 都没定义按照文章日期降序排
        });
      var paginationDir = config.pagination_dir || 'page';
      return pagination('', posts, {
        perPage: config.index_generator.per_page,
        layout: ['index', 'archive'],
        format: paginationDir + '/%d/',
        data: {
          __index: true
        }
      });
    };

    在文章中添加 top 值,数值越大文章越靠前(默认是0,按时间排序),如

    ---
    title: 解决Charles乱码问题
    date: 2017-05-22 22:45:48
    tags: 技巧
    categories: 技巧
    copyright: true
    top: 100
    ---