Page Resources

Page Resources – images, other pages, documents etc. – have page-relative URLs and their own metadata.

Properties

ResourceType

The main type of the resource. For example, a file of MIME type image/jpg has for ResourceType image.

Name

Default value is the filename (relative to the owning page). Can be set in front matter.

Title

Default blank. Can be set in front matter.

Permalink

The absolute URL to the resource. Resources of type page will have no value.

RelPermalink

The relative URL to the resource. Resources of type page will have no value.

Methods

ByType

Returns the page resources of the given type.

{{.Resources.ByType"image"}}

Match

Returns all the page resources (as a slice) whose Name matches the given Glob pattern (examples). The matching is case-insensitive.

{{.Resources.Match"images/*"}}

GetMatch

Same as Match but will return the first match.

Pattern Matching

// Using Match/GetMatch to find this images/sunset.jpg ?
.Resources.Match"images/sun*"✅.Resources.Match"**/Sunset.jpg"✅.Resources.Match"images/*.jpg"✅.Resources.Match"**.jpg"✅.Resources.Match"*"🚫.Resources.Match"sunset.jpg"🚫.Resources.Match"*sunset.jpg"🚫

Page Resources Metadata

Page Resources’ metadata is managed from their page’s front matter with an array/table parameter named resources. You can batch assign values using a wildcards.

sunset.jpg will receive a new Name and can now be found with .GetMatch "header".

documents/photo_specs.pdf will get the photo icon.

documents/checklist.pdf, documents/guide.pdf and documents/payment.docx will get Title as set by title.

Every PDF in the bundle except documents/photo_specs.pdf will get the pdf icon.

All PDF files will get a new Name. The name parameter contains a special placeholder :counter, so the Name will be pdf-file-1, pdf-file-2, pdf-file-3.

Every docx in the bundle will receive the word icon.

The order matters — Only the first set values of the title, name and params-keys will be used. Consecutive parameters will be set only for the ones not already set. For example, in the above example, .Params.icon is already first set to "photo" in src = "documents/photo_specs.pdf". So that would not get overridden to "pdf" by the later set src = "**.pdf" rule.

The :counter placeholder in name and title

The :counter is a special placeholder recognized in name and title parameters resources.

The counter starts at 1 the first time they are used in either name or title.

For example, if a bundle has the resources photo_specs.pdf, other_specs.pdf, guide.pdf and checklist.pdf, and the front matter has specified the resources as: