Compare commits

...

8 Commits

Author SHA1 Message Date
Mark Dumay
2433fa8a66 Merge pull request #943 from gethinode/image
Refine CDN image handling
2024-05-20 15:26:53 +02:00
Mark Dumay
adbff26d18 Merge branch 'main' into image 2024-05-20 14:49:16 +02:00
Mark Dumay
bdcdeb9b55 Bump package release 2024-05-20 14:48:39 +02:00
Mark Dumay
0636708dac Add DAM provider config 2024-05-20 14:48:10 +02:00
Mark Dumay
eb65b94ef4 Fix fallback URL of Cloudinary images 2024-05-20 14:47:10 +02:00
Mark Dumay
01b51f6ef1 Provide default dimensions when site data is unavailable 2024-05-20 14:46:30 +02:00
Mark Dumay
89b81cf1b8 Handle undefined dimensions 2024-05-20 14:46:06 +02:00
Mark Dumay
54396f4dc0 Fix dimensions rounding errors 2024-05-20 13:23:26 +02:00
7 changed files with 35 additions and 13 deletions

View File

@@ -13,7 +13,7 @@
- 992x661
- 1200x800
- 1400x933
- 2800x1866
- 2800x1867
- ratio: 1x1
dimensions:
- 576x576
@@ -29,7 +29,7 @@
- 992x558
- 1200x675
- 1400x788
- 2800x1576
- 2800x1575
- ratio: 21x9
dimensions:
- 576x247

View File

@@ -70,6 +70,14 @@
[messages]
placement = "bottom-right"
[dam]
dimensions = "dimensions.yml"
[[dam.providers]]
name = "Cloudinary"
pattern = "cloudinary"
adapter = "assets/adapters/cloudinary.html"
[sharing]
enabled = true
sort = "weight"

View File

@@ -33,7 +33,7 @@
{{ $operation := "" }}
{{ if $format }}
{{ $operation = printf "%s,h_%d,w_%d" $transform $height $width }}
{{ $file = printf "%s.%s" (path.BaseName $file) $format }}
{{ $file = printf "%s.%s" (strings.TrimSuffix (path.Ext $file) $file) $format }}
{{ else }}
{{ $operation = printf "f_auto,%s,h_%d,w_%d" $transform $height $width }}
{{ end }}

View File

@@ -3,11 +3,23 @@
-->
{{ $ratio := .ratio }}
{{ $dim := "" }}
{{ $matches := first 1 (where site.Data.dimensions "ratio" $ratio) }}
{{ if eq ($matches | len) 1 }}
{{ $dim = (index $matches 0).dimensions }}
{{ $default := dict "4x3" "1400x1050" "3x2" "1400x933" "1x1" "1400x1400" "16x9" "1400x788" "21x9" "1400x600" "auto" "1400" }}
<!-- Initialize dimensions data - stripping unsupported file extension -->
{{ $config := "dimensions" }}
{{ with index site.Params "dam" }}{{ with index . "dimensions" }}{{ $config = . }}{{ end }}{{ end }}
{{ $config = path.Join (path.Dir $config) (path.BaseName $config) }}
{{ with index site.Data $config }}
{{ $matches := first 1 (where . "ratio" $ratio) }}
{{ if eq ($matches | len) 1 }}
{{ $dim = (index $matches 0).dimensions }}
{{ end }}
{{ end }}
{{ if not $dim }}
{{ $dim = slice (index $default $ratio) }}
{{ end }}
{{ return $dim }}

View File

@@ -72,9 +72,11 @@
<!-- Derive image width and height -->
{{ $width := "" }}
{{ $height := "" }}
{{ range $dim := ($dims | last 1) }}
{{ $width = (int (index (split $dim "x") 0)) }}
{{ $height = (int (index (split $dim "x") 1)) }}
{{ with $dims }}
{{ range $dim := (. | last 1) }}
{{ $width = (int (index (split $dim "x") 0)) }}
{{ $height = (int (index (split $dim "x") 1)) }}
{{ end }}
{{ end }}
<!-- Generate image urls -->

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@gethinode/hinode",
"version": "0.24.0-alpha2",
"version": "0.24.0-alpha3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@gethinode/hinode",
"version": "0.24.0-alpha2",
"version": "0.24.0-alpha3",
"license": "MIT",
"devDependencies": {
"@fullhuman/postcss-purgecss": "^6.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.24.0-alpha2",
"version": "0.24.0-alpha3",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",