Skip to content

Putting CDN base URL for urlPath changes https:// to https:/  #239

@danburzo

Description

@danburzo

I’m trying to prefix the src/srcset attributes of the markup generated by Image.generateHTML with the base URL for a CDN (.e.g. https://mycdn.com/). However, sending that value to parseUrl results in the https:/mycdn.com prefix (with a single slash). I assume this function is the culprit, as Node’s path.join() is not equipped to deal with URLs.

static convertFilePathToUrl(dir, filename) {
    let src = path.join(dir, filename);
    return src.split(path.sep).join("/");
  }

Should we make this function work for the case where dir is a valid URL?


Relevant .eleventy.js snippet:

let metadata = await Image(inputPath, {
	urlPath: `https://dans-cdn.com/img/`,
	// ...
});

const markup = Image.generateHTML(metadata, { ... });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions