From 0634e7a3f78baaf903b7ed7d504fe6db95936846 Mon Sep 17 00:00:00 2001 From: Yuri Zamyatin Date: Tue, 3 Dec 2024 22:01:12 +0000 Subject: [PATCH] images, deterministic caching --- README.md | 4 ++++ archetypes/home.md | 19 +++++++-------- archetypes/section/_index.md | 2 +- assets/css/basic.scss | 27 ++++++++++++++++++---- init/hugo.yaml | 7 +++++- layouts/_default/_markup/render-image.html | 7 ++++++ layouts/_default/baseof.html | 8 +++++-- layouts/_default/index.html | 10 ++++---- 8 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 layouts/_default/_markup/render-image.html diff --git a/README.md b/README.md index facad5c..a379955 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,8 @@ Some styling and general logic of my website, separated from content. No extra a cp themes/yrzam/init/hugo.yaml . # site config hugo new _index.md --kind home # home template hugo new yoursection --kind section # list template +# put png favicons in assets/favicon +# read generated _index template ``` + +Resource names must not start with underscore. Pattern `/_` in the URL means that resource may be permanently cached (but it won't unless you configure this rule on the web server). diff --git a/archetypes/home.md b/archetypes/home.md index 7c4b211..7a62d2f 100644 --- a/archetypes/home.md +++ b/archetypes/home.md @@ -2,20 +2,21 @@ linkTitle: home title: description: -image: - link: - ratio: 1/1 # x/y +image: # localpath from assets/ pgp: - fingerprint: - link: + fingerprint: # space-separated + link: # localpath from static/ links: - - link: - icon: + - url: + icon: # localpath from assets/icons/ w/o ext # ... sections: - name: - link: - icon: + link: # /
/ + icon: # localpath from assets/icons/ w/o ext # ... notice: + +# generator settings, no need to edit +cascade: [ build: { publishResources: false } ] --- diff --git a/archetypes/section/_index.md b/archetypes/section/_index.md index bf88c68..dc61083 100644 --- a/archetypes/section/_index.md +++ b/archetypes/section/_index.md @@ -1,5 +1,5 @@ --- linkTitle: "{{ .File.ContentBaseName | humanize | lower }}" title: "{{ .File.ContentBaseName | humanize }}" -outputs: [html] +outputs: [html] # ,rss --- diff --git a/assets/css/basic.scss b/assets/css/basic.scss index e74feff..d401383 100644 --- a/assets/css/basic.scss +++ b/assets/css/basic.scss @@ -14,7 +14,7 @@ $color-fg-accent-op-l: rgba($color-fg-accent, $opacity-low); box-sizing: border-box; } /* prettier-ignore */ -html,body,ul,ol,li,blockquote,pre,hr { +html,body,ul,ol,li,blockquote,pre,hr,figure,figcaption { margin: 0; padding: 0; } @@ -121,10 +121,27 @@ article { border: 1px solid $color-bg-accent-light; border-radius: 0.25rem; } - p img, - li img { - width: 100%; - border: 1px solid $color-bg-accent-light; + figure { + margin: 1em 0; + img { + object-fit: contain; + display: block; + width: 100%; + max-height: 30rem; + border: 1px solid $color-bg-accent-light; + } + figcaption { + text-align: center; + color: $color-fg-dark; + font-size: 0.875rem; + margin-top: 0.2rem; + line-height: 1.5; + } + &:hover { + figcaption { + color: $color-fg; + } + } } blockquote { border-left: 0.5rem solid $color-bg-accent-light; diff --git a/init/hugo.yaml b/init/hugo.yaml index d893a19..e65145a 100644 --- a/init/hugo.yaml +++ b/init/hugo.yaml @@ -13,7 +13,8 @@ params: dateFormat: "2006-01-02T15:04:05Z" dateFormatShort: "2006-01-02" paginationAdjacentLinks: 2 -paginate: 50 +pagination: + pagerSize: 50 # GENERATOR SETTINGS capitalizeListTitles: false @@ -29,3 +30,7 @@ outputFormats: baseName: rss minify: minifyOutput: true +markup: + goldmark: + parser: + wrapStandAloneImageWithinParagraph: false diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html new file mode 100644 index 0000000..ea0b229 --- /dev/null +++ b/layouts/_default/_markup/render-image.html @@ -0,0 +1,7 @@ +{{ $hook_ctx := . }} +{{ with .Page.Resources.Get .Destination | resources.Copy (replaceRE "([^/]*)$" "_$1" (path.Join .Page.Path .Destination)) | fingerprint }} +
+ + {{- with $hook_ctx.Text }}
{{ . }}
{{ end -}} +
+{{ end }} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index ddc68f1..65f72a2 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -5,11 +5,15 @@ {{ if not .IsHome }}{{ .LinkTitle | humanize }} - {{ end }}{{ .Site.Title }} - {{ $opts := dict "transpiler" "libsass" "targetPath" "style.css" }} + {{ $opts := dict "transpiler" "libsass" "targetPath" "_style._c.css" }} {{ with resources.Get "css/index.scss" | toCSS $opts | minify | fingerprint }} {{ end }} - + {{ range resources.Match "favicon/*.png" }} + {{ with resources.Copy (printf "_favicon%d._c.png" .Width) . }} + + {{ end }} + {{ end }} {{ with .OutputFormats.Get "rss" -}} {{ printf `` .Rel .MediaType.Type .Permalink site.Title | safeHTML }} {{ end }} diff --git a/layouts/_default/index.html b/layouts/_default/index.html index b814af4..44d2b88 100644 --- a/layouts/_default/index.html +++ b/layouts/_default/index.html @@ -4,10 +4,12 @@
- + {{ end }}

{{ .Title }}

@@ -22,7 +24,7 @@