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

Add new filter type `theme_inject` #868

Merged
merged 17 commits into from Jul 10, 2019

Conversation

@jiangtj
Copy link
Member

jiangtj commented May 7, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines.
  • Tests for the changes was maked (for bug fixes / features).
    • Muse | Mist have been tested.
    • Pisces | Gemini have been tested.
  • Docs in NexT website have been added / updated (for new features).

PR Type

What kind of change does this PR introduce?

  • Bugfix.
  • Feature.
  • Code style update (formatting, local variables).
  • Refactoring (no functional changes, no api changes).
  • Build related changes.
  • CI related changes.
  • Documentation content changes.
  • Other... Please describe:

What is the current behavior?

Through update custom layout file.

Issue resolved: N/A

What is the new behavior?

Inject custom layout.

I want to write an new theme by myself, based on NexT.
This is a core feature, and want to refactor comment post_meta etc, based on it.

How to use?

For advanced-settings user, you can write code as following. And others can see Breaking Change, if you have compatibility issue.

In scripts:

hexo.extend.filter.register('theme_inject', function(injects) {
  injects.head.file('custom-name', 'source/_data/head.swig', {}, {cache: true});
  injects.sidebar.raw('custom-name', 'Put some in sidebar!');
});

Layout (point: ['head', 'header', 'sidebar', 'postMeta', 'postBodyEnd', 'footer', 'bodyEnd'] )

  • injects.[point].file(name, filePath, [locals], [options]);
  • injects.[point].raw(name, raw, [locals], [options]);

Style (point: ['variable', 'mixin', 'style'] )

  • injects.[point].push(styleFile)

Does this PR introduce a breaking change?

  • Yes.
  • No.

Breaking Change

Remove default custom layout files (layout/_custom/*) and css files.

If you define the content in the default custom layout files, you will need to migrate it into the hexo directory and define it in the custom_file_path.

Example: move theme source/css/_variables/custom.styl to hexo source/_data/variables.styl, and then config as following:

custom_file_path:
  variable: source/_data/variables.styl

DIFF:

- #custom_file_path:
+ custom_file_path:
-   # Default paths: layout/_custom/*
-   # Default path: source/css/_variables/custom.styl	
-   # Default path: source/css/_mixins/custom.styl	
-   # Default path: source/css/_custom/custom.styl
-   #variables: source/_data/variables.styl
-   #mixins: source/_data/mixins.styl	 
-   #styles: source/_data/styles.styl
+   #postMeta: source/_data/post-meta.swig
+   #postBodyEnd: source/_data/post-body-end.swig
+   #footer: source/_data/footer.swig
+   #bodyEnd: source/_data/body-end.swig
+   #variable: source/_data/variables.styl
+   #mixin: source/_data/mixins.styl 
+   #style: source/_data/styles.styl
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@theme-next theme-next deleted a comment May 7, 2019
@jiangtj jiangtj marked this pull request as ready for review May 7, 2019
@stevenjoezhang

This comment has been minimized.

Copy link
Member

stevenjoezhang commented Jul 8, 2019

And docs here...

// P.S. If u want to change this paddings u may set this variables into `source/css/_variables/custom.styl`.

@jiangtj

This comment has been minimized.

Copy link
Member Author

jiangtj commented Jul 8, 2019

And docs here...

// P.S. If u want to change this paddings u may set this variables into `source/css/_variables/custom.styl`.

Why is there a doc here? QAQ

@stevenjoezhang

This comment has been minimized.

Copy link
Member

stevenjoezhang commented Jul 8, 2019

// P.S. If u want to change this paddings u may set this variables into `source/css/_variables/custom.styl`. 

->

// P.S. If u want to change this paddings u may set this variables into `source/_data/variables.styl`. 
@theme-next theme-next deleted a comment Jul 8, 2019
@theme-next theme-next deleted a comment Jul 8, 2019
@stevenjoezhang

This comment has been minimized.

Copy link
Member

stevenjoezhang commented Jul 8, 2019

And... how about a post-end inject point: #835

@jiangtj

This comment has been minimized.

Copy link
Member Author

jiangtj commented Jul 8, 2019

And... how about a post-end inject point: #835

Yeah 😂, In addition, we also can add post-mate after you refactored.

@theme-next theme-next deleted a comment Jul 9, 2019
@theme-next theme-next deleted a comment Jul 9, 2019
@theme-next theme-next deleted a comment Jul 9, 2019
@jiangtj jiangtj merged commit 0764d51 into theme-next:master Jul 10, 2019
5 checks passed
5 checks passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
Mergeable Mergeable Run has been Completed!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details
Feats. / Imprs. / Fixes automation moved this from Reviewer approved to Done Jul 10, 2019
@jiangtj jiangtj deleted the jiangtj:theme-injects branch Jul 10, 2019
@ivan-nginx ivan-nginx referenced this pull request Jul 10, 2019
42 of 72 tasks complete
@stevenjoezhang stevenjoezhang referenced this pull request Jul 11, 2019
6 of 15 tasks complete
tongluyang pushed a commit to tongluyang/hexo-theme-next that referenced this pull request Nov 19, 2019
* Add theme_inject filter

* Fix QA

* Move to merge-config.js and add default injects

* fix config

* Fix QA

* Fix file function args

* Add new injectType

* Fix QA

* Update config file

* Format. remove inject_name

* Format

* Fix QA

* Add a new inject point `footer`

* Add warn log

* Update doc

* Add `postMeta` and `postBodyEnd`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.