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

Feature: cache busting #382

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions exampleSite/full-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,31 @@ defaultContentLanguage = "en" # Default language to use
noHl = false
style = 'friendly'
tabWidth = 4

[deployment]

[[deployment.targets]]
# An arbitrary name for this target.
#name = "production"

# Amazon Web Services S3; see https://gocloud.dev/howto/blob/#s3
# For S3-compatible endpoints, see https://gocloud.dev/howto/blob/#s3-compatible
#URL = "s3://<Bucket Name>?region=<AWS region>"

# If you are using a CloudFront CDN, deploy will invalidate the cache as needed.
#cloudFrontDistributionID = "<FILL ME IN>"

#[[deployment.matchers]]
# JS, CSS and fonts are either fingerprinted or versioned. Should be cached forever.
#pattern = "^.+\\.(js|css|woff2)$"
#cacheControl = "public, max-age=31536000, immutable"

#[[deployment.matchers]]
# Images in content are fingerprinted and should be cached forever.
#pattern = "^content/.+\\.(jpe?g|webp|png|gif)$"
#cacheControl = "public, max-age=31536000, immutable"

#[[deployment.matchers]]
# All other files by default should never be cached.
#pattern = ".*"
#cacheControl = "public, max-age=0, must-revalidate"
4 changes: 2 additions & 2 deletions layouts/partials/photoswipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
{{ .Site.Params.publicCDN.photoswipeCSS | safeHTML }}
{{ .Site.Params.publicCDN.photoswipeSkin | safeHTML }}
{{ else }}
<link rel="stylesheet" href="{{ "lib/photoswipe/photoswipe.min.css" | relURL }}" />
<link rel="stylesheet" href="{{ "lib/photoswipe/default-skin/default-skin.min.css" | relURL }}" />
<link rel="stylesheet" href="{{ "lib/photoswipe/4.1.2/photoswipe.min.css" | relURL }}" />
<link rel="stylesheet" href="{{ "lib/photoswipe/4.1.2/default-skin/default-skin.min.css" | relURL }}" />
{{ end }}
<!-- these files are loaded in the theme footer
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.3/photoswipe.min.js" integrity="sha256-ePwmChbbvXbsO02lbM3HoHbSHTHFAeChekF1xKJdleo=" crossorigin="anonymous"></script>
Expand Down
13 changes: 7 additions & 6 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{{- end }}

<!-- Jane theme main js -->
{{ $jsMain := resources.Get "js/main.js" | js.Build }}
{{ $secureJS := $jsMain | resources.ExecuteAsTemplate "js/main.js" . | fingerprint }}
{{ $jsMain := resources.Get "js/main.js" | js.Build (dict "targetPath" "js/main.min.js" "minify" true "target" "es6") }}
{{ $secureJS := $jsMain | resources.ExecuteAsTemplate "js/main.min.js" . | fingerprint }}
<script type="text/javascript" src="{{ $secureJS.RelPermalink }}" integrity="{{ $secureJS.Data.Integrity }}" crossorigin="anonymous"></script>
<!-- End -->

Expand Down Expand Up @@ -98,19 +98,20 @@

<!-- Load PhotoSwipe js if the load-photoswipe shortcode has been used -->
{{ if or .Site.Params.photoswipe .Site.Params.fancybox }}
{{- with resources.Get "js/load-photoswipe.js" | js.Build (dict "targetPath" "js/load-photoswipe.min.js" "minify" true "target" "es6") | fingerprint -}}
<script type="text/javascript" src="{{ .RelPermalink }}"></script>
{{- end -}}
{{ if .Site.Params.bootcdn }}
<script src="{{ "js/load-photoswipe.js" | relURL }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe.min.js" integrity="sha256-UplRCs9v4KXVJvVY+p+RSo5Q4ilAUXh7kpjyIP5odyc="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe-ui-default.min.js" integrity="sha256-PWHOlUzc96pMc8ThwRIXPn8yH4NOLu42RQ0b9SpnpFk="
crossorigin="anonymous"></script>
{{ else if .Site.Params.publicCDN.enable }}
<script type="text/javascript" src="{{ "js/load-photoswipe.js" | relURL }}"></script>
{{ .Site.Params.publicCDN.photoswipe | safeHTML }}
{{ .Site.Params.publicCDN.photoswipeUI | safeHTML }}
{{ else }}
<script type="text/javascript" src="{{ "lib/photoswipe/photoswipe.min.js" | relURL}}"></script>
<script type="text/javascript" src="{{ "lib/photoswipe/photoswipe-ui-default.min.js" | relURL}}"></script>
<script type="text/javascript" src="{{ "lib/photoswipe/4.1.2/photoswipe.min.js" | relURL}}"></script>
<script type="text/javascript" src="{{ "lib/photoswipe/4.1.2/photoswipe-ui-default.min.js" | relURL}}"></script>
{{ end }}
{{ end }}

