GithubHelp home page GithubHelp logo

Return relative URLs about list-assets HOT 2 OPEN

callumlocke avatar callumlocke commented on May 26, 2024
Return relative URLs

from list-assets.

Comments (2)

callumlocke avatar callumlocke commented on May 26, 2024

Hi! No, that's not what that option is supposed to do. This module never modifies the URLs it finds. It justs lists them.

The rootRelative option means "look for root-relative URLs", and the relative option means "look for page-relative URLs". By default both of these are enabled.

Therefore your example should return nothing (empty array) for that HTML snippet as it only contains root-relative URLs, which you've set to false. It looks like there's a bug, where falsey values get overridden by the default, making it impossible to disable either of those options. I'll have to fix that tomorrow.

Otherwise, how can I remove them in my output?

If all you want to do is remove the initial slash, you could just iterate over the results and strip the initial slash from each URL. Something like:

assets.forEach(asset => {
  asset.url = asset.url.replace(/^\//, '');
});

Why do you want to do that though? I'm curious

from list-assets.

theetrain avatar theetrain commented on May 26, 2024

Thanks for the detailed response. I am using your package with Gulp to find all assets within every html file stream, and then create resource hints for them in each document <head>; you can see it here. Note this snippet:

if (_.find(assets, { 'url': '/' + files[i] })) {
  images += '<link rel="prefetch" href="/' + files[i] + '"/>'
}

I'm using list-assets.html() with the default options, yet I have to prepend a forward slash in the returned collection of URLs. One of the assets in a given html file includes a prepended forward slash already, so I'm unsure what to expect from the returned collection:

<img src="/assets/images/homepage/plugin-oriented.png" alt="Kong plugins"/>

If you identify this as a bug, I'll be happy to help test and document it. Your package has proven useful in spite of this!

from list-assets.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.