f9a5dc59b Code Toggle block added to doc site final batch Templates ✅ Variables ✅ 4d4107968 Add eSolia as new sponsor 000fed94e Add missing closing tags for li in menu template example f462b620f Clarify that local CSV files cannot be inside data dir ae083641a Added hugo-search-index to list of search tools e2b64d0b7 Remove extra link 2fb4c9af5 Release 0.38.2 59b1c9853 releaser: Prepare repository for 0.39-DEV 92f6a05ea releaser: Add release notes to /docs for release of 0.38.2 76244729e releaser: Bump versions for release of 0.38.2 0960c5fb3 Adjust gray color of tab vs pane in code-toggle. 8ae3aadd7 use code-toggle shortcode when relevant Content Management ✅ 455b8b53b Update related.md 6e8d19090 Release 0.38.1 079ba044c releaser: Prepare repository for 0.39-DEV 6f23e6ec1 releaser: Add release notes to /docs for release of 0.38.1 c51692ceb releaser: Bump versions for release of 0.38.1 d37ea6a5e Update related.md faa2707d0 Update index.md 9ce901dcb Add a forgotten language tag (go-html-template) for code b05aaed14 Update where.md 4d4760819 Fix typo in code-toggle.md c5a5250a1 Use the new go-html-template Chroma lexer 2de831f4b Add the full list of Chroma lexers 18114d4b4 Update Output Formats b069d7f84 Release 0.38 caaa8355a releaser: Prepare repository for 0.39-DEV e45b7cc9f releaser: Add release notes to /docs for release of 0.38 40f40906e releaser: Bump versions for release of 0.38 2d52e2e4e Merge commit 'ed8bf081fdbf336e026517b7e1b123c039014ab5' 1439f64a0 docs: Generate docshelper data 5b0edfd79 Add .Site.IsServer fdb579ad1 Merge commit '0a23baa6a90901f772c234107c4f12c16c76f4aa' 7b71da1f8 hugolib: Add Reset method to delete key from Scratch 63a131664 docs: Add docs for lang.Merge 55cba056d Merge commit '3886fc1fef6ac19d58b9ba1bb642d0c6c9a54031' 6f301ebcc docs: Add docs on the new front matter configuration 7ba35ef56 Merge commit 'c0290655825e7bb36e13fb39f89d85b392cf1adc' 3d2cab754 releaser: Prepare repository for 0.38-DEV 095e888e1 releaser: Add release notes to /docs for release of 0.37.1 593fa0dcb releaser: Bump versions for release of 0.37.1 c18c1df54 releaser: Prepare repository for 0.38-DEV git-subtree-dir: docs git-subtree-split: f9a5dc59b77d15cc2c7534e10bcd90bcfeda7bb4
4.7 KiB
title | description | date | categories | keywords | weight | draft | toc | linktitle | menu | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Page Resources | Page Resources -- images, other pages, documents etc. -- have page-relative URLs and their own metadata. | 2018-01-24 |
|
|
4003 | false | true | Page Resources |
|
Properties
- ResourceType
- The main type of the resource. For example, a file of MIME type
image/jpg
has for ResourceTypeimage
. - 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.
{{% note %}}
Resources of type page
get Title
etc. from their own front matter.
{{% /note %}}
- name
- Sets the value returned in
Name
.
{{% warning %}}
The methods Match
and GetMatch
use Name
to match the resources.
{{%/ warning %}}
- title
- Sets the value returned in
Title
- params
- A map of custom key/values.
Resources metadata example
{{< code-toggle copy="false">}} title: Application date : 2018-01-25 resources :
- src : "images/sunset.jpg" name : "header"
- src : "documents/photo_specs.pdf" title : "Photo Specifications" params: icon : "photo"
- src : "documents/guide.pdf" title : "Instruction Guide"
- src : "documents/checklist.pdf" title : "Document Checklist"
- src : "documents/payment.docx" title : "Proof of Payment"
- src : "**.pdf" name : "pdf-file-:counter" params : icon : "pdf"
- src : "**.docx" params : icon : "word" {{</ code-toggle >}}
From the example above:
sunset.jpg
will receive a newName
and can now be found with.GetMatch "header"
.documents/photo_specs.pdf
will get thephoto
icon.documents/checklist.pdf
,documents/guide.pdf
anddocuments/payment.docx
will getTitle
as set bytitle
.- Every
PDF
in the bundle exceptdocuments/photo_specs.pdf
will get thepdf
icon. - All
PDF
files will get a newName
. Thename
parameter contains a special placeholder:counter
, so theName
will bepdf-file-1
,pdf-file-2
,pdf-file-3
. - Every docx in the bundle will receive the
word
icon.
{{% warning %}}
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.
{{%/ warning %}}
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:
{{< code-toggle copy="false">}} resources src = "*specs.pdf" title = "Specification #:counter" resources src = "**.pdf" name = "pdf-file-:counter" {{</ code-toggle >}}
the Name
and Title
will be assigned to the resource files as follows:
Resource file | Name |
Title |
---|---|---|
checklist.pdf | "pdf-file-1.pdf |
"checklist.pdf" |
guide.pdf | "pdf-file-2.pdf |
"guide.pdf" |
other_specs.pdf | "pdf-file-3.pdf |
"Specification #1" |
photo_specs.pdf | "pdf-file-4.pdf |
"Specification #2" |