Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kc0bfv/autophugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl <kc0bfv@gmail.com>2021-11-12 01:22:04 +0300
committerKarl <kc0bfv@gmail.com>2021-11-12 01:22:04 +0300
commit74b26dccda624f6678c6c941f7285184239cbce6 (patch)
treeb0003a1dcb0d354fa3b810101b3c3775ca1ce828
parenteffeb59d25be8560117bd827594f9d3c207260ff (diff)
By-weight sort no longer requires an option
-rw-r--r--README.md8
-rw-r--r--archetypes/default.md5
-rw-r--r--exampleSite/config.toml1
-rw-r--r--exampleSite/content/cats/_index.md5
-rw-r--r--exampleSite/content/dogs/_index.md15
-rw-r--r--exampleSite/content/many-simple/_index.md3
-rw-r--r--exampleSiteNoAlbum/config.toml1
-rw-r--r--layouts/partials/sect_and_img_content.html14
8 files changed, 29 insertions, 23 deletions
diff --git a/README.md b/README.md
index 2b296d6..ba7bc71 100644
--- a/README.md
+++ b/README.md
@@ -45,8 +45,6 @@ The `exampleSite` demonstrates the features unique to this theme. In your site
* `breadcrumb_use_title` - if true, breadcrumbs (the path-like display at the bottom) will use page titles instead of paths
* `filename_as_phototitle` - if true, a humanized form of the filename will be used as the phototitle (default false)
* `images_downloadable` - if true, images have a download button (default true)
-* `sort_by_weight` - resources are sorted by weights which are specified explicitly in the page bundle resource (default false)
-
Additionally, `Author.name` and `Author.email` in the site config will display as the author and webmaster email.
@@ -127,11 +125,7 @@ You can place images and subalbums together - the `assets` directory would conta
## Using Custom Weights
-When using custom weights (`sort_by_weight: true`) at section level be mindful that Hugo treats a weight of 0 as undefined. This means that an asset with weight 0 is sorted AFTER any non-null weight, positive or negative.
-
-At resource level, the sort order is as expected, with any `weight: 0` resourse sorted below negative and above positive weights.
-
-Setting `sort_by_weight: true` but not specifying any weights (or `weight: 0` only) currently results in the same sort order than `sort_by_weight: false`, but should be avoided to avoid surprises later.
+Default sorting for subalbums and images sorts by weight. For subalbums with the same weight it sorts by date, and for images with the same weight it sorts by filename. If you don't specify a weight for an item, the default is 0. Therefore - if you don't set any weights you'll sort by date... Lower weights come first so negative weights get sorted before unspecified weights and positive ones.
## Building the Site
diff --git a/archetypes/default.md b/archetypes/default.md
index d22dd34..959dd2c 100644
--- a/archetypes/default.md
+++ b/archetypes/default.md
@@ -3,9 +3,6 @@
{{- $resources := where (resources.Match $imgglob) "ResourceType" "image" }}
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
-{{- if .Site.Params.sort_by_weight }}
-weight: 0
-{{- end }}
albumthumb: "{{ cond (gt (len $resources) 0) (index $resources 0) "" }}"
draft: false
## Optional additional meta info for resources list
@@ -15,8 +12,6 @@ draft: false
resources:
{{ range $elem_index, $elem_val := $resources -}}
- src: "{{ . }}"
-{{- if $.Site.Params.sort_by_weight }}
weight: {{ add (mul $elem_index 10) 10 }}
-{{- end }}
{{ end -}}
---
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index 8090c1c..9478501 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -24,7 +24,6 @@ disableKinds = ["taxonomy", "taxonomyTerm"]
#breadcrumb_use_title = false
#filename_as_phototitle = false
#images_downloadable = true
- #sort_by_weight = false
# Headerbar links
# Do not put too many links here,
diff --git a/exampleSite/content/cats/_index.md b/exampleSite/content/cats/_index.md
index 6bf8938..c1c553a 100644
--- a/exampleSite/content/cats/_index.md
+++ b/exampleSite/content/cats/_index.md
@@ -1,8 +1,9 @@
---
title: "Cats"
-date: 2020-03-15T14:06:11-06:00
+date: 2020-03-15T10:06:11-06:00
resources:
- src: cats/cat_01.jpg
+ weight: 1
alt: Cat in the grass
phototitle: Grass cat
description: This cat stalks through the grass
@@ -10,5 +11,7 @@ resources:
alt: A cat in some sort of urban setting
phototitle: Cool cat
description: One of the coolest cats
+- src: cats/cat_03.jpg
+ weight: -1
---
diff --git a/exampleSite/content/dogs/_index.md b/exampleSite/content/dogs/_index.md
index 9db4264..2d60313 100644
--- a/exampleSite/content/dogs/_index.md
+++ b/exampleSite/content/dogs/_index.md
@@ -1,5 +1,20 @@
---
title: "Dog Group"
date: 2020-03-15T14:00:00-06:00
+weight: -1
albumthumb: "dogs/happy-dogs/stationary-dogs/dog_04.jpg"
+draft: false
+## Optional additional meta info for resources list
+# alt: Image alternative and screen-reader text
+# phototitle: A title for the photo
+# description: A sub-title or description for the photo
+resources:
+- src: "dogs/jumping_dog_01.jpg"
+ weight: 10
+- src: "dogs/jumping_dog_02.jpg"
+ weight: 20
+- src: "dogs/jumping_dog_03.jpg"
+ weight: 30
+- src: "dogs/jumping_dog_04.jpg"
+ weight: 40
---
diff --git a/exampleSite/content/many-simple/_index.md b/exampleSite/content/many-simple/_index.md
index 635ac5c..7da6f86 100644
--- a/exampleSite/content/many-simple/_index.md
+++ b/exampleSite/content/many-simple/_index.md
@@ -1,6 +1,7 @@
---
title: "Many Simple Images"
-date: 2020-12-21T12:11:50-06:00
+date: 2019-12-21T12:11:50-06:00
+weight: 1
albumthumb: "many-simple/Jamestown.gif"
draft: false
## Optional additional meta info for resources list
diff --git a/exampleSiteNoAlbum/config.toml b/exampleSiteNoAlbum/config.toml
index f28fb0a..ec303af 100644
--- a/exampleSiteNoAlbum/config.toml
+++ b/exampleSiteNoAlbum/config.toml
@@ -23,7 +23,6 @@ disableKinds = ["taxonomy", "taxonomyTerm"]
#column_count = 2
#filename_as_phototitle = false
#images_downloadable = true
- #sort_by_weight = false
# Headerbar links
# Do not put here too many links,
diff --git a/layouts/partials/sect_and_img_content.html b/layouts/partials/sect_and_img_content.html
index d85fb44..a7b995a 100644
--- a/layouts/partials/sect_and_img_content.html
+++ b/layouts/partials/sect_and_img_content.html
@@ -9,16 +9,16 @@
{{- $full_quality := default 90 ($.Param "full_quality") }}
{{- $filename_as_phototitle := default false ($.Param "filename_as_phototitle") }}
{{- $downloadable := default true ($.Param "images_downloadable") }}
- {{- $sort_by_weight := default true ($.Param "sort_by_weight") }}
{{- $thumb_size := printf "%dx q%d" $thumb_width $thumb_quality }}
{{- $full_size := printf "%dx q%d" $full_width $full_quality }}
{{- /* Build the list of sections and thumbnails */}}
{{- $.Scratch.Set "sections" (slice) }}
- {{- range cond $sort_by_weight .Sections.ByWeight .Sections.ByDate }}
+ {{- range .Sections.ByDate }}
{{- $title := .Title }}
{{- $link := .RelPermalink }}
+ {{- $weight := default 0 (.Param "weight") }}
{{- partial "scratch_set_retalbumthumb.html" . }}
{{- /* Note that the Scratch below must come from . context, not $ */}}
@@ -28,13 +28,15 @@
{{- errorf (printf "When processing '%s', no thumbnail image found for: %s" $.Page.File.Path $title) }}
{{- else }}
{{- $thumb := $image.Resize $thumb_size }}
- {{- $new_sect := dict "type" "sect" "title" $title "link" $link "thumb" $thumb }}
+ {{- $new_sect := dict "type" "sect" "title" $title "link" $link "thumb" $thumb "weight" $weight }}
{{- $sections := $.Scratch.Get "sections" }}
{{- $sections := $sections | append $new_sect }}
{{- $.Scratch.Set "sections" $sections }}
{{- end }}
{{- end }}
+ {{- /* Section list is complete, now resort */}}
+ {{- $.Scratch.Set "sections" (sort ($.Scratch.Get "sections") "weight") }}
{{- $sections := $.Scratch.Get "sections" }}
{{- /* Get and reorder the list of images */}}
@@ -88,10 +90,8 @@
{{- $images := $images | append $new_img }}
{{- $.Scratch.Set "images" $images }}
{{- end }}
- {{- /* Image list is complete, now resort if necessary */}}
- {{- if $sort_by_weight }}
- {{- $.Scratch.Set "images" (sort ($.Scratch.Get "images") "weight") }}
- {{- end }}
+ {{- /* Image list is complete, now resort */}}
+ {{- $.Scratch.Set "images" (sort ($.Scratch.Get "images") "weight") }}
{{- $images := $.Scratch.Get "images" }}
{{- /* Initialize the column storage */}}