Exemple #1
0
`).then(result => {
    result.repository.issues.edges.forEach((em) => {
        const {title, body, createdAt, url, labels} = em.node;
        const tags = labels.edges.map(em => em.node.name);
        const mdContent = `---
title: ${title}
date: ${createdAt}
url: ${url}
tags:
${tags.map(tag => `    - ${tag}`).join('\n')}
---

${body}`;
        fs.writeFileSync(`./source/_posts/${title}.md`, mdContent);
    });
    console.info('更新 md 完毕');
    execSync(`rm -rf ./public`);
    fs.mkdirSync('./public');
    fs.writeFileSync('./public/CNAME', 'wuhaolin.cn\nwww.wuhaolin.cn');

    const hexo = new Hexo();
    hexo.init().then(function () {
        hexo.call('generate',{}).then(function () {
            execSync(`rm -rf docs`);
            execSync(`mv public docs`);
            console.log('网站生成完毕');
            process.exit(0);
        });
    });
}).catch(err => {
Exemple #2
0
gulp.task('generate', function(){
	hexo.init().then(function(){
	  hexo.call('generate');
	}).catch(function(err){
	  console.log(err);
	});
	
});
 before(function () {
   hexo.config.permalink = ':title';
   hexo.config.url = 'http://yoursite.com/rootpath';
   hexo.config.root = '/rootpath/';
   hexo.init();
   return insertPosts()
     .then(insertPages)
     .then(insertTags)
     .then(setHexoLocals);
 });
var instanciateHexo = function (category) {
  var hexo = new Hexo(__dirname, {silent: true});
  hexo.config.sitemap = {
    path: 'sitemap.xml'
  };
  if (category !== undefined) {
    hexo.config.sitemap.category = category;
  }
  hexo.config.permalink = ':title';
  hexo.init();
  return Promise.resolve(hexo);
};
var instanciateHexo = function(tag) {
  var hexo = new Hexo(__dirname, { silent: true })
  hexo.config.sitemap = {
    path: 'sitemap.xml'
  }
  if (tag !== undefined) {
    hexo.config.sitemap.tag = tag
  }
  hexo.config.permalink = ':title'
  hexo.init()
  return Promise.resolve(hexo)
}
Exemple #6
0
  (HEXO_CONFIG.server.port || '80') +
  (HEXO_CONFIG.root || '').replace(/\/+$/, '');
var REQUEST_OPTS = {
  followAllRedirects: true,
  rejectUnauthorized: false,
  timeout: 10000,
  headers: {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Firefox/45.0'
  }
};
var WWW_DIR = 'public';

var linksUnique = [];
var linksPromises = [];

hexo.init().then(function () {
  return hexo.call('generate', {});
})
.then(checkLinks)
.catch(function (err) {
  console.log(err.stack);
});

function checkLinks () {
  glob('public/**/*.html', function (err, files) {
    if (err) {
      console.error('Error:\n%s', err);
      return;
    }

    var lastFileIdx = files.length - 1;
 return new Promise(function (resolve, reject) {
     hexo.init().then(function () {
         hexo.call('generate', {force: true}).then(resolve, reject);
     });
 });
Exemple #8
0
describe('Tag generator', function() {
  var hexo = new Hexo(__dirname, {silent: true});
  hexo.init();
  var Post = hexo.model('Post');
  var generator = require('../lib/generator').bind(hexo);
  var posts,
    locals;

  // Default config
  hexo.config.tag_generator = {
    per_page: 10
  };

  before(function() {
    return Post.insert([
      {source: 'foo', slug: 'foo', date: 1e8},
      {source: 'bar', slug: 'bar', date: 1e8 + 1},
      {source: 'baz', slug: 'baz', date: 1e8 - 1},
      {source: 'boo', slug: 'boo', date: 1e8 + 2}
    ]).then(function(data) {
      posts = data;

      return posts[0].setTags(['foo']).then(function() {
        return posts[1].setTags(['bar']);
      }).then(function() {
        return posts[2].setTags(['foo']);
      }).then(function() {
        return posts[3].setTags(['foo']);
      });
    }).then(function() {
      locals = hexo.locals.toObject();
    });
  });

  describe('Disable index page', function() {
    it('pagination enabled', function() {
      hexo.config.tag_generator.per_page = 2;

      var result = generator(locals);

      result.length.should.eql(3);

      for (var i = 0, len = result.length; i < len; i++) {
        result[i].layout.should.eql(['tag', 'archive', 'index']);
      }

      result[0].path.should.eql('tags/foo/');
      result[0].data.base.should.eql('tags/foo/');
      result[0].data.total.should.eql(2);
      result[0].data.current.should.eql(1);
      result[0].data.current_url.should.eql('tags/foo/');
      result[0].data.posts.eq(0)._id.should.eql(posts[3]._id);
      result[0].data.posts.eq(1)._id.should.eql(posts[0]._id);
      result[0].data.prev.should.eql(0);
      result[0].data.prev_link.should.eql('');
      result[0].data.next.should.eql(2);
      result[0].data.next_link.should.eql('tags/foo/page/2/');
      result[0].data.tag.should.eql('foo');

      result[1].path.should.eql('tags/foo/page/2/');
      result[1].data.base.should.eql('tags/foo/');
      result[1].data.total.should.eql(2);
      result[1].data.current.should.eql(2);
      result[1].data.current_url.should.eql('tags/foo/page/2/');
      result[1].data.posts.eq(0)._id.should.eql(posts[2]._id);
      result[1].data.prev.should.eql(1);
      result[1].data.prev_link.should.eql('tags/foo/');
      result[1].data.next.should.eql(0);
      result[1].data.next_link.should.eql('');
      result[1].data.tag.should.eql('foo');

      result[2].path.should.eql('tags/bar/');
      result[2].data.base.should.eql('tags/bar/');
      result[2].data.total.should.eql(1);
      result[2].data.current.should.eql(1);
      result[2].data.current_url.should.eql('tags/bar/');
      result[2].data.posts.eq(0)._id.should.eql(posts[1]._id);
      result[2].data.prev.should.eql(0);
      result[2].data.prev_link.should.eql('');
      result[2].data.next.should.eql(0);
      result[2].data.next_link.should.eql('');
      result[2].data.tag.should.eql('bar');

      // Restore config
      hexo.config.tag_generator.per_page = 10;
    });

    it('pagination disabled', function() {
      hexo.config.tag_generator.per_page = 0;

      var result = generator(locals);

      result.length.should.eql(2);

      for (var i = 0, len = result.length; i < len; i++) {
        result[i].layout.should.eql(['tag', 'archive', 'index']);
      }

      result[0].path.should.eql('tags/foo/');
      result[0].data.base.should.eql('tags/foo/');
      result[0].data.total.should.eql(1);
      result[0].data.current.should.eql(1);
      result[0].data.current_url.should.eql('tags/foo/');
      result[0].data.posts.eq(0)._id.should.eql(posts[3]._id);
      result[0].data.posts.eq(1)._id.should.eql(posts[0]._id);
      result[0].data.posts.eq(2)._id.should.eql(posts[2]._id);
      result[0].data.prev.should.eql(0);
      result[0].data.prev_link.should.eql('');
      result[0].data.next.should.eql(0);
      result[0].data.next_link.should.eql('');
      result[0].data.tag.should.eql('foo');

      result[1].path.should.eql('tags/bar/');
      result[1].data.base.should.eql('tags/bar/');
      result[1].data.total.should.eql(1);
      result[1].data.current.should.eql(1);
      result[1].data.current_url.should.eql('tags/bar/');
      result[1].data.posts.eq(0)._id.should.eql(posts[1]._id);
      result[1].data.prev.should.eql(0);
      result[1].data.prev_link.should.eql('');
      result[1].data.next.should.eql(0);
      result[1].data.next_link.should.eql('');
      result[1].data.tag.should.eql('bar');

      // Restore config
      hexo.config.tag_generator.per_page = 10;
    });

    it('custom pagination_dir', function() {
      hexo.config.tag_generator.per_page = 2;
      hexo.config.pagination_dir = 'yo';

      var result = generator(locals);

      result.map(function(item) {
        return item.path;
      }).should.eql(['tags/foo/', 'tags/foo/yo/2/', 'tags/bar/']);

      // Restore config
      hexo.config.tag_generator.per_page = 10;
      hexo.config.pagination_dir = 'page';
    });
  });

  describe('Enable index page', function() {
    it('pagination enabled', function() {
      hexo.config.tag_generator.per_page = 2;
      hexo.config.tag_generator.enable_index_page = true;

      var result = generator(locals);

      result.length.should.eql(4);

      for (var i = 0, len = result.length - 1; i < len; i++) {
        result[i].layout.should.eql(['tag', 'archive', 'index']);
      }

      result[3].layout.should.eql(['tag-index', 'tag', 'archive', 'index']);

      result[0].path.should.eql('tags/foo/');
      result[0].data.base.should.eql('tags/foo/');
      result[0].data.total.should.eql(2);
      result[0].data.current.should.eql(1);
      result[0].data.current_url.should.eql('tags/foo/');
      result[0].data.posts.eq(0)._id.should.eql(posts[3]._id);
      result[0].data.posts.eq(1)._id.should.eql(posts[0]._id);
      result[0].data.prev.should.eql(0);
      result[0].data.prev_link.should.eql('');
      result[0].data.next.should.eql(2);
      result[0].data.next_link.should.eql('tags/foo/page/2/');
      result[0].data.tag.should.eql('foo');

      result[1].path.should.eql('tags/foo/page/2/');
      result[1].data.base.should.eql('tags/foo/');
      result[1].data.total.should.eql(2);
      result[1].data.current.should.eql(2);
      result[1].data.current_url.should.eql('tags/foo/page/2/');
      result[1].data.posts.eq(0)._id.should.eql(posts[2]._id);
      result[1].data.prev.should.eql(1);
      result[1].data.prev_link.should.eql('tags/foo/');
      result[1].data.next.should.eql(0);
      result[1].data.next_link.should.eql('');
      result[1].data.tag.should.eql('foo');

      result[2].path.should.eql('tags/bar/');
      result[2].data.base.should.eql('tags/bar/');
      result[2].data.total.should.eql(1);
      result[2].data.current.should.eql(1);
      result[2].data.current_url.should.eql('tags/bar/');
      result[2].data.posts.eq(0)._id.should.eql(posts[1]._id);
      result[2].data.prev.should.eql(0);
      result[2].data.prev_link.should.eql('');
      result[2].data.next.should.eql(0);
      result[2].data.next_link.should.eql('');
      result[2].data.tag.should.eql('bar');

      result[3].path.should.eql('tags/');
      result[3].data.base.should.eql('tags/');
      result[3].data.total.should.eql(1);
      result[3].data.current.should.eql(1);
      result[3].data.current_url.should.eql('tags/');
      // just all posts
      result[3].data.posts.should.eql(locals.posts);
      result[3].data.prev.should.eql(0);
      result[3].data.prev_link.should.eql('');
      result[3].data.next.should.eql(0);
      result[3].data.next_link.should.eql('');
      // no tag, tags instead
      (result[3].data.tag === undefined).should.be.true;
      result[3].data.tags.should.eql(locals.tags);

      // Restore config
      hexo.config.tag_generator.per_page = 10;
    });

    it('pagination disabled', function() {
      hexo.config.tag_generator.per_page = 0;
      hexo.config.tag_generator.enable_index_page = true;

      var result = generator(locals);

      result.length.should.eql(3);

      for (var i = 0, len = result.length - 1; i < len; i++) {
        result[i].layout.should.eql(['tag', 'archive', 'index']);
      }

      result[2].layout.should.eql(['tag-index', 'tag', 'archive', 'index']);

      result[0].path.should.eql('tags/foo/');
      result[0].data.base.should.eql('tags/foo/');
      result[0].data.total.should.eql(1);
      result[0].data.current.should.eql(1);
      result[0].data.current_url.should.eql('tags/foo/');
      result[0].data.posts.eq(0)._id.should.eql(posts[3]._id);
      result[0].data.posts.eq(1)._id.should.eql(posts[0]._id);
      result[0].data.posts.eq(2)._id.should.eql(posts[2]._id);
      result[0].data.prev.should.eql(0);
      result[0].data.prev_link.should.eql('');
      result[0].data.next.should.eql(0);
      result[0].data.next_link.should.eql('');
      result[0].data.tag.should.eql('foo');

      result[1].path.should.eql('tags/bar/');
      result[1].data.base.should.eql('tags/bar/');
      result[1].data.total.should.eql(1);
      result[1].data.current.should.eql(1);
      result[1].data.current_url.should.eql('tags/bar/');
      result[1].data.posts.eq(0)._id.should.eql(posts[1]._id);
      result[1].data.prev.should.eql(0);
      result[1].data.prev_link.should.eql('');
      result[1].data.next.should.eql(0);
      result[1].data.next_link.should.eql('');
      result[1].data.tag.should.eql('bar');

      result[2].path.should.eql('tags/');
      result[2].data.base.should.eql('tags/');
      result[2].data.total.should.eql(1);
      result[2].data.current.should.eql(1);
      result[2].data.current_url.should.eql('tags/');
      result[2].data.posts.should.eql(locals.posts);
      result[2].data.prev.should.eql(0);
      result[2].data.prev_link.should.eql('');
      result[2].data.next.should.eql(0);
      result[2].data.next_link.should.eql('');
      (result[2].data.tag === undefined).should.be.true;
      result[2].data.tags.should.eql(locals.tags);

      // Restore config
      hexo.config.tag_generator.per_page = 10;
    });

    it('custom pagination_dir', function() {
      hexo.config.tag_generator.per_page = 2;
      hexo.config.pagination_dir = 'yo';
      hexo.config.tag_generator.enable_index_page = true;

      var result = generator(locals);

      result.map(function(item) {
        return item.path;
      }).should.eql(['tags/foo/', 'tags/foo/yo/2/', 'tags/bar/', 'tags/']);

      // Restore config
      hexo.config.tag_generator.per_page = 10;
      hexo.config.pagination_dir = 'page';
    });
  });
});
 constructor(base_dir) {
   this.hexo = new Hexo(base_dir, {});
   this.hexo.init().then(function(){
     console.log('Hexo init success.');
   });
 }