i18n.js 528 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Pattern = require('hexo-util').Pattern;
  3. const pathFn = require('path');
  4. exports.process = file => {
  5. const path = file.params.path;
  6. const extname = pathFn.extname(path);
  7. const name = path.substring(0, path.length - extname.length);
  8. const i18n = file.box.i18n;
  9. if (file.type === 'delete') {
  10. i18n.remove(name);
  11. return;
  12. }
  13. return file.render().then(data => {
  14. if (typeof data !== 'object') return;
  15. i18n.set(name, data);
  16. });
  17. };
  18. exports.pattern = new Pattern('languages/*path');