[x/go.dev] all: simplify page↔template API

Overall, this CL changes Pages from an object with behaviors
to just plain old data operated on by templates. All the necessary
behaviors, like loading information about related pages, become
registered functions.

This CL simplifies the mental model: a page is literally nothing more
than data rendered by a template.

For example, instead of Parent and CurrentSection returning *Page
objects, they now return just the path (/foo) of the page, which can
be passed to the "page" function to load that page if needed.
Section now returns that path form too, instead of omitting the
leading slash. So "page .Section" is the section's landing page.
CurrentSection is actually gone entirely, but if needed it would be
"page .Dir".

This CL merges the Page.Params and other fields into a single map,
so that templates don't have to say .Params all over the place just to
get at per-page in what is already the per-page data object.
In that map, the convention is that uppercase keys are the ones
supplied by the site package itself, and the lowercase keys are
the ones from the  page's YAML data. But that's just a convention.
".Params.foo" is now just ".foo".

A few YAML fields known to Hugo seem to have been available in
multiple casings: in particular, series and Series, title and Title.
Fix the templates to use the form from the YAML: lowercase.

Similarly, replace where and sort, which required a custom
expression evaluator separate from the template engine, with
more limited functions "pages" (which loads pages from a given
set of files) and "newest" (which sorts them by date and then title).
These are less to understand, and the rest can be done with
plain templates (with the help of a new "add" function).

Unexport Page since nothing needs it to be exported.

Change-Id: I8a927515c45880f52dcc3cea38ac3252fe1bff15
X-GoDev-Commit: 7b0e82257a7b492fae378ea9ee51cf7c924d98a1
10 files changed
tree: d5ef9ba272e96dff07b961a7b02679bcb6108027
  1. go.dev/
  2. AUTHORS
  3. CONTRIBUTING.md
  4. CONTRIBUTORS
  5. LICENSE
  6. PATENTS
  7. README.md
README.md

Go Website

This repository holds the Go Website server code and content.

Download/Install

The easiest way to install is to run go get -u golang.org/x/website. You can also manually git clone the repository to $GOPATH/src/golang.org/x/website.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the time repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/website:” in the subject line, so it is easy to find.