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

Migration from PostHTML Modules/Include/Extends plugins #16

Closed
thewebartisan7 opened this issue Oct 21, 2022 · 0 comments
Closed

Migration from PostHTML Modules/Include/Extends plugins #16

thewebartisan7 opened this issue Oct 21, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@thewebartisan7
Copy link
Collaborator

thewebartisan7 commented Oct 21, 2022

PostHTML Include

PostHTML Include plugin can work when passed via options.plugins like below example:

require("posthtml-component")({
      root: "./src",
      folders: ["components", "layouts"],
      plugins: [
        require("posthtml-include")({
          encoding: "utf8",
          root: "./src"
        }),
      ]
    }),

PostHTML Modules

At the moment doesn't work when nested inside PostHTML Components plugin since it use tree.match and even trying with something like PostHTML Include is doing here https://github.com/posthtml/posthtml-include/blob/master/lib/index.js#L16 doesn't work. But a workaround is to use PostHTML Components custom tag and attributes like below:

    require("posthtml-component")({
      root: "./src",
      folders: ["components", "layouts"],
      tag: 'module',
      attribute: 'href',
      yield: 'content'
      plugins: [
        require("posthtml-include")({
          encoding: "utf8",
          root: "./src/www/posthtml-templates/"
        }),
      ]
    }),

NOTE: If you change <yield> tag to <content> to support your existing code, then you need to use it always. Maybe you can just replace all <content> with <yield> and it should works fine.

PostHTML Extends

Not yet tested.

Whole plugins array

This is my current array of plugins passed to PostHTML. The PostHTML Component plugin works in my case only when loaded after PostHTML Extends/Modules/Include.

[
    require("posthtml-extend")({
      encoding: "utf8",
      root: "./src",
      strict: false
    }),

    require("posthtml-include")({
      encoding: "utf8",
      root: "./src"
    }),

    require("posthtml-modules")({
      encoding: "utf8",
      root: "./src",
      tag: "component",
      attribute: "path",
      attributeAsLocals: true
    }),

    require("posthtml-expressions")({
      removeScriptLocals: true, 
      strictMode: false
    }),

    require("posthtml-component")({
      root: "./src/www/posthtml-templates",
      folders: ["components", "layouts", "partials", "docs/components", "docs/layouts", "docs/partials"],
      tag: 'component', // For posthtml-modules
      attribute: 'path', // For posthtml-modules
      plugins: [
        require("posthtml-include")({
          encoding: "utf8",
          root: "./src"
        }),
      ]
    }),
   
   // ... others here...
  ],
@thewebartisan7 thewebartisan7 added the documentation Improvements or additions to documentation label Oct 21, 2022
@thewebartisan7 thewebartisan7 changed the title Migration from PostHTML Modules/Include/Extends plugin Migration from PostHTML Modules/Include/Extends plugins Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant