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

Allow global ignore of some resource trans. methods per environment. #4981

Closed
regisphilibert opened this issue Jul 21, 2018 · 8 comments
Closed

Comments

@regisphilibert
Copy link
Member

regisphilibert commented Jul 21, 2018

It is good practice to test .IsServer before applying resource.Minify and resources.Fingerprint to a resource.

Systematically calling a condition for each resource processed may become very tedious when you start using Hugo Pipes's asset transform (ex image process) in a lot of different location in your templates or when most of your templates are inherited from a theme.

I'm proposing (more like enquiring for feasibility) an alternative: To add a new config setting allowing the ignoring of certain asset transformation methods. This way we can safely .Fingerprint and/or .Whatever our assets without having to test the environement.

# config.yaml
ignoreAssetTransform:
  - fingerprint
  - minify
# config.prod.yaml
ignoreAssetTransform: false
@bep
Copy link
Member

bep commented Jul 21, 2018

Hmm... I guess we at some point will add some "site config globals" for the different transformations (SCSS etc.), but t.this was not what I had in mind. What I really like with all of this is the what you see is what you get. Without having to hunt down some nested config in some XML files to debug why fingerprinting suddenly stopped working.

@regisphilibert
Copy link
Member Author

regisphilibert commented Jul 21, 2018

Without having to hunt down some nested config in some XML files to debug why fingerprinting suddenly stopped working.

What XML file? I'm talking about a project only configuration parameter (you make a point, themes should not be able to set it).

Let me push my point a bit here.

Currently an {{ if .IsServer / else }} statement is needed for every "permalinked" resource. Meaning:

  1. As a theme user you cannot force fingerprinting on hugo-sever for temporary testing.
  2. As a theme user you cannot rule out fingerprinting on a non-hugo-server environment, say staging.
  3. As a project/theme coder, you cannot do 2. without updating your if with an environment variable or config parameter unique to your setup.
  4. But most importantly Hugo Pipes loses all the one liner jazz it first inspired :)

Lastly, I would add that this fingerprinting on/off switch per environment is almost systematic among Gulp|Grunt|Webpack users and would be a welcome addition to their Hugo built-in counterpart: Hugo Pipes.

@bep
Copy link
Member

bep commented Jul 21, 2018

What XML file? I

I was talking about the "Gulp XML files", not Hugo.

You can use some other flag than IsServer which would solve most of your concerns. What you want is doable, of course, but I'm not totally convinced. This will look prettier once Go 1.11 is out and we can re-assign variables, and the "one-liner" is only beautiful if I can look at it and tell exactly what it does.

@bep
Copy link
Member

bep commented Jul 21, 2018

... but this isn't set in stone, but I feel that this need to linger a little...

@regisphilibert
Copy link
Member Author

regisphilibert commented Jul 21, 2018

and the "one-liner" is only beautiful if I can look at it and tell exactly what it does

Sure some users may spend some time wondering why their assets are not fingerprinted, but I don't think we should worry about the tribulations of people not aware of their project's configuration settings. They'll find the problem, slap their forehead and quietly move on. Like I always do when being clueless with my Gruntfile.js.

I think a global, per environment fingerprinting / minifying is something people will want to deal with easily and with the minimum template files editing involved. I am not sure the current if / else solution offers that yet, and this is a modest proposal for improvement.

I feel that this need to linger a little...

Of course.

@regisphilibert
Copy link
Member Author

I build this kind of partials which systematically needs .Site in its context...

<img src="{{ partial "asset" (dict "site" .Site "asset" "images/logo.svg") }}">
{{- $site := .site -}}
{{- with resources.Get .asset -}}
	{{- if $site.IsServer -}}
		{{- .Permalink -}}
	{{- else }}
		{{- (. | fingerprint).Permalink -}}
	{{- end -}}
{{- end -}}

And start daydreaming about this issue :)

@stale
Copy link

stale bot commented Dec 20, 2018

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 20, 2018
@stale stale bot closed this as completed Jan 20, 2019
@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 Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants