github.com/jbramsden/hugo@v0.47.1/docs/content/en/content-management/page-resources.md (about)

     1  ---
     2  title : "Page Resources"
     3  description : "Page Resources -- images, other pages, documents etc. -- have page-relative URLs and their own metadata."
     4  date: 2018-01-24
     5  categories: ["content management"]
     6  keywords: [bundle,content,resources]
     7  weight: 4003
     8  draft: false
     9  toc: true
    10  linktitle: "Page Resources"
    11  menu:
    12    docs:
    13      parent: "content-management"
    14      weight: 31
    15  ---
    16  
    17  ## Properties
    18  
    19  ResourceType
    20  : The main type of the resource. For example, a file of MIME type `image/jpg` has for ResourceType `image`.
    21  
    22  Name
    23  : Default value is the filename (relative to the owning page). Can be set in front matter.
    24  
    25  Title
    26  : Default blank. Can be set in front matter.
    27  
    28  Permalink
    29  : The absolute URL to the resource. Resources of type `page` will have no value.
    30  
    31  RelPermalink
    32  : The relative URL to the resource. Resources of type `page` will have no value.
    33  
    34  ## Methods
    35  ByType
    36  : Returns the page resources of the given type.
    37  
    38  ```go
    39  {{ .Resources.ByType "image" }}
    40  ```
    41  Match
    42  : Returns all the page resources (as a slice) whose `Name` matches the given Glob pattern ([examples](https://github.com/gobwas/glob/blob/master/readme.md)). The matching is case-insensitive.
    43  
    44  ```go
    45  {{ .Resources.Match "images/*" }}
    46  ```
    47  
    48  GetMatch
    49  : Same as `Match` but will return the first match.
    50  
    51  ### Pattern Matching
    52  ```go
    53  // Using Match/GetMatch to find this images/sunset.jpg ?
    54  .Resources.Match "images/sun*" ✅
    55  .Resources.Match "**/Sunset.jpg" ✅
    56  .Resources.Match "images/*.jpg" ✅
    57  .Resources.Match "**.jpg" ✅
    58  .Resources.Match "*" 🚫
    59  .Resources.Match "sunset.jpg" 🚫
    60  .Resources.Match "*sunset.jpg" 🚫
    61  
    62  ```
    63  
    64  ## Page Resources Metadata
    65  
    66  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](http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm).
    67  
    68  {{% note %}}
    69  Resources of type `page` get `Title` etc. from their own front matter.
    70  {{% /note %}}
    71  
    72  name
    73  : Sets the value returned in `Name`.
    74  
    75  {{% warning %}}
    76  The methods `Match` and `GetMatch` use `Name` to match the resources.
    77  {{%/ warning %}}
    78  
    79  title
    80  : Sets the value returned in `Title`
    81  
    82  params
    83  : A map of custom key/values.
    84  
    85  
    86  ###  Resources metadata example
    87  
    88  {{< code-toggle copy="false">}}
    89  title: Application
    90  date : 2018-01-25
    91  resources :
    92  - src : "images/sunset.jpg"
    93    name : "header"
    94  - src : "documents/photo_specs.pdf"
    95    title : "Photo Specifications"
    96    params:
    97      icon : "photo"
    98  - src : "documents/guide.pdf"
    99    title : "Instruction Guide"
   100  - src : "documents/checklist.pdf"
   101    title : "Document Checklist"
   102  - src : "documents/payment.docx"
   103    title : "Proof of Payment"
   104  - src : "**.pdf"
   105    name : "pdf-file-:counter"
   106    params :
   107      icon : "pdf"
   108  - src : "**.docx"
   109    params :
   110      icon : "word"
   111  {{</ code-toggle >}}
   112  
   113  From the example above:
   114  
   115  - `sunset.jpg` will receive a new `Name` and can now be found with `.GetMatch "header"`.
   116  - `documents/photo_specs.pdf` will get the `photo` icon.
   117  - `documents/checklist.pdf`, `documents/guide.pdf` and `documents/payment.docx` will get `Title` as set by `title`.
   118  - Every `PDF` in the bundle except `documents/photo_specs.pdf` will get the `pdf` icon.
   119  - All `PDF` files will get a new `Name`. The `name` parameter contains a special placeholder [`:counter`](#the-counter-placeholder-in-name-and-title), so the `Name` will be `pdf-file-1`, `pdf-file-2`, `pdf-file-3`.
   120  - Every docx in the bundle will receive the `word` icon.
   121  
   122  {{% warning %}}
   123  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.
   124  {{%/ warning %}}
   125  
   126  ### The `:counter` placeholder in `name` and `title`
   127  
   128  The `:counter` is a special placeholder recognized in `name` and `title` parameters `resources`.
   129  
   130  The counter starts at 1 the first time they are used in either `name` or `title`.
   131  
   132  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:
   133  
   134  {{< code-toggle copy="false">}}
   135  [[resources]]
   136    src = "*specs.pdf"
   137    title = "Specification #:counter"
   138  [[resources]]
   139    src = "**.pdf"
   140    name = "pdf-file-:counter"
   141  {{</ code-toggle >}}
   142  
   143  the `Name` and `Title` will be assigned to the resource files as follows:
   144  
   145  | Resource file     | `Name`            | `Title`               |
   146  |-------------------|-------------------|-----------------------|
   147  | checklist.pdf     | `"pdf-file-1.pdf` | `"checklist.pdf"`     |
   148  | guide.pdf         | `"pdf-file-2.pdf` | `"guide.pdf"`         |
   149  | other\_specs.pdf  | `"pdf-file-3.pdf` | `"Specification #1"` |
   150  | photo\_specs.pdf  | `"pdf-file-4.pdf` | `"Specification #2"` |