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

Open
robole opened this issue May 2, 2024 · 0 comments
Open

Access to serverOptions in eleventy config #3273

robole opened this issue May 2, 2024 · 0 comments

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant