Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Feb 11, 2023
1 parent 02c8496 commit 784ecdf
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/extend/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Deployer {
return this.store;
}

get(name) {
get(name: string) {
return this.store[name];
}

register(name, fn) {
register(name: string, fn) {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');

Expand Down
2 changes: 1 addition & 1 deletion lib/extend/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Generator {
return this.store;
}

get(name) {
get(name: string) {
return this.store[name];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/extend/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Helper {
* @param {String} name - The name of the helper plugin
* @returns {Function}
*/
get(name) {
get(name: string) {
return this.store[name];
}

Expand All @@ -26,7 +26,7 @@ class Helper {
* @param {String} name - The name of the helper plugin
* @param {Function} fn - The helper plugin function
*/
register(name, fn) {
register(name: string, fn) {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');

Expand Down
4 changes: 2 additions & 2 deletions lib/extend/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class Migrator {
return this.store;
}

get(name) {
get(name: string) {
return this.store[name];
}

register(name, fn) {
register(name: string, fn) {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');

Expand Down
13 changes: 9 additions & 4 deletions lib/extend/syntax_highlight.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
interface Options {
context?: any;
args?: any;
}

interface StoreFunction {
(...args: any[]): any;
priority?: number;
}

interface Store {
[key: string]: StoreFunction[]
[key: string]: StoreFunction
}

class SyntaxHighlight {
Expand All @@ -14,17 +19,17 @@ class SyntaxHighlight {
this.store = {};
}

register(name, fn) {
register(name: string, fn: StoreFunction) {
if (typeof fn !== 'function') throw new TypeError('fn must be a function');

this.store[name] = fn;
}

query(name) {
query(name: string) {
return name && this.store[name];
}

exec(name, options) {
exec(name: string, options: Options) {
const fn = this.store[name];

if (!fn) throw new TypeError(`syntax highlighter ${name} is not registered`);
Expand Down
2 changes: 1 addition & 1 deletion lib/hexo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class Hexo extends EventEmitter {
require('../plugins/injector')(this);
require('../plugins/processor')(this);
require('../plugins/renderer')(this);
require('../plugins/tag')(this);
require('../plugins/tag').default(this);

// Load config
return Promise.each([
Expand Down
1 change: 1 addition & 0 deletions lib/hexo/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ interface Data {
content?: string;
disableNunjucks?: boolean;
markdown?: object;
source?: string;
}

class Post {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/generator/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ interface Data {
}

const process = (name, ctx) => {
return Promise.filter(ctx.model(name).toArray(), (asset: warehouse.Schema) => fs.exists(asset.source).tap(exist => {
return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => fs.exists(asset.source).tap(exist => {
if (!exist) return asset.remove();
})).map((asset: warehouse.Schema) => {
})).map((asset: warehouse['Schema']) => {
const { source } = asset;
let { path } = asset;
const data: Data = {
Expand Down
14 changes: 13 additions & 1 deletion lib/plugins/tag/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ const rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+)\s+(.+)/i;
const rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/\S+)/i;
const rCaption = /\S[\S\s]*/;

interface Options {
lang: string;
language_attr: boolean;
firstLine: number;
caption: string;
line_number: boolean;
line_threshold: number;
mark: number[];
wrap: boolean;
lines_length?: number;
}

/**
* Code block tag
* Syntax:
Expand All @@ -25,7 +37,7 @@ const rCaption = /\S[\S\s]*/;
* @returns {String} Code snippet with code highlighting
*/

function parseArgs(args) {
function parseArgs(args): Options {
const _else = [];
const len = args.length;
let lang, language_attr,
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/tag/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moize from 'moize';

export = ctx => {
export default ctx => {
const { tag } = ctx.extend;

const blockquote = require('./blockquote')(ctx);
Expand Down

0 comments on commit 784ecdf

Please sign in to comment.