GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - posthtml/posthtml-include: Include HTML Plugin

BranchesTags
Open more actions menu

Latest commit

 

History

177 Commits
177 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
lib
lib
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.nycrc
.nycrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
xo.config.js
xo.config.js
 
 

Repository files navigation

Actions Status NPM Coverage

Include Plugin

Install

npm i -D posthtml-include

Usage

const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const include = require('posthtml-include')

const html = readFileSync('index.html')

posthtml([ include({ encoding: 'utf8' }) ])
    .process(html)
    .then((result) => console.log(result.html))

Options

root: Root directory for include. Default process.cwd()

cwd: Current working directory for include. Default process.cwd()

encoding: Default utf-8

posthtmlExpressionsOptions: Array to pass options posthtml-expression

Component options

locals: Object containing any local variables that you want to be accessible inside the include component

Usage

index.html

<html>
<head>
    <title>index.html</title>
</head>
<body>
    <include src="components/button.html" locals='{
        "text": "Button"
    }'></include>
</body>
</html>

components/button.html

<button class="button"><div class="button__text">{{ text }}</div></button>
const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const include = require('posthtml-include')

const html = readFileSync('index.html')

posthtml([ include({ encoding: 'utf8' }) ])
    .process(html)
    .then((result) => console.log(result.html))
<html>
<head>
  <title>index.html</title>
</head>
<body>
  <button class="button">
    <div class="button__text">Button</div>
  </button>
</body>
</html>

You can also pass your locals directly on the <include> content, just drop a JSON there. When doing it, all the "\n" chars will be removed from your data. If you need "\n" chars on your data, you can still use the "locals" attribute.

<include src="components/button.html">
  {
    "text": "Button"
  }
</include>

Note: Also supports multi nesting.

LICENSE

MIT License (MIT)

Copyright (c) PostHTML Ivan Voischev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Include HTML Plugin

Resources

Readme
MIT license
Activity
Custom properties

Stars

204 stars

Watchers

4 watching

Forks

29 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.