sheki
January 16, 2015, 7:31am
1
I would like to append a sha1 to the css file everytime I modify it, so that I am not served an old version by a cdn.
the way I would like to do this is to pass the sha1 as an environment variable and use that in generating the HTML in header template.
Can some one tell me how can I access the environment variable in the template.
bep
January 16, 2015, 1:42pm
2
Not currently possible, I think.
But a template function that wraps os.Getenv would be easy to add I guess. If you know Go (or want to learn, it’s fun!), a PR might be the fastest approach.
See:
// Copyright 2017-present The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tpl
import (
"io"
"time"
"text/template/parse"
This file has been truncated. show original
sheki
January 16, 2015, 6:06pm
3
I don’t mind adding this. I have been looking and I don’t understand the codebase yet.
So I have a few questions
Why should I add the method to the Template ? Is is object wrapped by a template before it is passed down ?
I would think the method would need to be present on Site/Page/Node to be available in the template. am I wrong ?
bep
January 16, 2015, 6:26pm
4
This is, in my head, a general purpose template function, not connected to Page or anything.
See:
If you look at the init() in template.go - this is where the custom Hugo template functions are made available to the templates via the funcMap.
For what I understand, using HUGO_TITLE
as an environment variable will work because there is a title
field in the configuration file.
It does not seem to work with unknown configuration keys: I tried HUGO_PARAMS_SOMETHING=1
and it does not seem to be picked up in the templates.
However the getenv
function can be used in the templates to collect a random environment variable. Combined with default
, it does the job well.
1 Like
I am new to hugo, here is the syntax
<script type=“text/javascript” src=’/app/global.bundle.{{getenv “HUGO_HASHNEW”}}.js’></script>
1 Like
ju52
December 3, 2018, 9:36am
7
With CDN you have to change the file names only for new files!
You can use this for CSS and JS!