Expand Down
50 changes: 45 additions & 5 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,58 @@
Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
-->
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="{{ "css/hugo-easy-gallery.css" | relURL }}" />{{ end }}
{{- if not ($.Page.Scratch.Get "figurecount") }}
{{- with resources.Get "css/hugo-easy-gallery.css" | minify | fingerprint -}}
<link rel="stylesheet" href="{{ .RelPermalink }}" />
{{- end -}}
{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 -}}

<!-- updated to match Hugo's latest built-in figure shortcode -->
{{- $srcUrl := urls.Parse (.Get "src") -}}
{{- $src := $srcUrl.String -}}
{{- if not $srcUrl.IsAbs -}}
{{- with or (.Page.Resources.Get $srcUrl.Path) (resources.Get $srcUrl.Path) -}}
{{- $resource := . | fingerprint -}}
{{- $src = $resource.RelPermalink -}}
{{- end -}}
{{- end -}}

{{- $linkUrl := urls.Parse (.Get "link") -}}
{{- $link := $linkUrl.String -}}
{{- if not $linkUrl.IsAbs -}}
{{- with or (.Page.Resources.Get $linkUrl.Path) (resources.Get $linkUrl.Path) -}}
{{- $resource := . | fingerprint -}}
{{- $link = $resource.RelPermalink -}}
{{- end -}}
{{- end -}}

{{- $thumbUrl := $linkUrl.String -}}
{{- if not $linkUrl.IsAbs -}}
{{- $thumbUrl = $linkUrl.Path -}}
{{- end -}}
{{ $linkThumb := replaceRE "((\\.[^/]+)?$)" (print (.Get "thumb") "$1") $thumbUrl }}
{{- if not $linkUrl.IsAbs -}}
{{- with or (.Page.Resources.Get $linkThumb) (resources.Get $linkThumb) -}}
{{- $resource := . | fingerprint -}}
{{- $linkThumb = $resource.RelPermalink -}}
{{- end -}}
{{- end -}}

<!-- use either src or link-thumb for thumbnail image -->
{{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
{{- $thumbnail := or $src $linkThumb -}}

<!-- use either link or src for lightbox image -->
{{- $lightbox := or $link $src -}}

<div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}">
<figure {{ with .Get "class" }} class="{{.}}" {{ end }} itemprop="associatedMedia"
itemscope itemtype="http://schema.org/ImageObject" {{ with .Get "width" }}
style="max-width:{{.}}" {{end}}>
<div class="img"{{ if .Parent }} style="background-image: url('{{ print $thumb }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
<img itemprop="thumbnail" src="{{ $thumb }}" {{ with .Get "alt" | default (.Get "caption") }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
<div class="img"{{ if .Parent }} style="background-image: url('{{ print $thumbnail }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
<img itemprop="thumbnail" src="{{ $thumbnail }}" {{ with .Get "alt" | default (.Get "caption") }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
</div>
{{ with .Get "link" | default (.Get "src") }}<a href="{{.}}"{{ with $.Get "target" }} target="{{.}}"{{ end }}{{ with $.Get "rel" }} rel="{{.}}"{{ end }} itemprop="contentUrl"></a>{{ end }}
<a href="{{ $lightbox }}"{{ with $.Get "target" }} target="{{.}}"{{ end }}{{ with $.Get "rel" }} rel="{{.}}"{{ end }} itemprop="contentUrl"></a>
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
<figcaption>
{{- with .Get "title" }}<h4>{{.}}</h4>{{ end }}
Expand Down
6 changes: 5 additions & 1 deletion layouts/shortcodes/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
Documentation and license at https://github.com/liwenyip/hugo-easy-gallery/
-->
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/hugo-easy-gallery.css" />{{ end }}
{{- if not ($.Page.Scratch.Get "figurecount") }}
{{- with resources.Get "css/hugo-easy-gallery.css" | minify | fingerprint -}}
<link rel="stylesheet" href="{{ .RelPermalink }}" />
{{- end -}}
{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 }}
{{ $baseURL := .Site.BaseURL }}
<div class="gallery caption-position-{{ with .Get "caption-position" | default "bottom" }}{{.}}{{end}} caption-effect-{{ with .Get "caption-effect" | default "slide" }}{{.}}{{end}} hover-effect-{{ with .Get "hover-effect" | default "zoom" }}{{.}}{{end}} {{ if ne (.Get "hover-transition") "none" }}hover-transition{{end}}" itemscope itemtype="http://schema.org/ImageGallery">
Expand Down