Skip to content
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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

dimaslanjaka
Copy link
Contributor

@dimaslanjaka dimaslanjaka commented May 18, 2023

What does it do?

Demo

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

- 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
to easily import between source files
chore(Renderer.register): add overload method types
docs: add JSDoc
@github-actions
Copy link

How to test

git clone -b v7-fix-extend https://github.com/dimaslanjaka/hexo.git
cd hexo
npm install
npm test

@dimaslanjaka dimaslanjaka changed the title V7 fix extend chore: improvement hexo.extend May 18, 2023
chore: cast tag function callback as custom context

useful for determining which post or page source the tag processor is currently processing from
lib/extend/renderer.ts Outdated Show resolved Hide resolved
Comment on lines +44 to +51
/**
* 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
*/
Copy link
Member

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?

Copy link
Contributor Author

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 ?

Comment on lines +16 to +22
if (
typeof data !== 'undefined'
&& !Array.isArray(data)
&& typeof data !== 'boolean'
&& data.lang
&& i18nLanguages.includes(data.lang)
) {
Copy link
Member

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?

Copy link
Contributor Author

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

ive tried:

  • when only validate (data), ts throw error property lang does not exist on Array type
  • when only validate !Array.isArray(data), ts throw error property lang does not exist on boolean type
  • when only validate typeof data === 'object' both errors above will occurs, because Array is also type object

typescript angry without strict validation :(

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

dimaslanjaka and others added 2 commits May 20, 2023 02:36
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>
@stevenjoezhang stevenjoezhang changed the base branch from v7.0.0 to master October 25, 2023 05:02
Copy link

How to test

git clone -b v7-fix-extend https://github.com/dimaslanjaka/hexo.git
cd hexo
npm install
npm test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants