Skip to content

generates a css-friendly page identifier for easy css scoping

License

Notifications You must be signed in to change notification settings

static-dev/spike-page-id

Repository files navigation

Spike Page ID

npm tests dependencies coverage

Generates a css-friendly page identifier from a webpack loader context

Note: This project is in early development, and versioning is a little different. Read this for more details.

Installation

npm install spike-page-id -S

Note: This project is compatible with node v6+ only

Usage

In your spike config:

const htmlStandards = require('reshape-standard')
const pageId = require('spike-page-id')

module.exports = {
  // other config…
  reshape: (ctx) => {
    return htmlStandards({
      locals: { pageId: pageId(ctx) }
    })
  }
}

Now in your html, let's say it's called index.sgr:

html
  head
    title My page
  body(id='{{ pageId }}')
    p hello world

This will render something like:

<html>
  <head>
    <title>My page</title>
  </head>
  <body id='index'>
    <p>hello world</p>
  </body>
</html>

If you are working with a page that's nested inside other folders, it will include all folders relative to the project root, separated by a hyphen. So for example:

  • views/index.sgr > index
  • views/posts/welcome.sgr > posts-welcome

…and that's about it!

License & Contributing

About

generates a css-friendly page identifier for easy css scoping

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •