How to sort data file content by date in reverse?

I have a collection of yaml data files, (one file per week) using the below format. I’m able to display the data, for example here: http://class.ronliskey.com/class/6/geology/

The data is listed by week. How can I display these weeks in reverse order? The following ranges work, but I’m unable add any form of sort. I would like to sort by either “week_starts” or “week”.

{{- range $data -}}

{{- range $index, $element := $data -}}

Example YAML Data File

  ---
  week: 22
  week_starts: 2020-01-11
  grade: 6
  bid: geol
  block: "Geology"
  code: geol6
  display: true

Try something like:

{{- $data := sort .Site.Data.<name-of-folder-containing-data-files> ".week" "desc" -}}
{{- range $index, $element := $data -}}
...
{{- end -}}

More about: collections.Sort | Hugo

Thanks for the fast reply. When I try that I get:

ERROR 2021/01/10 13:20:02 render of "page" failed: execute of template failed: template: class/single.html:49:30: executing "class/single.html" at <partial "subjects/schedule.html" .>: error calling partial: "/Volumes/Passport4T/Sites/test_hugo/ronliskey_class/layouts/partials/subjects/schedule.html:18:27": execute of template failed: template: partials/subjects/schedule.html:18:27: executing "partials/subjects/schedule.html" at <.Site.Data.c2023.g6.geology>: can't evaluate field Site in type bool

I tried adding $ to .Site

{{- $data := sort $.Site.Data.c2023.g6.geology ".week" "desc" -}}
{{- range $index, $element := $data  -}}

and got:

ERROR 2021/01/10 13:21:17 render of "page" failed: execute of template failed: template: class/single.html:49:30: executing "class/single.html" at <partial "subjects/schedule.html" .>: error calling partial: "/Volumes/Passport4T/Sites/test_hugo/ronliskey_class/layouts/partials/subjects/schedule.html:18:17": execute of template failed: template: partials/subjects/schedule.html:18:17: executing "partials/subjects/schedule.html" at <sort $.Site.Data.c2023.g6.geology ".week" "desc">: error calling sort: sequence must be provided

What is the folder tree under /data/?
As the error message suggests there needs to be a sequence of data files all of which must contain the week parameter for the sorting to work.

It seems that you need to share the project for us to have a look.