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

EleventyHtmlBasePlugin outputs pathPrefix several times when RSS-plugin is enabled #3547

Open
lsolesen opened this issue Nov 20, 2024 · 2 comments

Comments

@lsolesen
Copy link

lsolesen commented Nov 20, 2024

Operating system

Ubuntu

Eleventy

3.0.0

Describe the bug

I started encountering a strange issue. htmlBase (https://www.11ty.dev/docs/plugins/html-base/) started outputting the base url 3 times instead of just 1, and that - of course - breaks the included stuff on the site.

The error can be seen here:

https://lsolesen.github.io/minimal-mistakes/

image

Crossposted here: https://discord.com/channels/741017160297611315/1308552212125057024

Reproduction steps

Enable the RSS-plugin and enable the EleventyHtmlBasePlugin in your config:

import { EleventyHtmlBasePlugin } from "@11ty/eleventy";

export default function (eleventyConfig) {

  // Make it possible to have the site served in a sub directory
  eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
};

Seen in: https://github.com/lsolesen/minimal-mistakes/blob/11ty/_config/mainConfig.mjs

Building like this:

"build-gh-pages": "ELEVENTY_ENV=production eleventy --pathprefix=/minimal-mistakes/"

And the repos is here:

https://github.com/lsolesen/minimal-mistakes/tree/11ty

  • Hopefully some of you can help me figure out, why this is happening?

Expected behavior

Only write pathPrefix one time.

Reproduction URL

https://lsolesen.github.io/minimal-mistakes/

Screenshots

No response

@lsolesen lsolesen changed the title htmlbase outputs pathPrefix 3 times instead of one EleventyHtmlBasePlugin outputs pathPrefix 3 times instead of one Nov 20, 2024
@lsolesen
Copy link
Author

Even if I outcomment the following line from my config:

 eleventyConfig.addPlugin(EleventyHtmlBasePlugin);

It outputs /minimal-mistakes/ twice when starting the build with --pathprefix=/minimal-mistakes/

By help in the Discord-server I pinpointed this issue down to the RSS-plugin.

I ran the with DEBUG and got this output, which might be helpful.

https://gist.github.com/lsolesen/869545e6225a9acf0c34aea2d297237a

It seems that the RSS-plugin already adds the base plugin.

If I add htmlBasePluginOptions to to options for the RSS-plugin like this:

 eleventyConfig.addPlugin(feedPlugin, {
    type: "rss", // 'atom' or "rss", "json"
    outputPath: "/feed.xml",
    collection: {
      // …
    },
    metadata: {
      // …
    },
    htmlBasePluginOptions: {
      baseHref: '/foo/',
    }
  });

I get this output:

<link href="/minimal-mistakes/foo/minimal-mistakes/feed.xml" type="application/atom+xml" rel="alternate" title="Minimal Mistakes Feed">

So first there is a transformation with --pathprefix, then the RSS plugin runs the transformation with baseHref, and then the transformation is run with --pathprefix again.

@lsolesen lsolesen changed the title EleventyHtmlBasePlugin outputs pathPrefix 3 times instead of one EleventyHtmlBasePlugin outputs pathPrefix several times when RSS-plugin is enabled Nov 24, 2024
@lsolesen
Copy link
Author

Seems to be only the case in watch. Can work around by not adding --pathprefix to watch-commands.

And setting baseHref to "".

  // RSS-feed
  eleventyConfig.addPlugin(feedPlugin, {
    type: "rss", // 'atom' or "rss", "json"
		outputPath: "/feed.xml",
		collection: {
			name: "posts", // iterate over `collections.posts`
			limit: 0,     // 0 means no limit
		},
		metadata: {
			language: "en",
			title: "Blog Title",
			subtitle: "This is a longer description about your blog.",
			base: "https://example.com/",
			author: {
				name: "Your Name",
				email: "", // Optional
			}
		},
    htmlBasePluginOptions: {
      baseHref: '',
    }
  });

Now it works in build-mode with --pathprefix...

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