Skip to content

Commit

Permalink
fix: export of processors
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Feb 28, 2023
1 parent 978c462 commit cc3553b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
12 changes: 8 additions & 4 deletions lib/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ 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';

class Theme extends Box {
public config: any;
Expand All @@ -17,10 +21,10 @@ class Theme extends Box {
this.views = {};

this.processors = [
require('./processors/config'),
require('./processors/i18n'),
require('./processors/source'),
require('./processors/view')
config,
i18n,
source,
view
];

let languages = ctx.config.language;
Expand Down
9 changes: 7 additions & 2 deletions lib/theme/processors/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Pattern} from 'hexo-util';

export function process(file) {
function process(file) {
if (file.type === 'delete') {
file.box.config = {};
return;
Expand All @@ -15,4 +15,9 @@ export function process(file) {
});
}

export const pattern = new Pattern(/^_config\.\w+$/);
const pattern = new Pattern(/^_config\.\w+$/);

export const config = {
pattern: pattern,
process: process
}
9 changes: 7 additions & 2 deletions lib/theme/processors/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Pattern} from 'hexo-util';
import {extname} from 'path';

export function process(file) {
function process(file) {
const { path } = file.params;
const ext = extname(path);
const name = path.substring(0, path.length - ext.length);
Expand All @@ -18,4 +18,9 @@ export function process(file) {
});
}

export const pattern = new Pattern('languages/*path');
const pattern = new Pattern('languages/*path');

export const i18n = {
pattern: pattern,
process: process
}
10 changes: 8 additions & 2 deletions lib/theme/processors/source.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Pattern} from 'hexo-util';
import * as common from '../../plugins/processor/common';

export function process(file) {
function process(file) {
const Asset = this.model('Asset');
const id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
const { path } = file.params;
Expand All @@ -22,11 +22,17 @@ export function process(file) {
});
}

export const pattern = new Pattern(path => {
const pattern = new Pattern(path => {
if (!path.startsWith('source/')) return false;

path = path.substring(7);
if (common.isHiddenFile(path) || common.isTmpFile(path) || path.includes('node_modules')) return false;

return {path};
});


export const source = {
pattern: pattern,
process: process
}
9 changes: 7 additions & 2 deletions lib/theme/processors/view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pattern } from 'hexo-util';

export function process(file) {
function process(file) {
const { path } = file.params;

if (file.type === 'delete') {
Expand All @@ -13,4 +13,9 @@ export function process(file) {
});
}

export const pattern = new Pattern('layout/*path');
const pattern = new Pattern('layout/*path');

export const view = {
pattern: pattern,
process: process
}

0 comments on commit cc3553b

Please sign in to comment.