Skip to content

Commit

Permalink
Hugo 0.134.0, remove deprecations, optimise templates, add configs
Browse files Browse the repository at this point in the history
  • Loading branch information
yktoo committed Sep 13, 2024
1 parent 8aa627f commit 94d9362
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 290 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ This repository contains the code that runs [yktoo.com](https://yktoo.com/).

## Requirements

* Node.js 18.x+
* Hugo 0.108+
* Node.js 20.x+
* Hugo 0.134+

## Build

* `npm install`
* `hugo`
* `npm run build` in development mode, or `npm run build:prod` in production mode

## Run a live server

* `hugo server`
* `npm start`
* Navigate to [localhost:1313](http://localhost:1313/)

## Configuration

### Environment

* Set `HUGO_DISABLE_GA` to disable inserting Google Analytics script into the generated HTML pages.
The following environments are configured for this website:

* `development` — it disables inserting Google Analytics script into the generated HTML pages. Used when you run `npm start` or `npm build`.
* `production` — used when running `npm run build:prod`
11 changes: 9 additions & 2 deletions hugo.yml → config/_default/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pygmentsCodeFences: true
pygmentsStyle: tango
title: Yktoo
summaryLength: 15
googleAnalytics: G-XK4422MN2R
enableRobotsTXT: true

markup:
Expand Down Expand Up @@ -55,11 +54,19 @@ params:
logoUrl: /images/logo.png
rssLimit: 15
shortDateFormat: 'MON D, YYYY'
social:
twitter: yktoo
facebook: yktoo.blog
facebook_admin: yktoo

services:
googleAnalytics:
id: 'G-XK4422MN2R'

module:
hugoVersion:
extended: true
min: "0.123.7"
min: "0.134.0"
mounts:
- source: node_modules
target: assets/node_modules
Expand Down
1 change: 1 addition & 0 deletions config/development/hugo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: 'Yktoo [dev]'
7 changes: 3 additions & 4 deletions layouts/partials/google-analytics.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- Do not add the code when Google Analytics is disabled -->
{{- if eq (os.Getenv "HUGO_DISABLE_GA") "" }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.GoogleAnalytics }}"></script>
{{- if not hugo.IsDevelopment }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.Config.Services.GoogleAnalytics.ID }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ .Site.GoogleAnalytics }}');
gtag('config', '{{ .Site.Config.Services.GoogleAnalytics.ID }}');
</script>
{{- end }}
56 changes: 30 additions & 26 deletions layouts/partials/opengraph.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
<!-- Hugo's _internal/opengraph.html reimplemented to support 'image' (instead of 'images') and page resources -->
<meta property="og:title" content="{{ with .Params.series }}{{ with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end }}{{ end }}{{ default .Site.Title .Title | $.RenderString | plainify | safeHTML }}" />
<meta property="og:description" content="{{ with .Description }}{{ . | $.RenderString | plainify | safeHTML }}{{ else }}{{ if .IsPage }}{{ .Summary | .RenderString | plainify | safeHTML }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
<meta property="og:title" content="{{ partial `page-title-attr` . }}"/>
<meta property="og:description" content="{{ partial `page-summary-attr` . }}"/>
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}"/>
<meta property="og:url" content="{{ .Permalink }}"/>
{{- with $.Param "image" }}
{{- $url := . }}
{{- if not (findRE "^(/|http(s?)://)" $url) }}
{{- $url = ($.Page.Resources.GetMatch $url).Permalink }}
{{- end -}}
<meta property="og:image" content="{{ $url | absURL }}" />
{{- end -}}
<meta property="og:image" content="{{ $url | absURL }}"/>
{{- end }}

<!-- Dates -->
{{- $iso8601 := "2006-01-02T15:04:05-07:00" }}
{{- if .IsPage }}
{{- if not .PublishDate.IsZero }}<meta property="article:published_time" {{ .PublishDate.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- else if not .Date.IsZero }}<meta property="article:published_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}
{{- if not .Lastmod.IsZero }}<meta property="article:modified_time" {{ .Lastmod.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{- else }}
{{- if not .Date.IsZero }}
<meta property="og:updated_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}
{{- if .IsPage -}}
{{- if not .PublishDate.IsZero -}}
<meta property="article:published_time" {{ .PublishDate.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- else if not .Date.IsZero -}}
<meta property="article:published_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}
{{- if not .Lastmod.IsZero -}}
<meta property="article:modified_time" {{ .Lastmod.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}
{{- else if not .Date.IsZero -}}
<meta property="og:updated_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}

<!-- Audio and video links -->
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }}
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ end }}
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}"/>{{ end }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}"/>{{ end }}
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}"/>{{ end }}
{{- with .Params.videos }}{{ range . }}
<meta property="og:video" content="{{ . | absURL }}" />
<meta property="og:video" content="{{ . | absURL }}"/>
{{- end }}{{ end }}

<!-- If it is part of a series, link to related articles -->
Expand All @@ -38,19 +40,21 @@
{{- with .Params.series }}
{{- $series := index $siteSeries . }}
{{- range $page := first 6 $series.Pages }}
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}" />{{ end }}
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}"/>{{ end }}
{{- end }}
{{- end }}

