-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to reduce/dedupe the comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is somewhat over-complicated for a simple type guard. Is it possible to simplify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, becauseArray
is also type object
typescript angry without strict validation :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
object
Pattern
resultboolean
typeNEED 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.tgz
See all improved tarballs https://github.com/dimaslanjaka/hexo/tree/monorepo-v7/releasesb33d7e7 chore: moved interfaces toalready merged onrenderer-d.ts
hexojs/master
using ES Export style to easily import between source files
TagFunction
to overload typeAsyncTagFunction
to overload type_
to unused variablesRegisterAsyncOptions
pattern
as StoreFunctionfn
is not functionctx
object
to `Record<string, any>before_post_render
callback
as optional & add JSDocsample without callback https://github.com/hexojs/hexo/blob/8b95bbc722e5c77a7e8125441ed64d2ea3524ac0/test/scripts/tags/blockquote.js#LL8C16-L8C96
ExtendedTagProperty
useful 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