/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/plugins/processor/data.ts
36 строк
774 B
D-Sketon
refactor: refact types (#5271)
31 окт 2023, 15:52
Не верифицирован
31 окт 2023, 15:52
b898f29
Код
Авторство
О чём код?
import { Pattern } from 'hexo-util'; import { extname } from 'path'; import type Hexo from '../../hexo'; import type { _File } from '../../box'; export = (ctx: Hexo) => ({ pattern: new Pattern('_data/*path'), process: function dataProcessor(file: _File) { const Data = ctx.model('Data'); const { path } = file.params; const id = path.substring(0, path.length - extname(path).length); const doc = Data.findById(id); if (file.type === 'skip' && doc) { return; } if (file.type === 'delete') { if (doc) { return doc.remove(); } return; } return file.render().then(result => { if (result == null) return; return Data.save({ _id: id, data: result }); }); } });