<!-- Facebook page authors -->
{{- if .IsPage }}
{{- range .Site.Authors }}{{ with .Social.facebook }}
<meta property="article:author" content="https://www.facebook.com/{{ . }}" />{{ end }}{{ with .Site.Social.facebook }}
<meta property="article:publisher" content="https://www.facebook.com/{{ . }}" />{{ end }}
<meta property="article:section" content="{{ .Section }}" />
{{- with .Site.Params.Social.facebook }}
<meta property="article:author" content="https://www.facebook.com/{{ . }}"/>
<meta property="article:publisher" content="https://www.facebook.com/{{ . }}"/>
{{- end }}
<meta property="article:section" content="{{ .Section }}"/>
{{- with .Params.tags }}{{ range first 6 . }}
<meta property="article:tag" content="{{ . }}" />{{ end }}{{ end }}
<meta property="article:tag" content="{{ . }}"/>
{{- end }}{{ end }}
{{- end }}

<!-- Facebook Page Admin ID for Domain Insights -->
{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }}
{{- with .Site.Params.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}"/>{{ end }}
7 changes: 7 additions & 0 deletions layouts/partials/page-summary-attr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- with .Description -}}
{{- . | $.RenderString | plainify | safeHTML -}}
{{- else -}}{{- if .IsPage -}}
{{- replace (trim (.Summary | .RenderString | plainify) "\n\r\t ") "\n" " " | safeHTML -}}
{{- else -}}
{{- with .Site.Params.description }}{{ . }}{{ end -}}
{{- end }}{{ end -}}
4 changes: 4 additions & 0 deletions layouts/partials/page-title-attr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- with .Params.series -}}
{{- with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end -}}
{{- end -}}
{{- .Title | default .Site.Title | $.RenderString | plainify | safeHTML -}}
4 changes: 4 additions & 0 deletions layouts/partials/page-title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- with .Params.series -}}
{{- with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end -}}
{{- end -}}
{{- .Title | .RenderString -}}
10 changes: 4 additions & 6 deletions layouts/partials/twitter-cards.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!-- Hugo's _internal/twitter_cards.html reimplemented to support 'image' (instead of 'images') -->
<meta name="twitter:title" content="{{ .Title | default .Site.Title | .RenderString | plainify | safeHTML }}"/>
<meta name="twitter:description" content="{{ with .Description }}{{ . | $.RenderString | plainify | safeHTML }}{{ else }}{{ if .IsPage }}{{ .Summary | $.RenderString | plainify | safeHTML }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
<meta name="twitter:title" content="{{ partial `page-title-attr` . }}"/>
<meta name="twitter:description" content="{{ partial `page-summary-attr` . }}"/>

<!-- Twitter link -->
{{- with .Site.Social.twitter -}}
{{- with .Site.Params.Social.twitter -}}
<meta name="twitter:site" content="@{{ . }}"/>
{{- end }}
{{- range .Site.Authors }}{{ with .twitter -}}
<meta name="twitter:creator" content="@{{ . }}"/>
{{- end }}{{ end }}
{{- end }}

<!-- Image, if any -->
{{- with $.Param "image" }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/post/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<div class="card-body">
<!-- Post title -->
<div class="card-text">{{ with .Params.series }}{{ with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end }}{{ end }}{{ .Title | .RenderString }}</div>
<div class="card-text">{{ partial "page-title" . }}</div>
</div>
</article>

2 changes: 1 addition & 1 deletion layouts/post/list-item.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Single post item, which is displayed in a list -->
<article class="blog-post" data-aos="fade-up">
<!-- Post heading -->
<h2><a href="{{ .Permalink }}">{{ with .Params.series }}{{ with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end }}{{ end }}{{ .Title | .RenderString }}</a></h2>
<h2><a href="{{ .Permalink }}">{{ partial "page-title" . }}</a></h2>

<!-- Post metadata -->
<div class="page-heading-meta">{{ partial "date" (dict "date" .Date "long" false) }}</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/post/rss-item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<item>
<title>{{ with .Params.series }}{{ with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end }}{{ end }}{{ .Title }}</title>
<title>{{ partial "page-title" . }}</title>
<link>{{ .Permalink }}?utm_source=rss&amp;utm_medium=feed_{{ .Language }}&amp;utm_campaign=nix</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
<author>[email protected] ({{ .Params.author | default .Site.Params.author }})</author>
Expand Down
4 changes: 3 additions & 1 deletion layouts/post/single.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{- define "title" }}{{ with .Params.series }}{{ with index $.Site.Taxonomies.series . }}{{ .Page.Title }} ‣ {{ end }}{{ end }}{{ .Title | .RenderString | plainify | safeHTML }} | {{ .Site.Title }}{{ end }}
{{- define "title" }}
{{- partial "page-title-attr" . }} | {{ .Site.Title -}}
{{- end }}

{{- define "schema-dot-org" }}
<!-- Basic properties -->
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
</tr>
<tr>
<th scope="row">{{ i18n "statsBuildDate" }}</th>
<td class="date">{{ partial "date" (dict "date" .Site.LastChange "long" false) }}</td>
<td class="date">{{ partial "date" (dict "date" .Site.Lastmod "long" false) }}</td>
</tr>
</table>
Loading

0 comments on commit 94d9362

Please sign in to comment.