/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/theme/index.ts
87 строк
2 KB
D-Sketon
refactor: refactor types & support warehouse6 (#5483)
22 янв 2025, 10:05
Не верифицирован
22 янв 2025, 10:05
70efca7
Код
Авторство
О чём код?
import { extname } from 'path'; import Box from '../box'; import View from './view'; import I18n from 'hexo-i18n'; import { config } from './processors/config'; import { i18n } from './processors/i18n'; import { source } from './processors/source'; import { view } from './processors/view'; import type Hexo from '../hexo'; class Theme extends Box { public config: any; public views: Record<string, Record<string, View>>; public i18n: I18n; public View: typeof View; constructor(ctx: Hexo, options?: any) { super(ctx, ctx.theme_dir, options); this.config = {}; this.views = {}; this.processors = [ config, i18n, source, view ]; let languages: string | string[] = ctx.config.language; if (!Array.isArray(languages)) languages = [languages]; languages.push('default'); this.i18n = new I18n({ languages: [...new Set(languages.filter(Boolean))] }); class _View extends View {} this.View = _View; _View.prototype._theme = this; _View.prototype._render = ctx.render; _View.prototype._helper = ctx.extend.helper; } getView(path: string): View { // Replace backslashes on Windows path = path.replace(/\\/g, '/'); const ext = extname(path); const name = path.substring(0, path.length - ext.length); const views = this.views[name]; if (!views) return; if (ext) { return views[ext]; } return views[Object.keys(views)[0]]; } setView(path: string, data: string): void { const ext = extname(path); const name = path.substring(0, path.length - ext.length); this.views[name] = this.views[name] || {}; const views = this.views[name]; views[ext] = new this.View(path, data); } removeView(path: string): void { const ext = extname(path); const name = path.substring(0, path.length - ext.length); const views = this.views[name]; if (!views) return; views[ext] = undefined; } } export = Theme;