source.js 767 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const { Pattern } = require('hexo-util');
  3. const common = require('../../plugins/processor/common');
  4. exports.process = function(file) {
  5. const Asset = this.model('Asset');
  6. const id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
  7. const { path } = file.params;
  8. const doc = Asset.findById(id);
  9. if (file.type === 'delete') {
  10. if (doc) {
  11. return doc.remove();
  12. }
  13. return;
  14. }
  15. return Asset.save({
  16. _id: id,
  17. path,
  18. modified: file.type !== 'skip'
  19. });
  20. };
  21. exports.pattern = new Pattern(path => {
  22. if (!path.startsWith('source/')) return false;
  23. path = path.substring(7);
  24. if (common.isHiddenFile(path) || common.isTmpFile(path) || path.includes('node_modules')) return false;
  25. return {path};
  26. });