From 784ecdf14dd89d6ff3d42484e635bb0a82aba10b Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 1 Jan 2023 16:15:26 +0800 Subject: [PATCH] update --- lib/extend/deployer.ts | 4 ++-- lib/extend/generator.ts | 2 +- lib/extend/helper.ts | 4 ++-- lib/extend/migrator.ts | 4 ++-- lib/extend/syntax_highlight.ts | 13 +++++++++---- lib/hexo/index.ts | 2 +- lib/hexo/post.ts | 1 + lib/plugins/generator/asset.ts | 4 ++-- lib/plugins/tag/code.ts | 14 +++++++++++++- lib/plugins/tag/index.ts | 2 +- 10 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index d26e4187d8..b743071fdb 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -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'); diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index e5b3b5a533..41a4a07b12 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -13,7 +13,7 @@ class Generator { return this.store; } - get(name) { + get(name: string) { return this.store[name]; } diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index c3a5ba490d..fe0500fdd1 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -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]; } @@ -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'); diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index db0e4eb424..94e725dc0c 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -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'); diff --git a/lib/extend/syntax_highlight.ts b/lib/extend/syntax_highlight.ts index e0d79a2265..22d9371a5e 100644 --- a/lib/extend/syntax_highlight.ts +++ b/lib/extend/syntax_highlight.ts @@ -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 { @@ -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`); diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index daca53d648..ae61e38217 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -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([ diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 1bbebc11b6..563d3fb524 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -228,6 +228,7 @@ interface Data { content?: string; disableNunjucks?: boolean; markdown?: object; + source?: string; } class Post { diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index 76a2da7681..76c8cbc83a 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -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 = { diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index 21e8ebe107..cd7e07bd0e 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -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: @@ -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, diff --git a/lib/plugins/tag/index.ts b/lib/plugins/tag/index.ts index c0128847cb..a136ead63f 100644 --- a/lib/plugins/tag/index.ts +++ b/lib/plugins/tag/index.ts @@ -1,6 +1,6 @@ import moize from 'moize'; -export = ctx => { +export default ctx => { const { tag } = ctx.extend; const blockquote = require('./blockquote')(ctx);