Skip to content

Providing a custom domain for all assets #1808

Answered by pdehaan
a-type asked this question in Q&A
Discussion options

You must be logged in to vote

An easy solution might be a custom filter which wraps the JavaScript URL object so you can easily prefix a custom domain on a per-asset basis.

// .eleventy.js
const env = require("./src/_data/env");

module.exports = (eleventyConfig) => {
  eleventyConfig.addFilter("absUrl", (url="", base=env.PUBLIC_URL) => new URL(url, base).href);
  // ...
  return {...};
};
// ./src/_data/env.js
module.exports = {
  PUBLIC_URL: process.env.PUBLIC_URL || "https://landing.thing.com"
};
// ./src/_data/books.js
module.exports = [
  {title: "Cat in a Hat", tags: ["cat", "hat"], logo: "/img/cat.png"},
  {title: "Dog in a Coat", tags: ["dog", "coat"], logo: "/img/dog.png"},
];

USAGE

<img src="{{ book.logo | u…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@a-type
Comment options

Answer selected by a-type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants