mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Merge commit 'b3d87dd0fd746f07f9afa6e6a2969aea41da6a38'
This commit is contained in:
23
docs/layouts/_partials/helpers/debug/list-item-metadata.html
Normal file
23
docs/layouts/_partials/helpers/debug/list-item-metadata.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<span class="h-3"></span>
|
||||
<table class="mt-auto">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="align-top text-red-700">weight:</td>
|
||||
<td class="align-top pl-2 w-full">
|
||||
{{ .Weight }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="align-top text-red-700">keywords:</td>
|
||||
<td class="align-top pl-2">
|
||||
{{ delimit (or .Keywords "") ", " }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="align-top text-red-700">categories:</td>
|
||||
<td class="align-top pl-2">
|
||||
{{ delimit (or .Params.categories "") ", " }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
25
docs/layouts/_partials/helpers/funcs/color-from-string.html
Normal file
25
docs/layouts/_partials/helpers/funcs/color-from-string.html
Normal file
@@ -0,0 +1,25 @@
|
||||
{{ $colors := slice "slate" "green" "cyan" "blue" }}
|
||||
{{ with .single }}
|
||||
{{ $colors = slice . }}
|
||||
{{ end }}
|
||||
|
||||
{{ $shades := slice 300 400 500 }}
|
||||
{{ if not .dark }}
|
||||
{{ $shades = slice 700 800 }}
|
||||
{{ end }}
|
||||
{{ $hash := (hash.FNV32a .text) }}
|
||||
{{ $i := mod $hash (len $colors) }}
|
||||
{{ $j := mod $hash (len $shades) }}
|
||||
{{ $color := index $colors $i }}
|
||||
{{ $shade1 := index $shades $j }}
|
||||
{{ $shade2 := 0 }}
|
||||
{{ $shade3 := 0 }}
|
||||
{{ if gt $shade1 500 }}
|
||||
{{ $shade2 = math.Min (sub $shade1 500) 100 | int }}
|
||||
{{ $shade3 = sub $shade1 100 }}
|
||||
{{ else }}
|
||||
{{ $shade2 = math.Max (add $shade1 500) 700 | int }}
|
||||
{{ $shade3 = add $shade1 200 }}
|
||||
{{ end }}
|
||||
{{ $res := dict "color" $color "shade1" $shade1 "shade2" $shade2 "shade3" $shade3 }}
|
||||
{{ return $res }}
|
28
docs/layouts/_partials/helpers/funcs/get-github-info.html
Normal file
28
docs/layouts/_partials/helpers/funcs/get-github-info.html
Normal file
@@ -0,0 +1,28 @@
|
||||
{{ $url := "https://api.github.com/repos/gohugoio/hugo" }}
|
||||
{{ $cacheKey := print $url (now.Format "2006-01-02") }}
|
||||
{{ $headers := dict }}
|
||||
{{ with os.Getenv "HUGO_GH_TOKEN" }}
|
||||
{{ $headers = dict "Authorization" (printf "Bearer %s" .) }}
|
||||
{{ end }}
|
||||
{{ $opts := dict "headers" $headers "key" $cacheKey }}
|
||||
{{ $githubRepoInfo := dict }}
|
||||
{{ with try (resources.GetRemote $url $opts) }}
|
||||
{{ with .Err }}
|
||||
{{ warnf "Failed to get GitHub repo info: %s" . }}
|
||||
{{ else with (.Value | transform.Unmarshal) }}
|
||||
{{ $githubRepoInfo = dict
|
||||
"html_url" .html_url
|
||||
"stargazers_url" .stargazers_url
|
||||
"watchers_count" .watchers_count
|
||||
"stargazers_count" .stargazers_count
|
||||
"forks_count" .forks_count
|
||||
"contributors_url" .contributors_url
|
||||
"releases_url" .releases_url
|
||||
"forks_count" .forks_count
|
||||
}}
|
||||
{{ else }}
|
||||
{{ errorf "Unable to get remote resource %q" $url }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $githubRepoInfo }}
|
24
docs/layouts/_partials/helpers/funcs/get-remote-data.html
Normal file
24
docs/layouts/_partials/helpers/funcs/get-remote-data.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{{/* prettier-ignore-start */ -}}
|
||||
{{/*
|
||||
Parses the serialized data from the given URL and returns a map or an array.
|
||||
|
||||
Supports CSV, JSON, TOML, YAML, and XML.
|
||||
|
||||
@param {string} . The URL from which to retrieve the serialized data.
|
||||
@returns {any}
|
||||
|
||||
@example {{ partial "get-remote-data.html" "https://example.org/foo.json" }}
|
||||
*/}}
|
||||
{{/* prettier-ignore-end */ -}}
|
||||
{{ $url := . }}
|
||||
{{ $data := dict }}
|
||||
{{ with try (resources.GetRemote $url) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "%s" . }}
|
||||
{{ else with .Value }}
|
||||
{{ $data = .Content | transform.Unmarshal }}
|
||||
{{ else }}
|
||||
{{ errorf "Unable to get remote resource %q" $url }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ return $data }}
|
27
docs/layouts/_partials/helpers/gtag.html
Normal file
27
docs/layouts/_partials/helpers/gtag.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{{ with site.Config.Services.GoogleAnalytics.ID }}
|
||||
<script
|
||||
async
|
||||
src="https://www.googletagmanager.com/gtag/js?id={{ . }}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
{{ $site := site.BaseURL | replaceRE "^https?://(www\\.)?([^/]+).*" "$2" }}
|
||||
gtag('config', '{{ . }}', {'anonymize_ip': true, 'dimension1': '{{ $site }}', 'dimension2': '{{ getenv "BRANCH" }}'});
|
||||
|
||||
/**
|
||||
* Function that tracks a click on an outbound link in Analytics.
|
||||
* Setting the transport method to 'beacon' lets the hit be sent
|
||||
* using 'navigator.sendBeacon' in browser that support it.
|
||||
*/
|
||||
var trackOutboundLink = function(id, url) {
|
||||
gtag('event', 'click', {
|
||||
'event_category': 'outbound',
|
||||
'event_label': id,
|
||||
'transport_type': 'beacon'
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
{{ end }}
|
28
docs/layouts/_partials/helpers/linkcss.html
Normal file
28
docs/layouts/_partials/helpers/linkcss.html
Normal file
@@ -0,0 +1,28 @@
|
||||
{{ $r := .r }}
|
||||
{{ $attr := .attributes | default dict }}
|
||||
|
||||
{{ if hugo.IsDevelopment }}
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ $r.RelPermalink }}"
|
||||
{{ template `render-attributes` $attr }}>
|
||||
{{ else }}
|
||||
{{ with $r | minify | fingerprint }}
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ .RelPermalink }}"
|
||||
integrity="{{ .Data.Integrity }}"
|
||||
crossorigin="anonymous"
|
||||
{{ template `render-attributes` $attr }}>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "render-attributes" }}
|
||||
{{- range $k, $v := . -}}
|
||||
{{- if $v -}}
|
||||
{{- printf ` %s=%q` $k $v | safeHTMLAttr -}}
|
||||
{{- else -}}
|
||||
{{- printf ` %s` $k | safeHTMLAttr -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ end }}
|
15
docs/layouts/_partials/helpers/linkjs.html
Normal file
15
docs/layouts/_partials/helpers/linkjs.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{{ $r := .r }}
|
||||
{{ $attr := .attributes | default dict }}
|
||||
{{ if hugo.IsDevelopment }}
|
||||
<script
|
||||
src="{{ $r.RelPermalink }}"
|
||||
{{ template `render-attributes` $attr }}></script>
|
||||
{{ else }}
|
||||
{{ with $r | fingerprint }}
|
||||
<script
|
||||
src="{{ .RelPermalink }}"
|
||||
integrity="{{ .Data.Integrity }}"
|
||||
crossorigin="anonymous"
|
||||
{{ template `render-attributes` $attr }}></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
27
docs/layouts/_partials/helpers/picture.html
Normal file
27
docs/layouts/_partials/helpers/picture.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{{ $image := .image }}
|
||||
{{ $width := .width | default 1000 }}
|
||||
{{ $width1x := div $width 2 }}
|
||||
{{ $imageWebp := $image.Resize (printf "%dx webp" $width) }}
|
||||
{{ $image1x := $image.Resize (printf "%dx" $width1x) }}
|
||||
{{ $image1xWebp := $image.Resize (printf "%dx webp" $width1x) }}
|
||||
{{ $class := .class | default "h-64 tablet:h-96 lg:h-full w-full object-cover lg:absolute" }}
|
||||
{{ $loading := .loading | default "eager" }}
|
||||
<picture>
|
||||
<source
|
||||
srcset="{{ $imageWebp.RelPermalink }}"
|
||||
type="image/webp"
|
||||
media="(min-width: 1200px)">
|
||||
<source
|
||||
srcset="{{ $image.RelPermalink }}"
|
||||
type="image/jpeg"
|
||||
media="(min-width: 1200px)">
|
||||
<source srcset="{{ $image1xWebp.RelPermalink }}" type="image/webp">
|
||||
<source srcset="{{ $image1x.RelPermalink }}" type="image/jpeg">
|
||||
<img
|
||||
class="{{ $class }}"
|
||||
src="{{ $image1x.RelPermalink }}"
|
||||
alt=""
|
||||
loading="{{ $loading }}"
|
||||
width="{{ $image1x.Width }}"
|
||||
height="{{ $image1x.Height }}">
|
||||
</picture>
|
@@ -0,0 +1,22 @@
|
||||
{{/* prettier-ignore-start */ -}}
|
||||
{{- /*
|
||||
We use the front matter keywords field to determine related content. To ensure
|
||||
consistency, during site build we validate each keyword against the entries in
|
||||
data/keywords.yaml.
|
||||
|
||||
As of March 5, 2025, this feature is experimental, pending usability
|
||||
assessment. We anticipate that the number of additions to data/keywords.yaml
|
||||
will decrease over time, though the initial implementation will require some
|
||||
effort.
|
||||
*/}}
|
||||
{{/* prettier-ignore-end */ -}}
|
||||
{{- $t := debug.Timer "validateKeywords" }}
|
||||
{{- $allowedKeywords := collections.Apply site.Data.keywords "strings.ToLower" "." }}
|
||||
{{- range $p := site.Pages }}
|
||||
{{- range .Params.keywords }}
|
||||
{{- if not (in $allowedKeywords (lower .)) }}
|
||||
{{- warnf "The word or phrase %q is not in the keywords data file. See %s." . $p.Page.String }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $t.Stop }}
|
Reference in New Issue
Block a user