Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to serverOptions in eleventy config #3273

Closed
robole opened this issue May 2, 2024 · 1 comment
Closed

Access to serverOptions in eleventy config #3273

robole opened this issue May 2, 2024 · 1 comment
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

Comments

@robole
Copy link

robole commented May 2, 2024

Is your feature request related to a problem? Please describe.

I created a absoluteurl filter that converts a relative URL or an absolute path to an absolute URL. I would like it to behave like Jekyll's absolute_url filter. It prepends a baseurl value to the input.

The filter should do the following:

Since I cannot obtain the server host name and port, I am unable to do this for dev mode. Instead I return the input url.

Describe the solution you'd like

Access the serverOptions object with details about server.

Describe alternatives you've considered

I tried to use eleventyConfig.getMergingConfigObject().serverOptions in the eleventy config file, however it is empty. I guess that this could be because the server is not initiated yet. Is this a timing issue?

Additional context

This is the current implementation:

function absoluteUrl(url, baseUrl, production = true) {
  if (baseUrl === undefined || baseUrl === null) {
    throw new Error(
      `absoluteUrl - The baseUrl parameter is missing.`
    );
  }

  let absUrl = url;

  if (production) {
    try {
      absUrl = new URL(url, baseUrl).toString();
    } catch (e) {
      debug(
        "Trying to convert %o to be an absolute url with baseUrl %o and failed, returning: %o (invalid url)",
        url,
        baseUrl,
        url
      );
    }
  }

  return absUrl;
}
@zachleat zachleat added the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Jun 19, 2024
@zachleat
Copy link
Member

A bit of internal complexity here as the dev server currently starts after the build.

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!

@zachleat zachleat closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.
Projects
None yet
Development

No branches or pull requests

2 participants