index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. hexo.config.related_posts = Object.assign(
  2. {
  3. enable: true,
  4. enable_env_name: undefined,
  5. filter_threshold: 0.2,
  6. related_count: 5,
  7. weight: {
  8. title: 0.05,
  9. description: 0.05,
  10. keywords: 0.01,
  11. tags: 0.05,
  12. categories: 0.05,
  13. text: 1
  14. },
  15. stemmers: ['en', 'ru'],
  16. reserved: []
  17. },
  18. hexo.config.related_posts
  19. );
  20. const enable =
  21. (hexo.config.related_posts.enable || hexo.config.related_posts.enable === undefined) &&
  22. (hexo.config.related_posts.enable_env_name !== undefined ? hexo.env.args[hexo.config.related_posts.enable_env_name] : true);
  23. if (enable) {
  24. const calcRelatedPosts = require('./lib/calcRelatedPosts')(hexo);
  25. const postRender = require('./lib/postRender')(hexo);
  26. let calculated = false;
  27. hexo.extend.filter.register('before_post_render', function (data) {
  28. if (calculated === false) {
  29. calculated = true;
  30. calcRelatedPosts();
  31. postRender(data);
  32. } else {
  33. postRender(data);
  34. }
  35. });
  36. hexo.extend.filter.register('after_generate', function () {
  37. calculated = false;
  38. });
  39. }