-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Adds html-relative
Passthrough Copy mode for relative asset references in HTML #3552
#3573
Conversation
I have a few questions: First, in your example with Second, why make this a plugin? I understand wanting to maintain backwards compatibility for the existing passthrough copy function, but couldn't you achieve that by adding options to the passthrough copy function with default values that result in the existing behavior? I feel like having two different ways to copy static assets is going to be a little confusing, especially if the idea is that the built-in one is the one with which people struggle, and the one people probably want because it's more efficient and convenient is a plugin you have to import and add. Personally, I also just find the built-in plugins annoying because it means I have to have extra import statements at the top of my config file for something that is included when I Third, when you say "AutoCopy may be worse when you're not using HTML", does that mean when I'm using Markdown? |
You can write to JSON also. |
Yep! Alternatively there is a
Fair point! Let me think about it a bit—it might be more ergonomic to extend the
Anything that outputs to HTML is handled by this method (Markdown, Nunjucks, Liquid, 11ty.js, etc etc)! Updated the comment above: |
Per @darthmall’s excellent feedback I’ve reworked the API to use I love this change, thanks for the idea Evan! (Still open to feedback here!) A few other naming ideas:
|
I finally got around to testing this and had been banging my head on it for like 30 minutes before I thought to check back on this thread and see you're going in a different direction 😅 Couldn't figure out why
|
auto
Passthrough Copy mode for relative asset references in HTML #3552
auto
Passthrough Copy mode for relative asset references in HTML #3552html-relative
Passthrough Copy mode for relative asset references in HTML #3552
Renaming this from AutoCopy to HtmlRelativeCopy (via |
Oh no! I’m sorry!
I took your suggestion and settled on the |
Shipping with v3.0.1-alpha.1 |
Works great with emulated passthrough copy, too: https://www.11ty.dev/docs/copy/#emulate-passthrough-copy-during-serve
Why (and why not) use this?
Compared with using
eleventyConfig.addPassthroughCopy('content/**/*.mp4')
,HtmlRelativeCopy is better because:
permalink
) seamlessly without requiring any changes to source content.<video src="video.mp4">
ontemplate.njk
will copy to_site/template/video.mp4
alongside_site/template/index.html
<video src="assets/video.mp4">
onsubdir/template.njk
will copy to_site/subdir/template/assets/video.mp4
alongside_site/subdir/template/index.html
HtmlRelativeCopy may be worse when:
you aren’t using HTMLif your template is not writing an HTML file in output@11ty/posthtml-urls
: https://github.com/11ty/eleventy-posthtml-urls/blob/d3097f44868737627555ebec622b029d7c0b1ab3/lib/defaultOptions.js#L10-L35Restrictions
Some other differences from the usual
eleventyConfig.addPassthroughCopy
:dot: false
recursive-copy option)Full options list
copyOptions
matches the additional options passed to therecursive-copy
package, see https://www.11ty.dev/docs/copy/#advanced-optionscopyOptions.overwrite: false
to skip overwrite if a file already exists in the output directory.