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

Feature: When execute filter's callback, add new parameters. #4744

Closed
wants to merge 1 commit into from
Closed

Feature: When execute filter's callback, add new parameters. #4744

wants to merge 1 commit into from

Conversation

tcatche
Copy link
Contributor

@tcatche tcatche commented Jul 22, 2021

What does it do?

When a callback to a registered filter is executed, the parameters passed to the filter are those that have been processed by other filters. The filter executed later may be missing related information.

For example, the internal hexo filter(lib\plugins\filter\post_permalink.js) get Post Object as parameter.
After this filter run, return a permalink and dismisses other Post properties.
And then, other filter after this will lose Post info and only get a permalink parameter without any Post info:

// before
hexo.extend.filter.register('post_permalink', function(data){
  // only `2021/07/22/hello` without other info about the post.
  console.log(data); 
  return data;
});

The code try to solve this, give a new params to filter callback, The filter can get the origin info before other filter process:

// after
hexo.extend.filter.register('post_permalink', function(data, post){
// get more params.
  console.log(data, post); 
  return data;
});

How to test

git clone -b BRANCH https://github.com/USER/hexo.git
cd hexo
npm install
npm test

Screenshots

Pull request tasks

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

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0009%) to 98.283% when pulling 005a3d4 on tcatche:feature/filter_add_params into 9e3360a on hexojs:master.

lib/extend/filter.js Show resolved Hide resolved
@github-actions github-actions bot added the stale label Nov 28, 2021
@github-actions github-actions bot closed this Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants