chore: improvement hexo.extend#5209
Conversation
- StoreFunction & StoreSyncFunction & StoreFunctionData - SyncStore & Store to easily import the interfaces between `extend` source files
fix: conditional when `fn` is not function
chore: convert interface `AsyncTagFunction` to overload type docs: add some JSDoc chore: add prefix `_` to unused variables feat: add interface `RegisterAsyncOptions` fix: missing types feat(Tag.register): add overload types and JSDoc
marked as internal hexo function fix(lint): eslint --fix
fix(lint): eslint --fix
to easily import between source files chore(Renderer.register): add overload method types docs: add JSDoc
chore: add `Pattern` result `boolean` type - PR hexojs/hexo-util/pull/311 - changes hexojs/hexo-util@9ddb7e2
…parameter of type 'string'.
How to testgit clone -b v7-fix-extend https://github.com/dimaslanjaka/hexo.git
cd hexo
npm install
npm test |
chore: cast tag function callback as custom context useful for determining which post or page source the tag processor is currently processing from
| /** | ||
| * register renderer engine | ||
| * - [hexo-renderer-nunjucks example](https://github.com/hexojs/hexo-renderer-nunjucks/blob/c71a1979535c47c3949ff6bf3a85691641841e12/lib/renderer.js#L55-L56) | ||
| * - [typescript example](https://github.com/dimaslanjaka/hexo-renderers/blob/feed801e90920bea8a5e7000b275b912e4ef6c43/src/renderer-sass.ts#L37-L38) | ||
| * @param name input extension name. ex: ejs | ||
| * @param output output extension name. ex: html | ||
| * @param fn renderer function | ||
| */ |
There was a problem hiding this comment.
Is it possible to reduce/dedupe the comment here?
There was a problem hiding this comment.
Is it possible to reduce/dedupe the comment here?
yes, or should we using shortlink from http://bit.ly to reduce comment length ?
| if ( | ||
| typeof data !== 'undefined' | ||
| && !Array.isArray(data) | ||
| && typeof data !== 'boolean' | ||
| && data.lang | ||
| && i18nLanguages.includes(data.lang) | ||
| ) { |
There was a problem hiding this comment.
This is somewhat over-complicated for a simple type guard. Is it possible to simplify it?
There was a problem hiding this comment.
This is somewhat over-complicated for a simple type guard. Is it possible to simplify it?
because there has 3 return type (boolean | RegExpMatchArray | Record<string, unknown>)
see hexojs/hexo-util@e0719fb one of PR hexojs/hexo-util#311
see boolean return conflict
- https://github.com/dimaslanjaka/hexo/blob/4ba63bc65d05d231fd1db1053013e2ae71661a70/lib/plugins/processor/common.ts#L29-L32
- https://github.com/dimaslanjaka/hexo/blob/4ba63bc65d05d231fd1db1053013e2ae71661a70/lib/theme/processors/source.ts#L25-L32
ive tried:
- when only validate (
data), ts throw errorproperty lang does not exist on Array type - when only validate
!Array.isArray(data), ts throw errorproperty lang does not exist on boolean type - when only validate
typeof data === 'object'both errors above will occurs, becauseArrayis also type object
typescript angry without strict validation :(
There was a problem hiding this comment.
if there is any other suggestion, maybe it can be simplified without breaking (throw) during npm run build
There was a problem hiding this comment.
or. enable explicit any, down level iterator, and moved all export as ES Export style. might it can used square bracket (data['page']) to suppress error validation during npm run build
There was a problem hiding this comment.
sample supress syntax https://github.com/dimaslanjaka/static-blog-generator/blob/8cf940f1f7141085c42da874417c3d1a0cecf280/packages/sbg-utility/src/utils/scheduler.ts#L127
but these syntax style unsupported by hexo eslint config, it should be automatically fixed (moved to dots property style - data.page) on commit.
prevent indexed as source by VSCode, Intellij IDEA, Sublime Text v3 Co-authored-by: Sukka <isukkaw@gmail.com>
Co-authored-by: Sukka <isukkaw@gmail.com>
How to testgit clone -b v7-fix-extend https://github.com/dimaslanjaka/hexo.git
cd hexo
npm install
npm test |
What does it do?
objectPatternresultbooleantypeNEED PR chore: some improvement as description hexo-util#311changes hexojs/hexo-util@9ddb7e2OR temporarily install my customhexo-util.npm i hexo-util@https://github.com/dimaslanjaka/hexo/raw/1d4d41d/releases/hexo-util.tgzSee all improved tarballs https://github.com/dimaslanjaka/hexo/tree/monorepo-v7/releasesb33d7e7 chore: moved interfaces toalready merged onrenderer-d.tshexojs/masterusing ES Export style to easily import between source files
TagFunctionto overload typeAsyncTagFunctionto overload type_to unused variablesRegisterAsyncOptionspatternas StoreFunctionfnis not functionctxobjectto `Record<string, any>before_post_rendercallbackas optional & add JSDocsample without callback https://github.com/hexojs/hexo/blob/8b95bbc722e5c77a7e8125441ed64d2ea3524ac0/test/scripts/tags/blockquote.js#LL8C16-L8C96
ExtendedTagPropertyuseful for determining which post or page source the tag processor is currently processing from. see sample https://github.com/dimaslanjaka/hexo-shortcodes/blob/8224f992eee8a221db15996823e6d80e84a13ca1/src/include_file.ts#L55-L56
Demo
Pull request tasks