Skip to content

Prefixed URL attributes mapping to config #2

@stevenvachon

Description

@stevenvachon
<link cdn-href="lib.css">
<link npm-href="lib.css">
<link bower-href="lib.css">
<link domain-href="index.css">

<img cdn-src="img.png" cdn-srcset="img2.png 2x">


<script cdn-src="lib.js"></script>
<script npm-src="lib.css"></script>
<script bower-src="lib.css"></script>
<script domain-src="index.js"></script>

(we could also silently support data-* [ex. <img data-cdn-src="img.png">] for spec-compliance)

const options = {
  prefixes: {
    cdn: 'https://mycdn.com',
    npm: 'node_modules',
    bower: 'bower_components',
    domain: 'https://mysite.com'
  }
}

posthtml([ url(options) ]).process(html).then(result => console.log(result.html))

compiling to:

<link href="https://mycdn.com/lib.css">
<link href="node_modules/lib.css">
<link href="bower_components/lib.css">
<link href="https://mysite.com/index.css">

<img src="https://mycdn.com/img.png" srcset="https://mycdn.com/img2.png 2x">


<script src="https://mycdn.com/lib.js"></script>
<script src="node_modules/lib.css"></script>
<script src="bower_components/lib.css"></script>
<script src="https://mysite.com/index.js"></script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions