Skip to content

Commit

Permalink
Set age for cached remote resources
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Maddaus <[email protected]>
  • Loading branch information
IanMadd committed Nov 10, 2023
1 parent 09c744d commit 8088df6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
21 changes: 21 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ notAlternative = true
endLevel = 4
ordered = false
startLevel = 2

[caches]
[caches.assets]
dir = ':resourceDir/_gen'
maxAge = -1
[caches.getcsv]
dir = ':cacheDir/:project'
maxAge = -1
[caches.getjson]
dir = ':cacheDir/:project'
maxAge = "1h"
[caches.getresource]
dir = ':cacheDir/:project'
maxAge = "1h"
[caches.images]
dir = ':resourceDir/_gen'
maxAge = -1
[caches.modules]
dir = ':cacheDir/modules'
maxAge = -1

29 changes: 26 additions & 3 deletions themes/docs-new/layouts/_default/release_notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
{{ if or (hugo.IsProduction) ( eq hugo.Environment "staging") ( eq hugo.Environment "branch-deploy")}}
{{ with $product := $.Param "release_notes" }}


{{- $versionsUrl := "" -}}
{{- if eq $product "automate" -}}
{{- $versionsUrl = "https://packages.chef.io/releases/current/automate.json"}}
Expand All @@ -23,7 +22,26 @@
{{- $versionsUrl = (print "https://omnitruck.chef.io/stable/" $product "/versions/all") -}}
{{- end -}}

{{- $versions := getJSON $versionsUrl -}}
{{ $versions := "" }}

{{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }}
{{ $cacheKey := print $versionsUrl (now.Format "20060102") (div now.Hour 6) | md5 }}
{{ $opts := dict "headers" $headers "key" $cacheKey }}

{{- if hasPrefix $versionsUrl "https://" -}}
{{- with resources.GetRemote $versionsUrl $opts -}}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $unmarshalOpts := dict "delimiter" "," }}
{{ $versions = . | transform.Unmarshal $unmarshalOpts }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $versionsUrl }}
{{ end }}
{{ else }}
{{ $versions = getJSON $versionsUrl }}
{{ end }}

{{/* We have a "current" version of Infra Client that they want release notes for on the Client release notes page. */}}
{{/* This allows us to add current release version numbers of Client to the list of version numbers */}}
Expand Down Expand Up @@ -102,7 +120,12 @@ <h2 id="{{ $version }}">{{ $fullName }} {{ $version }}</h2>
<p><i>Released on {{ time.Format "January 2, 2006" .release_date }}</i></p>
{{- end -}}

{{- $remoteResponse := resources.GetRemote $mdUrl (dict "headers" (dict "Cache-Control" "no-cache" "Connection" "keep-alive")) -}}
{{/* Define GetRemote options */}}
{{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }}
{{ $cacheKey := print $mdUrl (now.Format "20060102") (div now.Hour 6) | md5 }}
{{ $opts := dict "headers" $headers "key" $cacheKey }}

{{- $remoteResponse := resources.GetRemote $mdUrl $opts -}}

{{- if eq $remoteResponse nil -}}
<p>This release does not have any release notes.</p>
Expand Down
21 changes: 20 additions & 1 deletion themes/docs-new/layouts/partials/release_notes_toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,26 @@
{{ $versionsUrl = (print "https://omnitruck.chef.io/stable/" $product "/versions/all") }}
{{ end }}

{{ $versions := getJSON $versionsUrl }}
{{ $versions := "" }}

{{ $headers := dict "Cache-Control" "no-cache" "Connection" "keep-alive" }}
{{ $cacheKey := print $versionsUrl (now.Format "20060102") (div now.Hour 6) | md5 }}
{{ $opts := dict "headers" $headers "key" $cacheKey }}

{{- if hasPrefix $versionsUrl "https://" -}}
{{- with resources.GetRemote $versionsUrl $opts -}}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $unmarshalOpts := dict "delimiter" "," }}
{{ $versions = . | transform.Unmarshal $unmarshalOpts }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $versionsUrl }}
{{ end }}
{{ else }}
{{ $versions = getJSON $versionsUrl }}
{{ end }}

{{/* We have a current version of Infra Client that they want release notes for on the Client release notes page. */}}
{{/* This allows us to add current release version numbers of Client to the list of version numbers */}}
Expand Down

0 comments on commit 8088df6

Please sign in to comment.