diff --git a/data/dimensions.yml b/data/dimensions.yml index 5ccd0d7f..e7b09057 100644 --- a/data/dimensions.yml +++ b/data/dimensions.yml @@ -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 diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 62611757..38790794 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -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" diff --git a/layouts/partials/assets/adapters/cloudinary.html b/layouts/partials/assets/adapters/cloudinary.html index 1599e590..78624c0b 100644 --- a/layouts/partials/assets/adapters/cloudinary.html +++ b/layouts/partials/assets/adapters/cloudinary.html @@ -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 }} diff --git a/layouts/partials/assets/helpers/GetDimension.html b/layouts/partials/assets/helpers/GetDimension.html index 0c3644b1..24529913 100644 --- a/layouts/partials/assets/helpers/GetDimension.html +++ b/layouts/partials/assets/helpers/GetDimension.html @@ -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" }} + + +{{ $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 }} diff --git a/layouts/partials/assets/helpers/image-definition.html b/layouts/partials/assets/helpers/image-definition.html index 22a5892d..0352701b 100644 --- a/layouts/partials/assets/helpers/image-definition.html +++ b/layouts/partials/assets/helpers/image-definition.html @@ -72,9 +72,11 @@ {{ $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 }} diff --git a/package-lock.json b/package-lock.json index 27994d84..3547a042 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 1edd086e..bd7e8b5e 100644 --- a/package.json +++ b/package.json @@ -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",