hexo-generator-basic-set源码讲解(一)

这是一个hexo多语言切换套装
因为hexo本身做多语言切换也是需要自己写一些代码的,利用这个套装插件,可以节省不少的力气

https://github.com/zyzyz/hexo-generator-basic-set/blob/master/index.js

/* global hexo */

'use strict'

var assign = require('object-assign');// 调用公共库object-assign,合并对象用的

var per_page = typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page;

/* Index */
if (hexo.config.index_generator) {
  hexo.config.index_generator = assign({
    per_page: per_page,
    order_by: '-date'
  }, hexo.config.index_generator);

  hexo.extend.generator.register('index', require('./lib/generator-index'));
}

if (hexo.config.archive_generator) {
  hexo.config.archive_generator = assign({
    per_page: per_page,
    yearly: true,
    monthly: true,
    daily: false
  }, hexo.config.archive_generator);

  hexo.extend.generator.register('archive', require('./lib/generator-archive'));
}

if (hexo.config.category_generator) {
  hexo.config.category_generator = assign({
    per_page: per_page,
  }, hexo.config.category_generator);

  hexo.extend.generator.register('category', require('./lib/generator-category'));
}

if (hexo.config.tag_generator) {
  hexo.config.tag_generator = assign({
    per_page: per_page,
    enable_index_page: false
  }, hexo.config.tag_generator);

  hexo.extend.generator.register('tag', require('./lib/generator-tag'));
}

index文件是插件的入口文件
里面调用的其实就是 hexo.extend.generator.register,这个会在每次hexo g命令的时候调用

你可能感兴趣的:(hexo-generator-basic-set源码讲解(一))