11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.3k stars 496 forks source link

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

Open lsolesen opened 1 week ago

lsolesen commented 1 week ago

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

Expected behavior

Only write pathPrefix one time.

Reproduction URL

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

Screenshots

No response

lsolesen commented 5 days ago

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 commented 5 days ago

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...