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

Automatic passthrough copy for files referenced in HTML output files #3552

Closed
zachleat opened this issue Nov 21, 2024 · 9 comments
Closed

Automatic passthrough copy for files referenced in HTML output files #3552

zachleat opened this issue Nov 21, 2024 · 9 comments
Labels
enhancement feature: 🗄 passthrough copy Related to the passthrough file copy feature

Comments

@zachleat
Copy link
Member

zachleat commented Nov 21, 2024

Use the existing HTML transformer architecture and wire it up to passthrough file copy to move any references to assets on the local file system to the output folder automatically.

For example:

  • <img src="my-image.png" alt=""> in template.html copies to _site/template/my-image.png
  • <img src="my-image.png" alt=""> in subdir/template.html copies to _site/subdir/template/my-image.png
  • <img src="deeper/my-image.png" alt=""> in subdir/template.html copies to _site/subdir/template/deeper/my-image.png

These output references would be relative to the template’s outputPath/permalink. This would apply to any URLs processed by https://github.com/11ty/eleventy-posthtml-urls.

Related:

@zachleat zachleat added enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. feature: 🗄 passthrough copy Related to the passthrough file copy feature labels Nov 21, 2024
@zachleat zachleat changed the title Automatic passthrough copy for files referenced in content Automatic passthrough copy for files referenced in HTML output files Nov 21, 2024
@kleinfreund
Copy link
Contributor

People might intentionally put currently invalid references in their source files (e.g. {{ to_be_replaced_external_to_eleventy }}/path/path/file.webp) to fill in with a separate build pipeline, so I would if this could cause any conflicts with such systems? (And to be clear, I made this up just now; I don't have a concrete example)

@zachleat
Copy link
Member Author

zachleat commented Nov 21, 2024

Ah, to be clear this would be an opt-in feature via a configuration API flag for now to avoid conflicts with existing projects. The HTML transformer runs as a postprocessing step currently! It’s used by the Base plugin, the InputPath to URL plugin, the Image transform, among others.

@pepelsbey
Copy link

Yes please! Currently, I’m working around it with the following passthrough config:

config.addPassthroughCopy('src/articles/**/*.!(md|yml)')

And just to clarify: will it work if the resource is referenced in Markdown?

@zachleat
Copy link
Member Author

@pepelsbey yes, absolutely!

@jeremenichelli
Copy link

I wonder what would happen if I have some references in my HTML that I do want but also have some assets that I do some sort of processing on the side, or generated from other npm scripts.

I think this could benefit some obvious parts (like favicons for example), but mess up others. I wonder how I could signal inline if I want to opt-out, because if the user needs to exclude paths, then I don't see the benefit from just configuring the passthroughs you want 🤔

@iamdtms
Copy link

iamdtms commented Nov 21, 2024

What if someone stores image assets in _site/assets/media folder by default? Is it okay? Or it would be rewritten by automatic passthrough copy? Is it a real use case?

@eaton
Copy link

eaton commented Nov 22, 2024

People might intentionally put currently invalid references in their source files (e.g. {{ to_be_replaced_external_to_eleventy }}/path/path/file.webp) to fill in with a separate build pipeline, so I would if this could cause any conflicts with such systems? (And to be clear, I made this up just now; I don't have a concrete example)

Glad to hear this scenario will be accounted for — that's exactly how I structure things with quite a bit of my content; I actually use a dummy protocol on the URLs, replacing it with one value on dev but pointing it to an S3 bucket once it's deployed.

zachleat added a commit that referenced this issue Dec 6, 2024
@zachleat
Copy link
Member Author

zachleat commented Dec 6, 2024

PR for the AutoCopy plugin (with a few preliminary docs) is here: #3573

Feedback welcome!

@zachleat zachleat added this to the Eleventy 3.0.1 milestone Dec 6, 2024
@zachleat zachleat removed the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Dec 6, 2024
@zachleat
Copy link
Member Author

#3573 is shipping with the Html Relative feature for Passthrough File Copy in v3.0.1-alpha.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature: 🗄 passthrough copy Related to the passthrough file copy feature
Projects
None yet
Development

No branches or pull requests

6 participants