Skip to content

Prefixed URL attributes mapping to config #2

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>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions