|
10 | 10 | weight: 80
|
11 | 11 | toc: true
|
12 | 12 | ---
|
| 13 | + |
13 | 14 | Page resources are only accessible from [page bundles](/content-management/page-bundles), those directories with `index.md` or
|
14 | 15 | `_index.md` files at their root. Page resources are only available to the
|
15 | 16 | page with which they are bundled.
|
@@ -114,7 +115,7 @@ GetMatch
|
114 | 115 | .Resources.Match "*sunset.jpg" 🚫
|
115 | 116 | ```
|
116 | 117 |
|
117 |
| -## Page resources metadata |
| 118 | +## Metadata |
118 | 119 |
|
119 | 120 | The page resources' metadata is managed from the corresponding page's front matter with an array/table parameter named `resources`. You can batch assign values using [wildcards](https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm).
|
120 | 121 |
|
@@ -201,3 +202,108 @@ the `Name` and `Title` will be assigned to the resource files as follows:
|
201 | 202 | | guide.pdf | `"pdf-file-2.pdf` | `"guide.pdf"` |
|
202 | 203 | | other\_specs.pdf | `"pdf-file-3.pdf` | `"Specification #1"` |
|
203 | 204 | | photo\_specs.pdf | `"pdf-file-4.pdf` | `"Specification #2"` |
|
| 205 | + |
| 206 | +## Multilingual |
| 207 | + |
| 208 | +{{< new-in 0.123.0 >}} |
| 209 | + |
| 210 | +By default, with a multilingual single-host site, Hugo does not duplicate shared page resources when building the site. |
| 211 | + |
| 212 | +{{% note %}} |
| 213 | +This behavior is limited to markdown content. Shared page resources for other [content formats] are copied into each language bundle. |
| 214 | + |
| 215 | +[content formats]: /content-management/formats/ |
| 216 | +{{% /note %}} |
| 217 | + |
| 218 | +Consider this site configuration: |
| 219 | + |
| 220 | +{{< code-toggle file=hugo >}} |
| 221 | +defaultContentLanguage = 'de' |
| 222 | +defaultContentLanguageInSubdir = true |
| 223 | + |
| 224 | +[languages.de] |
| 225 | +languageCode = 'de-DE' |
| 226 | +languageName = 'Deutsch' |
| 227 | +weight = 1 |
| 228 | + |
| 229 | +[languages.en] |
| 230 | +languageCode = 'en-US' |
| 231 | +languageName = 'English' |
| 232 | +weight = 2 |
| 233 | +{{< /code-toggle >}} |
| 234 | + |
| 235 | +And this content: |
| 236 | + |
| 237 | +```text |
| 238 | +content/ |
| 239 | +└── my-bundle/ |
| 240 | + ├── a.jpg <-- shared page resource |
| 241 | + ├── b.jpg <-- shared page resource |
| 242 | + ├── c.de.jpg |
| 243 | + ├── c.en.jpg |
| 244 | + ├── index.de.md |
| 245 | + └── index.en.md |
| 246 | +``` |
| 247 | + |
| 248 | +With v0.122.0 and earlier, Hugo duplicated the shared page resources, creating copies for each language: |
| 249 | + |
| 250 | +```text |
| 251 | +public/ |
| 252 | +├── de/ |
| 253 | +│ ├── my-bundle/ |
| 254 | +│ │ ├── a.jpg <-- shared page resource |
| 255 | +│ │ ├── b.jpg <-- shared page resource |
| 256 | +│ │ ├── c.de.jpg |
| 257 | +│ │ └── index.html |
| 258 | +│ └── index.html |
| 259 | +├── en/ |
| 260 | +│ ├── my-bundle/ |
| 261 | +│ │ ├── a.jpg <-- shared page resource (duplicate) |
| 262 | +│ │ ├── b.jpg <-- shared page resource (duplicate) |
| 263 | +│ │ ├── c.en.jpg |
| 264 | +│ │ └── index.html |
| 265 | +│ └── index.html |
| 266 | +└── index.html |
| 267 | +
|
| 268 | +``` |
| 269 | + |
| 270 | +With v0.123.0 and later, Hugo places the shared resources in the page bundle for the default content language: |
| 271 | + |
| 272 | +```text |
| 273 | +public/ |
| 274 | +├── de/ |
| 275 | +│ ├── my-bundle/ |
| 276 | +│ │ ├── a.jpg <-- shared page resource |
| 277 | +│ │ ├── b.jpg <-- shared page resource |
| 278 | +│ │ ├── c.de.jpg |
| 279 | +│ │ └── index.html |
| 280 | +│ └── index.html |
| 281 | +├── en/ |
| 282 | +│ ├── my-bundle/ |
| 283 | +│ │ ├── c.en.jpg |
| 284 | +│ │ └── index.html |
| 285 | +│ └── index.html |
| 286 | +└── index.html |
| 287 | +``` |
| 288 | + |
| 289 | +This approach reduces build times, storage requirements, bandwidth consumption, and deployment times, ultimately reducing cost. |
| 290 | + |
| 291 | +{{% note %}} |
| 292 | +To resolve markdown link and image destinations to the correct location, you must use link and image render hooks that capture the page resource with the [`Resources.Get`] method, and then invoke its [`RelPermalink`] method. |
| 293 | + |
| 294 | +By default, with multilingual single-host sites, Hugo enables its [embedded link render hook] and [embedded image render hook] to resolve markdown link and image destinations. |
| 295 | + |
| 296 | +You may override the embedded render hooks as needed, provided they capture the resource as described above. |
| 297 | + |
| 298 | +[embedded link render hook]: /render-hooks/links/#default |
| 299 | +[embedded image render hook]: /render-hooks/images/#default |
| 300 | +[`Resources.Get`]: /methods/page/resources/#get |
| 301 | +[`RelPermalink`]: /methods/resource/relpermalink/ |
| 302 | +{{% /note %}} |
| 303 | + |
| 304 | +Although duplicating shared page resources is inefficient, you can enable this feature in your site configuration if desired: |
| 305 | + |
| 306 | +{{< code-toggle file=hugo >}} |
| 307 | +[markup.goldmark] |
| 308 | +duplicateResourceFiles = true |
| 309 | +{{< /code-toggle >}} |
0 commit comments