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

Add resource.Copy #9313

Closed
regisphilibert opened this issue Dec 22, 2021 · 16 comments · Fixed by #9920
Closed

Add resource.Copy #9313

regisphilibert opened this issue Dec 22, 2021 · 16 comments · Fixed by #9920
Assignees
Milestone

Comments

@regisphilibert
Copy link
Member

regisphilibert commented Dec 22, 2021

Currently only some resource methods can take a "destination" argument.

But many don't, including image transformation.

It might also be useful to rename an asset without doing anything to it, especially when using .GetRemote:

{{ with resources.GetRemote "https://image.com/3093i49039i403i4903i403.jpg" }}
  {{ $img := resources.Copy . "directory/good-looking-name.jpg" }}
  <img src="{{ $img.RelPermalink }}" />
{{ end }}
@bep
Copy link
Member

bep commented Dec 22, 2021

I suspect that we have discussed this before; my conclusion then would be that resources.Copy would be better (the old will still exist under its original name).

@regisphilibert
Copy link
Member Author

Yes I could not find the conversation though.

@regisphilibert regisphilibert changed the title Add resource.Rename Add resource.Copy Dec 22, 2021
@regisphilibert
Copy link
Member Author

regisphilibert commented Dec 22, 2021

But then once you've copied it, are you suppose to "Get" it again from its new location? Or the new asset is returned by the resources.Copy method...

@bep
Copy link
Member

bep commented Dec 22, 2021

Or the new asset is returned by the resources.Copy method...

Yes, you can start using it right away:

{{ $bar := resources.GetRemote "https://example.org/foo.jpg" | resources.Copy "bar.jpg" }}
<img src="{{ $bar.RelPermalink }}">

@regisphilibert
Copy link
Member Author

Damn! How did I miss that! Thanks!

@jmooring
Copy link
Member

What we have now:

{{ $options := dict "targetPath" "css/foo.css" }}
{{ $css := resources.Get "sass/style.scss" | resources.ToCSS $options }}

{{ $options := dict "targetPath" "js/foo.js" }}
{{ $js := resources.Get "js/script.js" | js.Build $options }}

To be somewhat consistent, we could just do the same for .GetRemote:

{{ $options := dict "targetPath" "img/foo.jpg" }}
{{ $img := resources.GetRemote "https://example.org/image.jpg" $options }}

There's an undocumented method to publish a resource, having the same effect as invoking .Permalink or .RelPermalink:

{{ $img := resources.GetRemote "https://example.org/image.jpg" }}
{{ $img.Publish }}

We could also create a resources.Publish method #9303 which would take an optional dictionary:

{{ $options := dict "targetPath" "img/foo.jpg" }}
{{ $img := resources.GetRemote "https://example.org/image.jpg" | resources.Publish $options  }}

I'm not advocating any of these, but it's worth thinking about. Whatever we do I hope it's mostly consistent between global and page resources, regardless of media type (images, css, js, etc.).

@bep
Copy link
Member

bep commented Dec 22, 2021

To be somewhat consistent, we could just do the same for .GetRemote:

Yes, I have thought about that, and maybe we should do that, but there's a non-trivial implementation cost to add the same set of options to every FooResource function we have/add in the future. And I like the Unixy simplicity of this simple line:

{{ $bar := resources.GetRemote "https://example.org/foo.jpg" | resources.Copy "bar.jpg" }}

But I'm not totally 100% sure ... There may be other considerations as to why we maybe should add targetPath to at least the core funcs, e.g. GetRemote/Get.

@bep
Copy link
Member

bep commented Dec 22, 2021

{{ $img := resources.GetRemote "https://example.org/image.jpg" | resources.Publish $options }}

Yea, that could maybe be a better idea; this would allow us to put more options in the future if needed.

@jmooring
Copy link
Member

jmooring commented Jan 6, 2022

@jmooring jmooring reopened this Jan 6, 2022
@jmooring
Copy link
Member

Duplicate of #7406

@jmooring jmooring marked this as a duplicate of #7406 Jan 22, 2022
@regisphilibert
Copy link
Member Author

Yes, you can start using it right away:

Are you sure? I get this when I try your suggestion:

at <resources>: can't evaluate field Copy in type interface {}

@jmooring
Copy link
Member

jmooring commented Feb 3, 2022

Lost in translation...

regis asked:

But then once you've copied it, are you suppose to "Get" it again from its new location? Or the new asset is returned by the resources.Copy method...

bep answered:

Yes, you can start using it right away:

bep didn't mean that the feature is available in the current release.

@regisphilibert
Copy link
Member Author

bep didn't mean that the feature is available in the current release.

I see, on master then?

@jmooring
Copy link
Member

jmooring commented Feb 3, 2022

No. This is still in the proposal stage. Nothing has been implemented.

@rbn30117
Copy link

This would help a lot! Any progress?

@bep bep added Enhancement and removed Proposal labels May 24, 2022
@bep bep self-assigned this May 24, 2022
@bep bep added this to the v0.100.0 milestone May 24, 2022
bep added a commit to bep/hugo that referenced this issue May 24, 2022
Implemented by most Resource objects, but not Page (for now).

Fixes gohugoio#9313
bep added a commit to bep/hugo that referenced this issue May 24, 2022
Implemented by most Resource objects, but not Page (for now).

Fixes gohugoio#9313
bep added a commit to bep/hugo that referenced this issue May 24, 2022
Implemented by most Resource objects, but not Page (for now).

Fixes gohugoio#9313
@bep bep closed this as completed in #9920 May 25, 2022
bep added a commit that referenced this issue May 25, 2022
Implemented by most Resource objects, but not Page (for now).

Fixes #9313
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants