npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pug-html-info-loader

v1.0.6

Published

Pug to html loader for webpack with pathInfo added as local variables

Downloads

11

Readme

Pug HTML loader for webpack with pathInfo added as local variables

This is a 【customized version】 of the original pug-html-loader.
Path information can be automatically set as local variables.

If you want to set local meta information for each pug file, It will be possible by data together with the file path as a JSON key.

Installation

npm i -D pug-html-info-loader

add options

  • basePath (optional)
    Base directory for public path.
    【 default 】 → node.env.pwd

added local variables

ex 【 src/baseDir/first/second/page.pug 】 & 【 config.basePath = baseDir's path 】

added pathInfo

  • 【 pathInfo.pug 】 → first/second/page.pug
  • 【 pathInfo.html 】 → first/second/page.html
  • 【 pathInfo.dir 】 → first/second/
  • 【 pathInfo.parent 】 → second
  • 【 pathInfo.basename 】 → page
  • 【 pathInfo.htmlname 】 → page.html
  • 【 pathInfo.pugname 】 → page.pug

If config.basePath is not set, it will be the path from node.env.pwd.

added pathInfo

  • 【 pathInfo.pug 】 → src/baseDir/first/second/page.pug
  • 【 pathInfo.html 】 → src/baseDir/first/second/page.html
  • 【 pathInfo.dir 】 → src/baseDir/first/second/

meta data example

meta.json

{
  "global": {
    "title": "global title",
    "description": "global description",
    "keywords": "global keywords",
    "og_url": "global og_url",
    "og_title": "global og_title",
    "og_image": "global og_image",
    "og_description": "global og_description",
    "bodyClass": "global bodyClass"
  },
  "local": {
    "path/to/page1.html": {
      "title": "Page1 title",
      "description": "Page1 description",
      "keywords": "Page1 keywords",
      "og_url": "Page1 og_url",
      "og_title": "Page1 og_title",
      "og_image": "Page1 og_image",
      "og_description": "Page1 og_description",
      "bodyClass": "Page1 bodyClass"
    },
    "path/to/page2.html": {
      "title": "Page2 title",
      "description": "Page2 description",
      "keywords": "Page2 keywords",
      "og_url": "Page2 og_url",
      "og_title": "Page2 og_title",
      "og_image": "Page2 og_image",
      "og_description": "Page2 og_description",
      "bodyClass": "Page2 bodyClass"
    }
  }
}

webpack.config

const path = require('path')
const metadata = require('./meta.json')

module.exports = {
  // your config settings ...
  module: [{
    // your modules...
    rules: [
      {
      test: /\.pug/,
      use: [
        'html-loader',
        {
          loader: 'pug-html-info-loader',
          options: {
            data: {
              globalConf:metadata['global'],
              localConf :metadata['local']
            }, // set of data to pass to the pug render.
            basePath: path.resolve(__dirname, 'src')
            // base folder path for local variables.
          }
        }
      ]
    }]
  }]
};

localfile.pug

- var config = localConf[pathInfo.html] ? localConf[pathInfo.html] : globalConf;
head
  title=config.title
  meta(name='description', content=config.description)
  meta(name='keywords', content=config.keywords)

  meta(property='og:title', content=config.og_title)
  meta(property='og:description', content=config.og_description)
  meta(property='og:url', content=config.og_url)
  meta(property='og:image', content=config.og_image)

body(class=config.bodyClass)

  p this page path → #{pathiInfo.html} 

ex

  • 【 path/to/page1.pug 】 → config.title = page1.title
  • 【 path/to/page3.pug 】 → config.title = global.title

License

MIT (http://www.opensource.org/licenses/mit-license.php)