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
Merged

Conversation

jiangtj
Copy link
Member

@jiangtj 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
stevenjoezhang
stevenjoezhang previously approved these changes May 7, 2019
@theme-next theme-next deleted a comment Jul 8, 2019
@jiangtj jiangtj requested a review from 1v9 July 8, 2019 03:30
@stevenjoezhang
Copy link
Contributor

And docs here...

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

@jiangtj
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
Copy link
Contributor

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
Copy link
Contributor

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

@jiangtj
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
@jiangtj jiangtj deleted the theme-injects branch July 10, 2019 04:50
@ivan-nginx ivan-nginx mentioned this pull request Jul 10, 2019
72 tasks
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants