From: Bjørn Erik Pedersen Date: Mon, 22 May 2023 14:47:07 +0000 (+0200) Subject: Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb' X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b95e15694;p=brevno-suite%2Fhugo Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb' --- b95e15694006a16eee41024be88615bda62041cf diff --cc docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company-dark.svg index 1793cb644,000000000..58fd601f5 mode 100644,000000..100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company-dark.svg +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company-dark.svg @@@ -1,4 -1,0 +1,4 @@@ - ++ + + + diff --cc docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company.svg index 6f3082b54,000000000..3b85ece5c mode 100644,000000..100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company.svg +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/images/sponsors/your-company.svg @@@ -1,4 -1,0 +1,4 @@@ - ++ + + + diff --cc docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml index c31178c92,000000000..71167bfd4 mode 100644,000000..100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/data/sponsors.toml @@@ -1,24 -1,0 +1,21 @@@ +[[banners]] + name = "Linode" + link = "https://www.linode.com/" + logo = "images/sponsors/linode-logo.svg" + utm_campaign = "hugosponsor" + +[[banners]] - name = "ButterCMS" - link = "https://buttercms.com/hugo-cms/" - logo = "images/sponsors/butter-light.svg" - utm_campaign = "sponsorship" - bgcolor = "#131A3E" ++ name = "Your Company?" ++ link = "https://bep.is/en/hugo-sponsor-2023-01/" ++ logo = "/images/sponsors/your-company.svg" ++ utm_campaign = "hugosponsor" ++ show_on_hover = true ++ bgcolor = "#004887" + +[[banners]] - name = "Gravity Kit" - link = "https://www.gravitykit.com/" - logo = "images/sponsors/graitykit-dark.svg" - query_params = "ref=532&campaign=hugo&" - utm_campaign = "hugosponsor" - bgcolor = "#e0ecf3" - - #hugohome - #hugofooter - #hugogithub ++ name = "Your Company?" ++ link = "https://bep.is/en/hugo-sponsor-2023-01/" ++ logo = "/images/sponsors/your-company.svg" ++ utm_campaign = "hugosponsor" ++ show_on_hover = true ++ bgcolor = "#004887" diff --cc docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/home-page-sections/sponsors.html index b2915e109,000000000..32bc44f6a mode 100644,000000..100644 --- a/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/home-page-sections/sponsors.html +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/partials/home-page-sections/sponsors.html @@@ -1,38 -1,0 +1,53 @@@ +{{ $classes_box := "ba b--dark-gray bg-light-gray br3 flex flex-column flex-wrap items-center justify-center ph3 pv4 mb4 w-100 w-30-l " }} +{{ $gtag := .gtag | default "unknown" }} +{{ $classes_box := "ba b--dark-gray bg-light-gray br3 flex flex-column flex-wrap items-center justify-center ph3 pv4 mb4 w-100 w-30-l " }} +{{ $gtag := .gtag | default "unknown" }} +{{ $isFooter := (eq $gtag "footer") }} +{{ $utmSource := cond $isFooter "hugofooter" "hugohome" }} +{{ with .cx.Site.Data.sponsors }} ++ +
+
+

Hugo Sponsors

+
+ {{ range .banners }} +
+ {{ $query_params := .query_params | default "" }} + {{ $url := printf "%s?%s%s" .link $query_params (querify "utm_source" $utmSource "utm_medium" "banner" "utm_campaign" (.utm_campaign | default "hugosponsor")) | safeURL }} + {{ $logo := resources.Get .logo }} + {{ if hugo.IsProduction }} + {{ $gtagID := printf "Sponsor %s %s" .name $gtag | title }} + ++ class="w-100 grow pa3{{ if .show_on_hover }} ++ show-on-hover ++ {{ end }}" ++ style=""> + {{ $logo.Content | safeHTML }} + + {{ else }} - ++ + {{ $logo.Content | safeHTML }} + + {{ end }} +
+ {{ end }} +
+
+ +{{ end }} diff --cc docs/_vendor/modules.txt index 9e5b08998,000000000..5c4b53271 mode 100644,000000..100644 --- a/docs/_vendor/modules.txt +++ b/docs/_vendor/modules.txt @@@ -1,1 -1,0 +1,1 @@@ - # github.com/gohugoio/gohugoioTheme v0.0.0-20230124135550-462d5fe4a87f ++# github.com/gohugoio/gohugoioTheme v0.0.0-20230418063032-99f9185b8e11 diff --cc docs/archetypes/functions.md index c2bb3113e,000000000..891458daa mode 100644,000000..100644 --- a/docs/archetypes/functions.md +++ b/docs/archetypes/functions.md @@@ -1,12 -1,0 +1,11 @@@ +--- - linktitle: "" ++title: {{ replace .Name "-" " " | title }} +description: "" - categories: [functions] - tags: [] - ns: "" +signature: [] - hugoversion: "" - aliases: [] ++categories: [functions] ++keywords: [] ++menu: ++ docs: ++ parent: functions +relatedfuncs: [] - toc: false +--- diff --cc docs/content/en/about/_index.md index 8ed441b61,000000000..91260a4a6 mode 100644,000000..100644 --- a/docs/content/en/about/_index.md +++ b/docs/content/en/about/_index.md @@@ -1,20 -1,0 +1,15 @@@ +--- +title: About Hugo +linktitle: Overview +description: Hugo's features, roadmap, license, and motivation. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [] +keywords: [] +menu: + docs: - parent: "about" ++ parent: about + weight: 1 +weight: 1 - draft: false +aliases: [/about-hugo/,/docs/] - toc: false +--- + +Hugo is not your average static site generator. diff --cc docs/content/en/about/benefits.md index 925da1732,000000000..91c243413 mode 100644,000000..100644 --- a/docs/content/en/about/benefits.md +++ b/docs/content/en/about/benefits.md @@@ -1,42 -1,0 +1,35 @@@ +--- +title: The Benefits of Static Site Generators +linktitle: The Benefits of Static +description: Improved performance, security and ease of use are just a few of the reasons static site generators are so appealing. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +keywords: [ssg,static,performance,security] +menu: + docs: - parent: "about" ++ parent: about + weight: 30 +weight: 30 - sections_weight: 30 - draft: false - aliases: [] - toc: false +--- + +The purpose of website generators is to render content into HTML files. Most are "dynamic site generators." That means the HTTP server---i.e., the program that sends files to the browser to be viewed---runs the generator to create a new HTML file every time an end user requests a page. + +Over time, dynamic site generators were programmed to cache their HTML files to prevent unnecessary delays in delivering pages to end users. A cached page is a static version of a web page. + +Hugo takes caching a step further and all HTML files are rendered on your computer. You can review the files locally before copying them to the computer hosting the HTTP server. Since the HTML files aren't generated dynamically, we say that Hugo is a *static site generator*. + +This has many benefits. The most noticeable is performance. HTTP servers are *very* good at sending files---so good, in fact, that you can effectively serve the same number of pages with a fraction of the memory and CPU needed for a dynamic site. + +## More on Static Site Generators + +* ["An Introduction to Static Site Generators", David Walsh] +* ["Hugo vs. WordPress page load speed comparison: Hugo leaves WordPress in its dust", GettingThingsTech][hugovwordpress] +* ["Static Site Generators", O'Reilly] +* [StaticGen: Top Open-Source Static Site Generators (GitHub Stars)] +* ["Top 10 Static Website Generators", Netlify blog] +* ["The Resurgence of Static", dotCMS][dotcms] + +["An Introduction to Static Site Generators", David Walsh]: https://davidwalsh.name/introduction-static-site-generators +["Static Site Generators", O'Reilly]: https://github.com/gohugoio/hugoDocs/files/1242701/static-site-generators.pdf +["Top 10 Static Website Generators", Netlify blog]: https://www.netlify.com/blog/2016/05/02/top-ten-static-website-generators/ +[hugovwordpress]: https://gettingthingstech.com/hugo-vs.-wordpress-page-load-speed-comparison-hugo-leaves-wordpress-in-its-dust/ +[StaticGen: Top Open-Source Static Site Generators (GitHub Stars)]: https://www.staticgen.com/ +[dotcms]: https://dotcms.com/blog/post/the-resurgence-of-static diff --cc docs/content/en/about/features.md index fc3d5a030,000000000..6fac68cdd mode 100644,000000..100644 --- a/docs/content/en/about/features.md +++ b/docs/content/en/about/features.md @@@ -1,84 -1,0 +1,78 @@@ +--- +title: Hugo Features - linktitle: Hugo Features +description: Hugo boasts blistering speed, robust content management, and a powerful templating language making it a great fit for all kinds of static websites. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +menu: + docs: - parent: "about" ++ parent: about + weight: 20 +weight: 20 - sections_weight: 20 - draft: false +toc: true +--- + +## General + +* [Extremely fast] build times (< 1 ms per page) +* Completely cross platform, with [easy installation][install] on macOS, Linux, Windows, and more +* Renders changes on the fly with [LiveReload] as you develop +* [Powerful theming] +* [Host your site anywhere][hostanywhere] + +## Organization + +* Straightforward [organization for your projects], including website sections +* Customizable [URLs] +* Support for configurable [taxonomies], including categories and tags +* [Sort content] as you desire through powerful template [functions] +* Automatic [table of contents] generation +* [Dynamic menu] creation +* [Pretty URLs] support +* [Permalink] pattern support +* Redirects via [aliases] + +## Content + +* Native Markdown and Emacs Org-Mode support, as well as other languages via *external helpers* (see [supported formats]) +* TOML, YAML, and JSON metadata support in [front matter] +* Customizable [homepage] +* Multiple [content types] +* Automatic and user defined [content summaries] +* [Shortcodes] to enable rich content inside of Markdown +* ["Minutes to Read"][pagevars] functionality +* ["WordCount"][pagevars] functionality + +## Additional Features + +* Integrated [Disqus] comment support +* Integrated [Google Analytics] support +* Automatic [RSS] creation +* Support for [Go] HTML templates +* [Syntax highlighting] powered by [Chroma] + +[aliases]: /content-management/urls/#aliases +[Chroma]: https://github.com/alecthomas/chroma +[content summaries]: /content-management/summaries/ +[content types]: /content-management/types/ +[Disqus]: https://disqus.com/ +[Dynamic menu]: /templates/menu-templates/ +[Extremely fast]: https://github.com/bep/hugo-benchmark +[front matter]: /content-management/front-matter/ +[functions]: /functions/ +[Go]: https://pkg.go.dev/html/template +[Google Analytics]: https://google-analytics.com/ +[homepage]: /templates/homepage/ +[hostanywhere]: /hosting-and-deployment/ +[install]: /installation/ +[LiveReload]: /getting-started/usage/ +[organization for your projects]: /getting-started/directory-structure/ +[pagevars]: /variables/page/ +[Permalink]: /content-management/urls/#permalinks +[Powerful theming]: /hugo-modules/theme-components/ +[Pretty URLs]: /content-management/urls/ +[RSS]: /templates/rss/ +[Shortcodes]: /content-management/shortcodes/ +[sort content]: /templates/ +[supported formats]: /content-management/formats/ +[Syntax highlighting]: /content-management/syntax-highlighting/ +[table of contents]: /content-management/toc/ +[taxonomies]: /content-management/taxonomies/ +[URLs]: /content-management/urls/ diff --cc docs/content/en/about/hugo-and-gdpr.md index 2d4fba872,000000000..3e0a160c7 mode 100644,000000..100644 --- a/docs/content/en/about/hugo-and-gdpr.md +++ b/docs/content/en/about/hugo-and-gdpr.md @@@ -1,138 -1,0 +1,134 @@@ +--- +title: Hugo and the General Data Protection Regulation (GDPR) +linktitle: Hugo and GDPR +description: About how to configure your Hugo site to meet the new regulations. - date: 2018-05-25 +layout: single +keywords: ["GDPR", "Privacy", "Data Protection"] +menu: + docs: - parent: "about" ++ parent: about + weight: 5 +weight: 5 - sections_weight: 5 - draft: false +aliases: [/privacy/,/gdpr/] +toc: true +--- + + General Data Protection Regulation ([GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation)) is a regulation in EU law on data protection and privacy for all individuals within the European Union and the European Economic Area. It became enforceable on 25 May 2018. + + **Hugo is a static site generator. By using Hugo you are already standing on very solid ground. Static HTML files on disk are much easier to reason about compared to server and database driven web sites.** + + But even static websites can integrate with external services, so from version `0.41`, Hugo provides a **Privacy Config** that covers the relevant built-in templates. + + Note that: + + * These settings have their defaults setting set to _off_, i.e. how it worked before Hugo `0.41`. You must do your own evaluation of your site and apply the appropriate settings. + * These settings work with the [internal templates](/templates/internal/). Some theme may contain custom templates for embedding services like Google Analytics. In that case these options have no effect. + * We will continue this work and improve this further in future Hugo versions. + +## All Privacy Settings + +Below are all privacy settings and their default value. These settings need to be put in your site config (e.g. `config.toml`). + + {{< code-toggle file="config">}} +[privacy] +[privacy.disqus] +disable = false +[privacy.googleAnalytics] +disable = false +respectDoNotTrack = false +anonymizeIP = false +useSessionStorage = false +[privacy.instagram] +disable = false +simple = false +[privacy.twitter] +disable = false +enableDNT = false +simple = false +[privacy.vimeo] +disable = false +enableDNT = false +simple = false +[privacy.youtube] +disable = false +privacyEnhanced = false +{{< /code-toggle >}} + - +## Disable All Services + +An example Privacy Config that disables all the relevant services in Hugo. With this configuration, the other settings will not matter. + + {{< code-toggle file="config">}} +[privacy] +[privacy.disqus] +disable = true +[privacy.googleAnalytics] +disable = true +[privacy.instagram] +disable = true +[privacy.twitter] +disable = true +[privacy.vimeo] +disable = true +[privacy.youtube] +disable = true +{{< /code-toggle >}} + +## The Privacy Settings Explained + +### GoogleAnalytics + +anonymizeIP +: Enabling this will make it so the users' IP addresses are anonymized within Google Analytics. + +respectDoNotTrack +: Enabling this will make the GA templates respect the "Do Not Track" HTTP header. + +useSessionStorage +: Enabling this will disable the use of Cookies and use Session Storage to Store the GA Client ID. + - {{% warning %}} ++{{% note %}} +`useSessionStorage` is not supported when using Google Analytics v4 (gtag.js). - {{% /warning %}} ++{{% /note %}} + +### Instagram + +simple +: If simple mode is enabled, a static and no-JS version of the Instagram image card will be built. Note that this only supports image cards and the image itself will be fetched from Instagram's servers. + +**Note:** If you use the _simple mode_ for Instagram and a site styled with Bootstrap 4, you may want to disable the inline styles provided by Hugo: + + {{< code-toggle file="config">}} +[services] +[services.instagram] +disableInlineCSS = true +{{< /code-toggle >}} + +### Twitter + +enableDNT +: Enabling this for the twitter/tweet shortcode, the tweet and its embedded page on your site are not used for purposes that include personalized suggestions and personalized ads. + +simple +: If simple mode is enabled, a static and no-JS version of a tweet will be built. + +**Note:** If you use the _simple mode_ for Twitter, you may want to disable the inline styles provided by Hugo: + + {{< code-toggle file="config">}} +[services] +[services.twitter] +disableInlineCSS = true +{{< /code-toggle >}} + +### YouTube + +privacyEnhanced +: When you turn on privacy-enhanced mode, YouTube won’t store information about visitors on your website unless the user plays the embedded video. + +### Vimeo + +enableDNT +: Enabling this for the vimeo shortcode, the Vimeo player will be blocked from tracking any session data, including all cookies and stats. + +simple +: If simple mode is enabled, the video thumbnail is fetched from Vimeo's servers and it is overlayed with a play button. If the user clicks to play the video, it will open in a new tab directly on Vimeo's website. diff --cc docs/content/en/about/license.md index ae74b6047,000000000..267ec95a0 mode 100644,000000..100644 --- a/docs/content/en/about/license.md +++ b/docs/content/en/about/license.md @@@ -1,165 -1,0 +1,161 @@@ +--- +title: Apache License +linktitle: License +description: Hugo v0.15 and later are released under the Apache 2.0 license. - date: 2016-02-01 - publishdate: 2016-02-01 - lastmod: 2016-03-02 +categories: ["about hugo"] +keywords: ["License","apache"] +menu: + docs: - parent: "about" ++ parent: about + weight: 60 +weight: 60 - sections_weight: 60 +aliases: [/meta/license] +toc: true +--- + +{{% note %}} +Hugo v0.15 and later are released under the Apache 2.0 license. - Earlier versions of Hugo were released under the [Simple Public License](https://opensource.org/licenses/Simple-2.0). ++Earlier versions of Hugo were released under the [Simple Public License](https://opensource.org/license/simpl-2-0-html/). +{{% /note %}} + +_Version 2.0, January 2004_
+ + +*Terms and Conditions for use, reproduction, and distribution* + +## 1. Definitions + +“License” shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +“Licensor” shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +“Legal Entity” shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, “control” means **(i)** the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the +outstanding shares, or **(iii)** beneficial ownership of such entity. + +“You” (or “Your”) shall mean an individual or Legal Entity exercising +permissions granted by this License. + +“Source” form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +“Object” form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +“Work” shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +“Derivative Works” shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +“Contribution” shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +“submitted” means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as “Not a Contribution.” + +“Contributor” shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +## 2. Grant of Copyright License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +## 3. Grant of Patent License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +## 4. Redistribution + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +* **(a)** You must give any other recipients of the Work or Derivative Works a copy of +this License; and +* **(b)** You must cause any modified files to carry prominent notices stating that You +changed the files; and +* **\(c)** You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +## 5. Submission of Contributions + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +## 6. Trademarks + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +## 7. Disclaimer of Warranty + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +## 8. Limitation of Liability + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +## 9. Accepting Warranty or Additional Liability + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +_END OF TERMS AND CONDITIONS_ + +## APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets `[]` replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives. + - {{< code file="apache-notice.txt" download="apache-notice.txt" >}} ++{{< code file="apache-notice.txt" >}} +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +{{< /code >}} diff --cc docs/content/en/about/security-model/index.md index d4dacd9bf,000000000..a909a4236 mode 100644,000000..100644 --- a/docs/content/en/about/security-model/index.md +++ b/docs/content/en/about/security-model/index.md @@@ -1,65 -1,0 +1,63 @@@ +--- +title: Hugo's Security Model +description: A summary of Hugo's security model. - date: 2019-10-01 +layout: single +keywords: ["Security", "Privacy"] +menu: + docs: - parent: "about" ++ parent: about + weight: 4 +weight: 5 - sections_weight: 5 +aliases: [/security/] +toc: true +--- + +## Runtime Security + +Hugo produces static output, so once built, the runtime is the browser (assuming the output is HTML) and any server (API) that you integrate with. + +But when developing and building your site, the runtime is the `hugo` executable. Securing a runtime can be [a real challenge](https://blog.logrocket.com/how-to-protect-your-node-js-applications-from-malicious-dependencies-5f2e60ea08f9/). + +**Hugo's main approach is that of sandboxing and a security policy with strict defaults:** + +* Hugo has a virtual file system and only the main project (not third-party components) is allowed to mount directories or files outside the project root. +* Only the main project can walk symbolic links. +* User-defined components have read-only access to the filesystem. +* We shell out to some external binaries to support [Asciidoctor](/content-management/formats/#list-of-content-formats) and similar, but those binaries and their flags are predefined and disabled by default (see [Security Policy](#security-policy)). General functions to run arbitrary external OS commands have been [discussed](https://github.com/gohugoio/hugo/issues/796), but not implemented because of security concerns. + +## Security Policy + +Hugo has a built-in security policy that restricts access to [os/exec](https://pkg.go.dev/os/exec), remote communication and similar. + +The default configuration is listed below. Any build using features not in the allow list of the security policy will fail with a detailed message about what needs to be done. Most of these settings are allow lists (string or slice, [Regular Expressions](https://pkg.go.dev/regexp) or `none` which matches nothing). + +{{< code-toggle config="security" />}} + +Note that these and other config settings in Hugo can be overridden by the OS environment. If you want to block all remote HTTP fetching of data: + +```txt +HUGO_SECURITY_HTTP_URLS=none hugo +``` + +## Dependency Security + +Hugo is built as a static binary using [Go Modules](https://github.com/golang/go/wiki/Modules) to manage its dependencies. Go Modules have several safeguards, one of them being the `go.sum` file. This is a database of the expected cryptographic checksums of all of your dependencies, including transitive dependencies. + +[Hugo Modules](/hugo-modules/) is a feature built on top of the functionality of Go Modules. Like Go Modules, a Hugo project using Hugo Modules will have a `go.sum` file. We recommend that you commit this file to your version control system. The Hugo build will fail if there is a checksum mismatch, which would be an indication of [dependency tampering](https://julienrenaux.fr/2019/12/20/github-actions-security-risk/). + +## Web Application Security + +These are the security threats as defined by [OWASP](https://en.wikipedia.org/wiki/OWASP). + +For HTML output, this is the core security model: + + + +In short: + +Template and configuration authors (you) are trusted, but the data you send in is not. +This is why you sometimes need to use the _safe_ functions, such as `safeHTML`, to avoid escaping of data you know is safe. +There is one exception to the above, as noted in the documentation: If you enable inline shortcodes, you also say that the shortcodes and data handling in content files are trusted, as those macros are treated as pure text. +It may be worth adding that Hugo is a static site generator with no concept of dynamic user input. + +For content, the default Markdown renderer is [configured](/getting-started/configuration-markup) to remove or escape potentially unsafe content. This behavior can be reconfigured if you trust your content. diff --cc docs/content/en/about/what-is-hugo.md index d61f821cd,000000000..3097de50e mode 100644,000000..100644 --- a/docs/content/en/about/what-is-hugo.md +++ b/docs/content/en/about/what-is-hugo.md @@@ -1,62 -1,0 +1,56 @@@ +--- +title: What is Hugo - linktitle: What is Hugo +description: Hugo is a fast and modern static site generator written in Go, and designed to make website creation fun again. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +layout: single +menu: + docs: - parent: "about" ++ parent: about + weight: 10 +weight: 10 - sections_weight: 10 - draft: false +aliases: [/overview/introduction/,/about/why-i-built-hugo/] +toc: true +--- + +Hugo is a general-purpose website framework. Technically speaking, Hugo is a [static site generator]. Unlike systems that dynamically build a page with each visitor request, Hugo builds pages when you create or update your content. Since websites are viewed far more often than they are edited, Hugo is designed to provide an optimal viewing experience for your website's end users and an ideal writing experience for website authors. + +Websites built with Hugo are extremely fast and secure. Hugo sites can be hosted anywhere, including [Netlify], [Heroku], [GoDaddy], [DreamHost], [GitHub Pages], [GitLab Pages], [Surge], [Firebase], [Google Cloud Storage], [Amazon S3], [Rackspace], [Azure], and [CloudFront] and work well with CDNs. Hugo sites run without the need for a database or dependencies on expensive runtimes like Ruby, Python, or PHP. + +We think of Hugo as the ideal website creation tool with nearly instant build times, able to rebuild whenever a change is made. + +## How Fast is Hugo? + +{{< youtube "CdiDYZ51a2o" >}} + +## What Does Hugo Do? + +In technical terms, Hugo takes a source directory of files and templates and uses these as input to create a complete website. + +## Who Should Use Hugo? + +Hugo is for people that prefer writing in a text editor over a browser. + +Hugo is for people who want to hand code their own website without worrying about setting up complicated runtimes, dependencies and databases. + +Hugo is for people building a blog, a company site, a portfolio site, documentation, a single landing page, or a website with thousands of pages. + +[@spf13]: https://twitter.com/spf13 +[Amazon S3]: https://aws.amazon.com/s3/ +[Azure]: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website +[CloudFront]: https://aws.amazon.com/cloudfront/ "Amazon CloudFront" +[DreamHost]: https://www.dreamhost.com/ +[Firebase]: https://firebase.google.com/docs/hosting/ "Firebase static hosting" +[GitHub Pages]: https://pages.github.com/ +[GitLab Pages]: https://about.gitlab.com/features/pages/ +[Go language]: https://go.dev/ +[GoDaddy]: https://www.godaddy.com/ "GoDaddy.com Hosting" +[Google Cloud Storage]: https://cloud.google.com/storage/ +[Heroku]: https://www.heroku.com/ +[Jekyll]: https://jekyllrb.com/ +[Middleman]: https://middlemanapp.com/ +[Nanoc]: https://nanoc.ws/ +[Netlify]: https://netlify.com +[Rackspace]: https://www.rackspace.com/cloud/files +[Surge]: https://surge.sh +[contributing to it]: https://github.com/gohugoio/hugo +[rackspace]: https://www.rackspace.com/openstack/public/files +[static site generator]: /about/benefits/ diff --cc docs/content/en/content-management/_index.md index 7cb6357c6,000000000..e87749d3a mode 100644,000000..100644 --- a/docs/content/en/content-management/_index.md +++ b/docs/content/en/content-management/_index.md @@@ -1,16 -1,0 +1,15 @@@ +--- +title: Content Management +linkTitle: Content Management Overview +description: Hugo makes managing large static sites easy with support for archetypes, content types, menus, cross references, summaries, and more. +menu: + docs: + parent: content-management + weight: 10 +keywords: [source, organization] +categories: [content management] - toc: false +weight: 10 +aliases: [/content/,/content/organization] +--- + +A static site generator needs to extend beyond front matter and a couple of templates to be both scalable and *manageable*. Hugo was designed with not only developers in mind, but also content managers and authors. diff --cc docs/content/en/content-management/archetypes.md index 1d2ba3179,000000000..f2bc6a441 mode 100644,000000..100644 --- a/docs/content/en/content-management/archetypes.md +++ b/docs/content/en/content-management/archetypes.md @@@ -1,91 -1,0 +1,90 @@@ +--- +title: Archetypes - linkTitle: Archetypes +description: Archetypes are templates used when creating new content. +keywords: [archetypes,generators,metadata,front matter] +categories: [content management] +menu: + docs: + parent: content-management + weight: 140 + quicklinks: +toc: true +weight: 140 +aliases: [/content/archetypes/] +--- + +## What are Archetypes? + +**Archetypes** are content template files in the [archetypes directory] of your project that contain preconfigured [front matter] and possibly also a content disposition for your website's [content types]. These will be used when you run `hugo new`. + + +The `hugo new` uses the `content-section` to find the most suitable archetype template in your project. If your project does not contain any archetype files, it will also look in the theme. + +{{< code file="archetype-example.sh" >}} +hugo new posts/my-first-post.md +{{< /code >}} + +The above will create a new content file in `content/posts/my-first-post.md` using the first archetype file found of these: + +1. `archetypes/posts.md` +2. `archetypes/default.md` +3. `themes/my-theme/archetypes/posts.md` +4. `themes/my-theme/archetypes/default.md` + +The last two list items are only applicable if you use a theme and it uses the `my-theme` theme name as an example. + +## Create a New Archetype Template + +A fictional example for the section `newsletter` and the archetype file `archetypes/newsletter.md`. Create a new file in `archetypes/newsletter.md` and open it in a text editor. + +{{< code file="archetypes/newsletter.md" >}} +--- +title: "{{ replace .Name "-" " " | title }}" +date: {{ .Date }} +draft: true +--- + +**Insert Lead paragraph here.** + +## New Cool Posts + +{{ range first 10 ( where .Site.RegularPages "Type" "cool" ) }} +* {{ .Title }} +{{ end }} +{{< /code >}} + +When you create a new newsletter with: + +```bash +hugo new newsletter/the-latest-cool.stuff.md +``` + +It will create a new newsletter type of content file based on the archetype template. + +**Note:** the site will only be built if the `.Site` is in use in the archetype file, and this can be time consuming for big sites. + +The above _newsletter type archetype_ illustrates the possibilities: The full Hugo `.Site` and all of Hugo's template funcs can be used in the archetype file. + +## Directory based archetypes + +Since Hugo `0.49` you can use complete directories as archetype templates. Given this archetype directory: + +```bash +archetypes +├── default.md +└── post-bundle + ├── bio.md + ├── images + │ └── featured.jpg + └── index.md +``` + +```bash +hugo new --kind post-bundle posts/my-post +``` + +Will create a new folder in `/content/posts/my-post` with the same set of files as in the `post-bundle` archetypes folder. All content files (`index.md` etc.) can contain template logic, and will receive the correct `.Site` for the content's language. + +[archetypes directory]: /getting-started/directory-structure/ +[content types]: /content-management/types/ +[front matter]: /content-management/front-matter/ diff --cc docs/content/en/content-management/build-options.md index f798754f1,000000000..4798f9b2b mode 100644,000000..100644 --- a/docs/content/en/content-management/build-options.md +++ b/docs/content/en/content-management/build-options.md @@@ -1,115 -1,0 +1,111 @@@ +--- +title: Build Options +linkTitle: Build Options +description: Build options help define how Hugo must treat a given page when building the site. +keywords: [build,content,front matter, page resources] +categories: [content management] +menu: + docs: + parent: content-management + weight: 70 +toc: true +weight: 70 +aliases: [/content/build-options/] +--- + +They are stored in a reserved Front Matter object named `_build` with the following defaults: + +{{< code-toggle >}} +_build: + render: always + list: always + publishResources: true +{{< /code-toggle >}} + +#### render + +If `always`, the page will be treated as a published page, holding its dedicated output files (`index.html`, etc...) and permalink. + +We extended this property from a boolean to an enum in Hugo 0.76.0. Valid values are: + +never +: The page will not be included in any page collection. + +always (default) +: The page will be rendered to disk and get a `RelPermalink` etc. + +link +: The page will be not be rendered to disk, but will get a `RelPermalink`. + +#### list + +Note that we extended this property from a boolean to an enum in Hugo 0.68.0. + +Valid values are: + +never +: The page will not be included in any page collection. + +always (default) +: The page will be included in all page collections, e.g. `site.RegularPages`, `$page.Pages`. + +local +: The page will be included in any _local_ page collection, e.g. `$page.RegularPages`, `$page.Pages`. One use case for this would be to create fully navigable, but headless content sections. + +If true, the page will be treated as part of the project's collections and, when appropriate, returned by Hugo's listing methods (`.Pages`, `.RegularPages` etc...). + +#### publishResources + - If set to true the [Bundle's Resources]({{< relref "content-management/page-bundles" >}}) will be published. ++If set to true the [Bundle's Resources](/content-management/page-bundles) will be published. +Setting this to false will still publish Resources on demand (when a resource's `.Permalink` or `.RelPermalink` is invoked from the templates) but will skip the others. + +{{% note %}} - Any page, regardless of their build options, will always be available using the [`.GetPage`]({{< relref "functions/GetPage" >}}) methods. ++Any page, regardless of their build options, will always be available using the [`.GetPage`](/functions/getpage) methods. +{{% /note %}} + - ------ - +### Illustrative use cases + +#### Not publishing a page + +Project needs a "Who We Are" content file for Front Matter and body to be used by the homepage but nowhere else. + - ```yaml - # content/who-we-are.md` ++{{< code-toggle file="content/who-we-are.md" fm=true copy=false >}} +title: Who we are +_build: + list: false + render: false - ``` ++{{< /code-toggle >}} + - ```go-html-template - {{/* layouts/index.html */}} ++{{< code file="layouts/index.html" copy=false >}} +
- {{ with site.GetPage "who-we-are" }} - {{ .Content }} - {{ end }} ++ {{ with site.GetPage "who-we-are" }} ++ {{ .Content }} ++ {{ end }} +
- ``` ++{{< /code >}} + +#### Listing pages without publishing them + +Website needs to showcase a few of the hundred "testimonials" available as content files without publishing any of them. + - To avoid setting the build options on every testimonials, one can use [`cascade`]({{< relref "/content-management/front-matter#front-matter-cascade" >}}) on the testimonial section's content file. ++To avoid setting the build options on every testimonials, one can use [`cascade`](/content-management/front-matter#front-matter-cascade) on the testimonial section's content file. + +{{< code-toggle >}} +title: Testimonials +_build: + render: true +cascade: + _build: + render: false + list: true # default +{{< /code-toggle >}} + - ```go-html-template - {{/* layouts/_defaults/testimonials.html */}} ++{{< code file="layouts/_defaults/testimonials.html" copy=false >}} +
- {{ range first 5 .Pages }} -
- {{ .Content }} -
- {{ end }} ++ {{ range first 5 .Pages }} ++
++ {{ .Content }} ++
++ {{ end }} +
++{{< /code >}} diff --cc docs/content/en/content-management/comments.md index e49711e7c,000000000..0543f47a7 mode 100644,000000..100644 --- a/docs/content/en/content-management/comments.md +++ b/docs/content/en/content-management/comments.md @@@ -1,72 -1,0 +1,71 @@@ +--- +title: Comments - linkTitle: Comments +description: Hugo ships with an internal Disqus template, but this isn't the only commenting system that will work with your new Hugo website. +keywords: [sections,content,organization] +categories: [project organization, fundamentals] +menu: + docs: + parent: content-management + weight: 220 +toc: true +weight: 220 +aliases: [/extras/comments/] +--- + +Hugo ships with support for [Disqus](https://disqus.com/), a third-party service that provides comment and community capabilities to websites via JavaScript. + +Your theme may already support Disqus, but if not, it is easy to add to your templates via [Hugo's built-in Disqus partial][disquspartial]. + +## Add Disqus + +Hugo comes with all the code you need to load Disqus into your templates. Before adding Disqus to your site, you'll need to [set up an account][disqussetup]. + +### Configure Disqus + +Disqus comments require you set a single value in your [site's configuration file][configuration] like so: + - {{< code-toggle copy="false" >}} ++{{< code-toggle copy=false >}} +disqusShortname = "yourDisqusShortname" +{{}} + +For many websites, this is enough configuration. However, you also have the option to set the following in the [front matter] of a single content file: + +* `disqus_identifier` +* `disqus_title` +* `disqus_url` + +### Render Hugo's Built-in Disqus Partial Template + +Disqus has its own [internal template](https://gohugo.io/templates/internal/#disqus) available, to render it add the following code where you want comments to appear: + +```go-html-template +{{ template "_internal/disqus.html" . }} +``` + +## Alternatives + +These are some alternatives to Disqus: + +* [Cactus Comments](https://cactus.chat/docs/integrations/hugo/) (Open Source, Matrix appservice, Docker install) +* [Commento](https://commento.io/) (Open Source, available as a service, local install, or docker image) +* [Graph Comment](https://graphcomment.com/) +* [Hyvor Talk](https://talk.hyvor.com/) (Available as a service) +* [IntenseDebate](https://intensedebate.com/) +* [Isso](https://isso-comments.de/) (Self-hosted, Python) ([tutorial][issotutorial]) +* [Muut](https://muut.com/) +* [Remark42](https://remark42.com/) (Open source, Golang, Easy to run docker) +* [ReplyBox](https://getreplybox.com/) +* [Staticman](https://staticman.net/) +* [Talkyard](https://blog-comments.talkyard.io/) (Open source, & serverless hosting) +* [Utterances](https://utteranc.es/) (Open source, GitHub comments widget built on GitHub issues) + +[configuration]: /getting-started/configuration/ +[disquspartial]: /templates/internal/#disqus +[disqussetup]: https://disqus.com/profile/signup/ +[forum]: https://discourse.gohugo.io +[front matter]: /content-management/front-matter/ +[kaijuissue]: https://github.com/spf13/kaiju/issues/new +[issotutorial]: https://stiobhart.net/2017-02-24-isso-comments/ +[partials]: /templates/partials/ +[MongoDB]: https://www.mongodb.com/ +[tweet]: https://twitter.com/spf13 diff --cc docs/content/en/content-management/diagrams.md index c95548249,000000000..e664dd501 mode 100644,000000..100644 --- a/docs/content/en/content-management/diagrams.md +++ b/docs/content/en/content-management/diagrams.md @@@ -1,265 -1,0 +1,266 @@@ +--- +title: Diagrams - LinkTitle: Diagrams +description: Use fenced code blocks and markdown render hooks to display diagrams. +categories: [content management] +keywords: [diagrams,drawing] +menu: + docs: + parent: content-management + weight: 50 +toc: true +weight: 50 +--- +{{< new-in "0.93.0" >}} + +## GoAT Diagrams (Ascii) + +Hugo supports [GoAT](https://github.com/bep/goat) natively. This means that this code block: + +````txt +```goat + . . . .--- 1 .-- 1 / 1 + / \ | | .---+ .-+ + + / \ .---+---. .--+--. | '--- 2 | '-- 2 / \ 2 + + + | | | | ---+ ---+ + + / \ / \ .-+-. .-+-. .+. .+. | .--- 3 | .-- 3 \ / 3 + / \ / \ | | | | | | | | '---+ '-+ + + 1 2 3 4 1 2 3 4 1 2 3 4 '--- 4 '-- 4 \ 4 + +``` +```` + +Will be rendered as: + +```goat + + . . . .--- 1 .-- 1 / 1 + / \ | | .---+ .-+ + + / \ .---+---. .--+--. | '--- 2 | '-- 2 / \ 2 + + + | | | | ---+ ---+ + + / \ / \ .-+-. .-+-. .+. .+. | .--- 3 | .-- 3 \ / 3 + / \ / \ | | | | | | | | '---+ '-+ + + 1 2 3 4 1 2 3 4 1 2 3 4 '--- 4 '-- 4 \ 4 +``` + +## Mermaid Diagrams + +Hugo currently does not provide default templates for Mermaid diagrams. But you can easily add your own. One way to do it would be to create `layouts/_default/_markup/render-codeblock-mermaid.html`: + +```go-html-template +
+ {{- .Inner | safeHTML }} +
+{{ .Page.Store.Set "hasMermaid" true }} +``` + +And then include this snippet at the bottom of the content template (**Note**: below `.Content` as the render hook is not processed until `.Content` is executed): + +```go-html-template +{{ if .Page.Store.Get "hasMermaid" }} - - +{{ end }} +``` + +With that you can use the `mermaid` language in Markdown code blocks: + ++```` +```mermaid +sequenceDiagram + participant Alice + participant Bob + Alice->>John: Hello John, how are you? + loop Healthcheck + John->>John: Fight against hypochondria + end + Note right of John: Rational thoughts
prevail! + John-->>Alice: Great! + John->>Bob: How about you? + Bob-->>John: Jolly good! +``` ++```` + +## Goat Ascii Diagram Examples + +### Graphics + +```goat + . + 0 3 P * Eye / ^ / + *-------* +y \ +) \ / Reflection + 1 /| 2 /| ^ \ \ \ v + *-------* | | v0 \ v3 --------*-------- + | |4 | |7 | *----\-----* + | *-----|-* +-----> +x / v X \ .-.<-------- o + |/ |/ / / o \ | / | Refraction / \ + *-------* v / \ +-' / \ + 5 6 +z v1 *------------------* v2 | o-----o + v + +``` + +### Complex + +```goat ++-------------------+ ^ .---. +| A Box |__.--.__ __.--> | .-. | | +| | '--' v | * |<--- | | ++-------------------+ '-' | | + Round *---(-. | + .-----------------. .-------. .----------. .-------. | | | + | Mixed Rounded | | | / Diagonals \ | | | | | | + | & Square Corners | '--. .--' / \ |---+---| '-)-' .--------. + '--+------------+-' .--. | '-------+--------' | | | | / Search / + | | | | '---. | '-------' | '-+------' + |<---------->| | | | v Interior | ^ + ' <---' '----' .-----------. ---. .--- v | + .------------------. Diag line | .-------. +---. \ / . | + | if (a > b) +---. .--->| | | | | Curved line \ / / \ | + | obj->fcn() | \ / | '-------' |<--' + / \ | + '------------------' '--' '--+--------' .--. .--. | .-. +Done?+-' + .---+-----. | ^ |\ | | /| .--+ | | \ / + | | | Join \|/ | | Curved | \| |/ | | \ | \ / + | | +----> o --o-- '-' Vertical '--' '--' '-- '--' + .---. + <--+---+-----' | /|\ | | 3 | + v not:line 'quotes' .-' '---' + .-. .---+--------. / A || B *bold* | ^ + | | | Not a dot | <---+---<-- A dash--is not a line v | + '-' '---------+--' / Nor/is this. --- + +``` + +### Process + +```goat + . + .---------. / \ + | START | / \ .-+-------+-. ___________ + '----+----' .-------. A / \ B | |COMPLEX| | / \ .-. + | | END |<-----+CHOICE +----->| | | +--->+ PREPARATION +--->| X | + v '-------' \ / | |PROCESS| | \___________/ '-' + .---------. \ / '-+---+---+-' + / INPUT / \ / + '-----+---' ' + | ^ + v | + .-----------. .-----+-----. .-. + | PROCESS +---------------->| PROCESS |<------+ X | + '-----------' '-----------' '-' +``` + +### File tree + +Created from + +```goat { width=300 color="orange" } +───Linux─┬─Android + ├─Debian─┬─Ubuntu─┬─Lubuntu + │ │ ├─Kubuntu + │ │ ├─Xubuntu + │ │ └─Xubuntu + │ └─Mint + ├─Centos + └─Fedora +``` + + +### Sequence Diagram + + + +```goat { class="w-40" } +┌─────┐ ┌───┐ +│Alice│ │Bob│ +└──┬──┘ └─┬─┘ + │ │ + │ Hello Bob! │ + │───────────>│ + │ │ + │Hello Alice!│ + │<───────────│ +┌──┴──┐ ┌─┴─┐ +│Alice│ │Bob│ +└─────┘ └───┘ + +``` + + +### Flowchart + + + +```goat + _________________ + ╱ ╲ ┌─────┐ + ╱ DO YOU UNDERSTAND ╲____________________________________________________│GOOD!│ + ╲ FLOW CHARTS? ╱yes └──┬──┘ + ╲_________________╱ │ + │no │ + _________▽_________ ______________________ │ + ╱ ╲ ╱ ╲ ┌────┐ │ +╱ OKAY, YOU SEE THE ╲________________╱ ... AND YOU CAN SEE ╲___│GOOD│ │ +╲ LINE LABELED 'YES'? ╱yes ╲ THE ONES LABELED 'NO'? ╱yes└──┬─┘ │ + ╲___________________╱ ╲______________________╱ │ │ + │no │no │ │ + ________▽_________ _________▽__________ │ │ + ╱ ╲ ┌───────────┐ ╱ ╲ │ │ + ╱ BUT YOU SEE THE ╲___│WAIT, WHAT?│ ╱ BUT YOU JUST ╲___ │ │ + ╲ ONES LABELED 'NO'? ╱yes└───────────┘ ╲ FOLLOWED THEM TWICE? ╱yes│ │ │ + ╲__________________╱ ╲____________________╱ │ │ │ + │no │no │ │ │ + ┌───▽───┐ │ │ │ │ + │LISTEN.│ └───────┬───────┘ │ │ + └───┬───┘ ┌──────▽─────┐ │ │ + ┌─────▽────┐ │(THAT WASN'T│ │ │ + │I HATE YOU│ │A QUESTION) │ │ │ + └──────────┘ └──────┬─────┘ │ │ + ┌────▽───┐ │ │ + │SCREW IT│ │ │ + └────┬───┘ │ │ + └─────┬─────┘ │ + │ │ + └─────┬─────┘ + ┌───────▽──────┐ + │LET'S GO DRING│ + └───────┬──────┘ + ┌─────────▽─────────┐ + │HEY, I SHOULD TRY │ + │INSTALLING FREEBSD!│ + └───────────────────┘ + +``` + + +### Table + + + +```goat { class="w-80 dark-blue" } +┌────────────────────────────────────────────────┐ +│ │ +├────────────────────────────────────────────────┤ +│SYNTAX = { PRODUCTION } . │ +├────────────────────────────────────────────────┤ +│PRODUCTION = IDENTIFIER "=" EXPRESSION "." . │ +├────────────────────────────────────────────────┤ +│EXPRESSION = TERM { "|" TERM } . │ +├────────────────────────────────────────────────┤ +│TERM = FACTOR { FACTOR } . │ +├────────────────────────────────────────────────┤ +│FACTOR = IDENTIFIER │ +├────────────────────────────────────────────────┤ +│ | LITERAL │ +├────────────────────────────────────────────────┤ +│ | "[" EXPRESSION "]" │ +├────────────────────────────────────────────────┤ +│ | "(" EXPRESSION ")" │ +├────────────────────────────────────────────────┤ +│ | "{" EXPRESSION "}" . │ +├────────────────────────────────────────────────┤ +│IDENTIFIER = letter { letter } . │ +├────────────────────────────────────────────────┤ +│LITERAL = """" character { character } """" .│ +└────────────────────────────────────────────────┘ +``` diff --cc docs/content/en/content-management/formats.md index a98898821,000000000..ba988c29b mode 100644,000000..100644 --- a/docs/content/en/content-management/formats.md +++ b/docs/content/en/content-management/formats.md @@@ -1,145 -1,0 +1,145 @@@ +--- +title: Content Formats +linkTitle: Content Formats +description: Both HTML and Markdown are supported content formats. +categories: [content management] +keywords: [markdown,asciidoc,pandoc,content format] +menu: + docs: + parent: content-management + weight: 40 +toc: true +weight: 40 +aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/] +--- + +You can put any file type into your `/content` directories, but Hugo uses the `markup` front matter value if set or the file extension (see `Markup identifiers` in the table below) to determine if the markup needs to be processed, e.g.: + +* Markdown converted to HTML +* [Shortcodes](/content-management/shortcodes/) processed +* Layout applied + +## List of content formats + +The current list of content formats in Hugo: + +| Name | Markup identifiers | Comment | +| ------------- | ------------- |-------------| +| Goldmark | md, markdown, goldmark |Note that you can set the default handler of `md` and `markdown` to something else, see [Configure Markup](/getting-started/configuration-markup/).| +|Emacs Org-Mode|org|See [go-org](https://github.com/niklasfasching/go-org).| +|AsciiDoc|asciidocext, adoc, ad|Needs [Asciidoctor][ascii] installed.| +|RST|rst|Needs [RST](https://docutils.sourceforge.io/rst.html) installed.| +|Pandoc|pandoc, pdc|Needs [Pandoc](https://www.pandoc.org/) installed.| +|HTML|html, htm|To be treated as a content file, with layout, shortcodes etc., it must have front matter. If not, it will be copied as-is.| + +The `markup identifier` is fetched from either the `markup` variable in front matter or from the file extension. For markup-related configuration, see [Configure Markup](/getting-started/configuration-markup/). + +## External Helpers + +Some of the formats in the table above need external helpers installed on your PC. For example, for AsciiDoc files, +Hugo will try to call the `asciidoctor` command. This means that you will have to install the associated +tool on your machine to be able to use these formats. + +Hugo passes reasonable default arguments to these external helpers by default: + +- `asciidoctor`: `--no-header-footer -` +- `rst2html`: `--leave-comments --initial-header-level=2` +- `pandoc`: `--mathjax` + - {{% warning "Performance of External Helpers" %}} ++{{% note %}} +Because additional formats are external commands, generation performance will rely heavily on the performance of the external tool you are using. As this feature is still in its infancy, feedback is welcome. - {{% /warning %}} ++{{% /note %}} + +### External Helper AsciiDoc + +[AsciiDoc](https://github.com/asciidoc/asciidoc) implementation EOLs in Jan 2020 and is no longer supported. +AsciiDoc development is being continued under [Asciidoctor](https://github.com/asciidoctor). The format AsciiDoc +remains of course. Please continue with the implementation Asciidoctor. + +### External Helper Asciidoctor + +The Asciidoctor community offers a wide set of tools for the AsciiDoc format that can be installed additionally to Hugo. +[See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/). Make sure that also all +optional extensions like `asciidoctor-diagram` or `asciidoctor-html5s` are installed if required. + +{{% note %}} +External `asciidoctor` command requires Hugo rendering to _disk_ to a specific destination directory. It is required to run Hugo with the command option `--destination`. +{{% /note %}} + +Some [Asciidoctor](https://asciidoctor.org/man/asciidoctor/) parameters can be customized in Hugo: + +Parameter | Comment +--- | --- +backend | Don't change this unless you know what you are doing. +doctype | Currently, the only document type supported in Hugo is `article`. +extensions | Possible extensions are `asciidoctor-html5s`, `asciidoctor-bibtex`, `asciidoctor-diagram`, `asciidoctor-interdoc-reftext`, `asciidoctor-katex`, `asciidoctor-latex`, `asciidoctor-mathematical`, `asciidoctor-question`, `asciidoctor-rouge`. +attributes | Variables to be referenced in your AsciiDoc file. This is a list of variable name/value maps. See [Asciidoctor's attributes](https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#attributes-and-substitutions). +noHeaderOrFooter | Output an embeddable document, which excludes the header, the footer, and everything outside the body of the document. Don't change this unless you know what you are doing. +safeMode | Safe mode level `unsafe`, `safe`, `server` or `secure`. Don't change this unless you know what you are doing. +sectionNumbers | Auto-number section titles. +verbose | Verbosely print processing information and configuration file checks to stderr. +trace | Include backtrace information on errors. +failureLevel | The minimum logging level that triggers a non-zero exit code (failure). + +Hugo provides additional settings that don't map directly to Asciidoctor's CLI options: + +workingFolderCurrent +: Sets the working directory to be the same as that of the AsciiDoc file being processed, so that [include](https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#include-files) will work with relative paths. This setting uses the `asciidoctor` cli parameter `--base-dir` and attribute `outdir=`. For rendering diagrams with [asciidoctor-diagram](https://asciidoctor.org/docs/asciidoctor-diagram/), `workingFolderCurrent` must be set to `true`. + +preserveTOC +: By default, Hugo removes the table of contents generated by Asciidoctor and provides it through the built-in variable [`.TableOfContents`](/content-management/toc/) to enable further customization and better integration with the various Hugo themes. This option can be set to `true` to preserve Asciidoctor's TOC in the generated page. + +Below are all the AsciiDoc related settings in Hugo with their default values: + +{{< code-toggle config="markup.asciidocExt" />}} + +Notice that for security concerns only extensions that do not have path separators (either `\`, `/` or `.`) are allowed. That means that extensions can only be invoked if they are in one's ruby's `$LOAD_PATH` (ie. most likely, the extension has been installed by the user). Any extension declared relative to the website's path will not be accepted. + +Example of how to set extensions and attributes: + +```yml +[markup.asciidocExt] + extensions = ["asciidoctor-html5s", "asciidoctor-diagram"] + workingFolderCurrent = true + [markup.asciidocExt.attributes] + my-base-url = "https://example.com/" + my-attribute-name = "my value" +``` + +In a complex Asciidoctor environment it is sometimes helpful to debug the exact call to your external helper with all +parameters. Run Hugo with `-v`. You will get an output like + +```txt +INFO 2019/12/22 09:08:48 Rendering book-as-pdf.adoc with C:\Ruby26-x64\bin\asciidoctor.bat using asciidoc args [--no-header-footer -r asciidoctor-html5s -b html5s -r asciidoctor-diagram --base-dir D:\prototypes\hugo_asciidoc_ddd\docs -a outdir=D:\prototypes\hugo_asciidoc_ddd\build -] ... +``` + +## Learn Markdown + +Markdown syntax is simple enough to learn in a single sitting. The following are excellent resources to get you up and running: + +* [Daring Fireball: Markdown, John Gruber (Creator of Markdown)][fireball] +* [Markdown Cheatsheet, Adam Pritchard][mdcheatsheet] +* [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial] +* [The Markdown Guide, Matt Cone][mdguide] + +[`emojify` function]: /functions/emojify/ +[ascii]: https://asciidoctor.org/ +[config]: /getting-started/configuration/ +[developer tools]: /tools/ +[emojis]: https://www.webpagefx.com/tools/emoji-cheat-sheet/ +[fireball]: https://daringfireball.net/projects/markdown/ +[gfmtasks]: https://guides.github.com/features/mastering-markdown/#syntax +[helperssource]: https://github.com/gohugoio/hugo/blob/77c60a3440806067109347d04eb5368b65ea0fe8/helpers/general.go#L65 +[hl]: /content-management/syntax-highlighting/ +[hlsc]: /content-management/shortcodes/#highlight +[hugocss]: /css/style.css +[ietf]: https://tools.ietf.org/html/ +[mathjaxdocs]: https://docs.mathjax.org/en/latest/ +[mdcheatsheet]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet +[mdguide]: https://www.markdownguide.org/ +[mdtutorial]: https://www.markdowntutorial.com/ +[org]: https://orgmode.org/ +[pandoc]: https://www.pandoc.org/ +[rest]: https://docutils.sourceforge.io/rst.html +[sc]: /content-management/shortcodes/ +[sct]: /templates/shortcode-templates/ diff --cc docs/content/en/content-management/front-matter.md index bf530518f,000000000..78d3323dd mode 100644,000000..100644 --- a/docs/content/en/content-management/front-matter.md +++ b/docs/content/en/content-management/front-matter.md @@@ -1,241 -1,0 +1,239 @@@ +--- +title: Front Matter - linkTitle: Front Matter +description: Hugo allows you to add front matter in yaml, toml, or json to your content files. - lastmod: 2017-02-24 +categories: [content management] +keywords: ["front matter", "yaml", "toml", "json", "metadata", "archetypes"] +menu: + docs: + parent: content-management + weight: 60 +toc: true +weight: 60 +aliases: [/content/front-matter/] +--- + +**Front matter** allows you to keep metadata attached to an instance of a [content type]---i.e., embedded inside a content file---and is one of the many features that gives Hugo its strength. + +{{< youtube Yh2xKRJGff4 >}} + +## Front Matter Formats + +Hugo supports four formats for front matter, each with their own identifying tokens. + +TOML +: identified by opening and closing `+++`. + +YAML +: identified by opening and closing `---`. + +JSON +: a single JSON object surrounded by '`{`' and '`}`', followed by a new line. + +ORG +: a group of Org mode keywords in the format '`#+KEY: VALUE`'. Any line that does not start with `#+` ends the front matter section. + Keyword values can be either strings (`#+KEY: VALUE`) or a whitespace separated list of strings (`#+KEY[]: VALUE_1 VALUE_2`). + +### Example + +{{< code-toggle >}} +title = "spf13-vim 3.0 release and new website" +description = "spf13-vim is a cross platform distribution of vim plugins and resources for Vim." +tags = [ ".vimrc", "plugins", "spf13-vim", "vim" ] +date = "2012-04-06" +categories = [ + "Development", + "VIM" +] +slug = "spf13-vim-3-0-release-and-new-website" +{{< /code-toggle >}} + +## Front Matter Variables + +### Predefined + +There are a few predefined variables that Hugo is aware of. See [Page Variables][pagevars] for how to call many of these predefined variables in your templates. + +aliases - : an array of one or more aliases (e.g., old published paths of renamed content) that will be created in the output directory structure . See [Aliases][aliases] for details. ++: An array of one or more aliases (e.g., old published paths of renamed content) that will be created in the output directory structure . See [Aliases][aliases] for details. + +audio - : an array of paths to audio files related to the page; used by the `opengraph` [internal template](/templates/internal) to populate `og:audio`. ++: An array of paths to audio files related to the page; used by the `opengraph` [internal template](/templates/internal) to populate `og:audio`. + +cascade - : a map of Front Matter keys whose values are passed down to the page's descendants unless overwritten by self or a closer ancestor's cascade. See [Front Matter Cascade](#front-matter-cascade) for details. ++: A map of front matter keys whose values are passed down to the page's descendants unless overwritten by self or a closer ancestor's cascade. See [Front Matter Cascade](#front-matter-cascade) for details. + +date - : the datetime assigned to this page. This is usually fetched from the `date` field in front matter, but this behavior is configurable. ++: The datetime assigned to this page. This is usually fetched from the `date` field in front matter, but this behavior is configurable. + +description - : the description for the content. ++: The description for the content. + +draft - : if `true`, the content will not be rendered unless the `--buildDrafts` flag is passed to the `hugo` command. ++: If `true`, the content will not be rendered unless the `--buildDrafts` flag is passed to the `hugo` command. + +expiryDate - : the datetime at which the content should no longer be published by Hugo; expired content will not be rendered unless the `--buildExpired` flag is passed to the `hugo` command. ++: The datetime at which the content should no longer be published by Hugo; expired content will not be rendered unless the `--buildExpired` flag is passed to the `hugo` command. + +headless - : if `true`, sets a leaf bundle to be [headless][headless-bundle]. ++: If `true`, sets a leaf bundle to be [headless][headless-bundle]. + +images - : an array of paths to images related to the page; used by [internal templates](/templates/internal) such as `_internal/twitter_cards.html`. ++: An array of paths to images related to the page; used by [internal templates](/templates/internal) such as `_internal/twitter_cards.html`. + +isCJKLanguage - : if `true`, Hugo will explicitly treat the content as a CJK language; both `.Summary` and `.WordCount` work properly in CJK languages. ++: If `true`, Hugo will explicitly treat the content as a CJK language; both `.Summary` and `.WordCount` work properly in CJK languages. + +keywords - : the meta keywords for the content. ++: The meta keywords for the content. + +layout - : the layout Hugo should select from the [lookup order][lookup] when rendering the content. If a `type` is not specified in the front matter, Hugo will look for the layout of the same name in the layout directory that corresponds with a content's section. See [Content Types][content type]. ++: The layout Hugo should select from the [lookup order][lookup] when rendering the content. If a `type` is not specified in the front matter, Hugo will look for the layout of the same name in the layout directory that corresponds with a content's section. See [Content Types][content type]. + +lastmod - : the datetime at which the content was last modified. ++: The datetime at which the content was last modified. + +linkTitle - : used for creating links to content; if set, Hugo defaults to using the `linktitle` before the `title`. Hugo can also [order lists of content by `linktitle`][bylinktitle]. ++: Used for creating links to content; if set, Hugo defaults to using the `linktitle` before the `title`. Hugo can also [order lists of content by `linktitle`][bylinktitle]. + +markup +: **experimental**; specify `"rst"` for reStructuredText (requires`rst2html`) or `"md"` (default) for Markdown. + +outputs - : allows you to specify output formats specific to the content. See [output formats][outputs]. ++: Allows you to specify output formats specific to the content. See [output formats][outputs]. + +publishDate - : if in the future, content will not be rendered unless the `--buildFuture` flag is passed to `hugo`. ++: If in the future, content will not be rendered unless the `--buildFuture` flag is passed to `hugo`. + +resources - : used for configuring page bundle resources. See [Page Resources][page-resources]. ++: Used for configuring page bundle resources. See [Page Resources][page-resources]. + +series - : an array of series this page belongs to, as a subset of the `series` [taxonomy](/content-management/taxonomies/); used by the `opengraph` [internal template](/templates/internal) to populate `og:see_also`. ++: An array of series this page belongs to, as a subset of the `series` [taxonomy](/content-management/taxonomies/); used by the `opengraph` [internal template](/templates/internal) to populate `og:see_also`. + +slug - : appears as the tail of the output URL. A value specified in front matter will override the segment of the URL based on the filename. ++: Overrides the last segment of the URL path. Not applicable to section pages. See [URL Management](/content-management/urls/#slug) for details. + +summary - : text used when providing a summary of the article in the `.Summary` page variable; details available in the [content-summaries](/content-management/summaries/) section. ++: Text used when providing a summary of the article in the `.Summary` page variable; details available in the [content-summaries](/content-management/summaries/) section. + +title - : the title for the content. ++: The title for the content. + +type - : the type of the content; this value will be automatically derived from the directory (i.e., the [section]) if not specified in front matter. ++: The type of the content; this value will be automatically derived from the directory (i.e., the [section]) if not specified in front matter. + +url - : the full path to the content from the web root. It makes no assumptions about the path of the content file. See [URL Management](/content-management/urls/#set-url-in-front-matter). ++: Overrides the entire URL path. Applicable to regular pages and section pages. See [URL Management](/content-management/urls/#url) for details. + +videos - : an array of paths to videos related to the page; used by the `opengraph` [internal template](/templates/internal) to populate `og:video`. ++: An array of paths to videos related to the page; used by the `opengraph` [internal template](/templates/internal) to populate `og:video`. + +weight +: used for [ordering your content in lists][ordering]. Lower weight gets higher precedence. So content with lower weight will come first. If set, weights should be non-zero, as 0 is interpreted as an *unset* weight. + +\ - : field name of the *plural* form of the index. See `tags` and `categories` in the above front matter examples. *Note that the plural form of user-defined taxonomies cannot be the same as any of the predefined front matter variables.* ++: Field name of the *plural* form of the index. See `tags` and `categories` in the above front matter examples. *Note that the plural form of user-defined taxonomies cannot be the same as any of the predefined front matter variables.* + - {{% note "Hugo's Default URL Destinations" %}} ++{{% note %}} +If neither `slug` nor `url` is present and [permalinks are not configured otherwise in your site `config` file](/content-management/urls/#permalinks), Hugo will use the filename of your content to create the output URL. See [Content Organization](/content-management/organization) for an explanation of paths in Hugo and [URL Management](/content-management/urls/) for ways to customize Hugo's default behaviors. +{{% /note %}} + +### User-Defined + +You can add fields to your front matter arbitrarily to meet your needs. These user-defined key-values are placed into a single `.Params` variable for use in your templates. + +The following fields can be accessed via `.Params.include_toc` and `.Params.show_comments`, respectively. The [Variables] section provides more information on using Hugo's page- and site-level variables in your templates. + - {{< code-toggle copy="false" >}} ++{{< code-toggle copy=false >}} +include_toc: true +show_comments: false +{{}} + +## Front Matter Cascade + +Any node or section can pass down to descendants a set of Front Matter values as long as defined underneath the reserved `cascade` Front Matter key. + +### Target Specific Pages + +The `cascade` block can be a slice with a optional `_target` keyword, allowing for multiple `cascade` values targeting different page sets. + - {{< code-toggle copy="false" >}} ++{{< code-toggle copy=false >}} +title ="Blog" +[[cascade]] +background = "yosemite.jpg" +[cascade._target] +path="/blog/**" +lang="en" +kind="page" +[[cascade]] +background = "goldenbridge.jpg" +[cascade._target] +kind="section" +{{}} + +Keywords available for `_target`: + +path +: A [Glob](https://github.com/gobwas/glob) pattern matching the content path below /content. Expects Unix-styled slashes. Note that this is the virtual path, so it starts at the mount root. The matching supports double-asterisks so you can match for patterns like `/blog/*/**` to match anything from the third level and down. + +kind +: A Glob pattern matching the Page's Kind(s), e.g. "{home,section}". + +lang +: A Glob pattern matching the Page's language, e.g. "{en,sv}". + +environment +: A Glob pattern matching the build environment, e.g. "{production,development}" + +Any of the above can be omitted. + +### Example + +In `content/blog/_index.md` + - {{< code-toggle copy="false" >}} ++{{< code-toggle copy=false >}} +title: Blog +cascade: + banner: images/typewriter.jpg +{{}} + +With the above example the Blog section page and its descendants will return `images/typewriter.jpg` when `.Params.banner` is invoked unless: + +- Said descendant has its own `banner` value set +- Or a closer ancestor node has its own `cascade.banner` value set. + +## Order Content Through Front Matter + +You can assign content-specific `weight` in the front matter of your content. These values are especially useful for [ordering][ordering] in list views. You can use `weight` for ordering of content and the convention of [`_weight`][taxweight] for ordering content within a taxonomy. See [Ordering and Grouping Hugo Lists][lists] to see how `weight` can be used to organize your content in list views. + +## Override Global Markdown Configuration + +It's possible to set some options for Markdown rendering in a content's front matter as an override to the [Rendering options set in your project configuration][config]. + +## Front Matter Format Specs + +- [TOML Spec][toml] +- [YAML Spec][yaml] +- [JSON Spec][json] + +[variables]: /variables/ +[aliases]: /content-management/urls/#aliases +[archetype]: /content-management/archetypes/ +[bylinktitle]: /templates/lists/#by-link-title +[config]: /getting-started/configuration/ "Hugo documentation for site configuration" +[content type]: /content-management/types/ +[contentorg]: /content-management/organization/ +[headless-bundle]: /content-management/page-bundles/#headless-bundle +[json]: https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf "Specification for JSON, JavaScript Object Notation" +[lists]: /templates/lists/#order-content "See how to order content in list pages; for example, templates that look to specific _index.md for content and front matter." +[lookup]: /templates/lookup-order/ "Hugo traverses your templates in a specific order when rendering content to allow for DRYer templating." +[ordering]: /templates/lists/ "Hugo provides multiple ways to sort and order your content in list templates" +[outputs]: /templates/output-formats/ "With the release of v22, you can output your content to any text format using Hugo's familiar templating" +[page-resources]: /content-management/page-resources/ +[pagevars]: /variables/page/ +[section]: /content-management/sections/ +[taxweight]: /content-management/taxonomies/ +[toml]: https://github.com/toml-lang/toml "Specification for TOML, Tom's Obvious Minimal Language" +[urls]: /content-management/urls/ +[variables]: /variables/ +[yaml]: https://yaml.org/spec/ "Specification for YAML, YAML Ain't Markup Language" diff --cc docs/content/en/content-management/image-processing/index.md index 3f71b4244,000000000..0043f97b0 mode 100644,000000..100644 --- a/docs/content/en/content-management/image-processing/index.md +++ b/docs/content/en/content-management/image-processing/index.md @@@ -1,477 -1,0 +1,476 @@@ +--- +title: Image Processing - linkTitle: Image Processing +description: Resize, crop, rotate, filter, and convert images. +categories: [content management] +keywords: [resources, images] +menu: + docs: + parent: content-management + weight: 90 +toc: true +weight: 90 +--- +## Image Resources + +To process an image, you must access the image as either a page resource or a global resource. + +### Page Resources + +A page resource is a file within a [page bundle]. A page bundle is a directory with an `index.md` or `_index.md` file at its root. + +```text +content/ +└── posts/ + └── post-1/ <-- page bundle + ├── index.md + └── sunset.jpg <-- page resource +``` + +### Global Resources + +A global resource is a file: + +- Within the `assets` directory, or +- Within any directory [mounted] to the `assets` directory, or +- Located on a remote server accessible via `http` or `https` + +```text +assets/ +└── images/ + └── sunset.jpg <-- global resource +``` + +To access a local image as a global resource: + +```go-html-template +{{ $image := resources.Get "images/sunset.jpg" }} +``` + +To access a remote image as a global resource: + +```go-html-template +{{ $image := resources.GetRemote "https://gohugo.io/img/hugo-logo.png" }} +``` + +## Image Rendering + +Once you have accessed an image as either a page resource or a global resource, render it in your templates using the `Permalink`, `RelPermalink`, `Width`, and `Height` properties. + +Example 1: Throws an error if the resource is not found. + +```go-html-template +{{ $image := .Resources.GetMatch "sunset.jpg" }} + +``` + +Example 2: Skips image rendering if the resource is not found. + +```go-html-template +{{ $image := .Resources.GetMatch "sunset.jpg" }} +{{ with $image }} + +{{ end }} +``` + +Example 3: A more concise way to skip image rendering if the resource is not found. + +```go-html-template +{{ with .Resources.GetMatch "sunset.jpg" }} + +{{ end }} +``` + +## Image Processing Methods + +The `image` resource implements the [`Resize`], [`Fit`], [`Fill`], [`Crop`], [`Filter`], [`Colors`] and [`Exif`] methods. + +{{% note %}} +Metadata (Exif, IPTC, XMP, etc.) is not preserved during image transformation. Use the [`Exif`] method with the _original_ image to extract Exif metadata from JPEG or TIFF images. +{{% /note %}} + +### Resize + +Resize an image to the specified width and/or height. + +If you specify both width and height, the resulting image will be disproportionally scaled unless the original image has the same aspect ratio. + +```go-html-template +{{/* Resize to a width of 600px and preserve aspect ratio */}} +{{ $image := $image.Resize "600x" }} + +{{/* Resize to a height of 400px and preserve aspect ratio */}} +{{ $image := $image.Resize "x400" }} + +{{/* Resize to a width of 600px and a height of 400px */}} +{{ $image := $image.Resize "600x400" }} +``` + +### Fit + +Downscale an image to fit the given dimensions while maintaining aspect ratio. You must provide both width and height. + +```go-html-template +{{ $image := $image.Fit "600x400" }} +``` + +### Fill + +Crop and resize an image to match the given dimensions. You must provide both width and height. Use the [`anchor`] option to change the crop box anchor point. + +```go-html-template +{{ $image := $image.Fill "600x400" }} +``` + +### Crop + +Crop an image to match the given dimensions without resizing. You must provide both width and height. Use the [`anchor`] option to change the crop box anchor point. + +```go-html-template +{{ $image := $image.Crop "600x400" }} +``` + +### Filter + +Apply one or more [filters] to an image. + +```go-html-template +{{ $image := $image.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} +``` + +Write this in a more functional style using pipes. Hugo applies the filters in the order given. + +```go-html-template +{{ $image := $image | images.Filter (images.GaussianBlur 6) (images.Pixelate 8) }} +``` + +Sometimes it can be useful to create the filter chain once and then reuse it. + +```go-html-template +{{ $filters := slice (images.GaussianBlur 6) (images.Pixelate 8) }} +{{ $image1 := $image1.Filter $filters }} +{{ $image2 := $image2.Filter $filters }} +``` + +### Colors + +{{< new-in "0.104.0" >}} + +`.Colors` returns a slice of hex strings with the dominant colors in the image using a simple histogram method. + +```go-html-template +{{ $colors := $image.Colors }} +``` + +This method is fast, but if you also scale down your images, it would be good for performance to extract the colors from the scaled down image. + + +### Exif + +Provides an [Exif] object containing image metadata. + +You may access Exif data in JPEG and TIFF images. To prevent errors when processing images without Exif data, wrap the access in a [`with`] statement. + +```go-html-template +{{ with $image.Exif }} + Date: {{ .Date }} + Lat/Long: {{ .Lat }}/{{ .Long }} + Tags: + {{ range $k, $v := .Tags }} + TAG: {{ $k }}: {{ $v }} + {{ end }} +{{ end }} +``` + +You may also access Exif fields individually, using the [`lang.FormatNumber`] function to format the fields as needed. + +```go-html-template +{{ with $image.Exif }} +
    + {{ with .Date }}
  • Date: {{ .Format "January 02, 2006" }}
  • {{ end }} + {{ with .Tags.ApertureValue }}
  • Aperture: {{ lang.FormatNumber 2 . }}
  • {{ end }} + {{ with .Tags.BrightnessValue }}
  • Brightness: {{ lang.FormatNumber 2 . }}
  • {{ end }} + {{ with .Tags.ExposureTime }}
  • Exposure Time: {{ . }}
  • {{ end }} + {{ with .Tags.FNumber }}
  • F Number: {{ . }}
  • {{ end }} + {{ with .Tags.FocalLength }}
  • Focal Length: {{ . }}
  • {{ end }} + {{ with .Tags.ISOSpeedRatings }}
  • ISO Speed Ratings: {{ . }}
  • {{ end }} + {{ with .Tags.LensModel }}
  • Lens Model: {{ . }}
  • {{ end }} +
+{{ end }} +``` + +#### Exif Variables + +.Date +: Image creation date/time. Format with the [time.Format] function. + +.Lat +: GPS latitude in degrees. + +.Long +: GPS longitude in degrees. + +.Tags +: A collection of the available Exif tags for this image. You may include or exclude specific tags from this collection in the [site configuration](#exif-data). + +## Image Processing Options + +The [`Resize`], [`Fit`], [`Fill`], and [`Crop`] methods accept a space-separated, case-insensitive list of options. The order of the options within the list is irrelevant. + +### Dimensions + +With the [`Resize`] method you must specify width, height, or both. The [`Fit`], [`Fill`], and [`Crop`] methods require both width and height. All dimensions are in pixels. + +```go-html-template +{{ $image := $image.Resize "600x" }} +{{ $image := $image.Resize "x400" }} +{{ $image := $image.Resize "600x400" }} +{{ $image := $image.Fit "600x400" }} +{{ $image := $image.Fill "600x400" }} +{{ $image := $image.Crop "600x400" }} +``` + +### Rotation + +Rotates an image counter-clockwise by the given angle. Hugo performs rotation _before_ scaling. For example, if the original image is 600x400 and you wish to rotate the image 90 degrees counter-clockwise while scaling it by 50%: + +```go-html-template +{{ $image = $image.Resize "200x r90" }} +``` + +In the example above, the width represents the desired width _after_ rotation. + +To rotate an image without scaling, use the dimensions of the original image: + +```go-html-template +{{ with .Resources.GetMatch "sunset.jpg" }} + {{ with .Resize (printf "%dx%d r90" .Height .Width) }} + + {{ end }} +{{ end }} +``` + +In the example above, on the second line, we have reversed width and height to reflect the desired dimensions _after_ rotation. + +### Anchor + +When using the [`Crop`] or [`Fill`] method, the _anchor_ determines the placement of the crop box. You may specify `TopLeft`, `Top`, `TopRight`, `Left`, `Center`,`Right`, `BottomLeft`, `Bottom`, `BottomRight`, or `Smart`. + +The default value is `Smart`, which uses [Smartcrop] image analysis to determine the optimal placement of the crop box. You may override the default value in the [site configuration]. + +For example, if you have a 400x200 image with a bird in the upper left quadrant, you can create a 200x100 thumbnail containing the bird: + +```go-html-template +{{ $image.Crop "200x100 TopLeft" }} +``` + +If you apply [rotation](#rotation) when using the [`Crop`] or [`Fill`] method, specify the anchor relative to the rotated image. + +### Target Format + +By default, Hugo encodes the image in the source format. You may convert the image to another format by specifying `bmp`, `gif`, `jpeg`, `jpg`, `png`, `tif`, `tiff`, or `webp`. + +```go-html-template +{{ $image.Resize "600x webp" }} +``` + +To convert an image without scaling, use the dimensions of the original image: + +```go-html-template +{{ with .Resources.GetMatch "sunset.jpg" }} + {{ with .Resize (printf "%dx%d webp" .Width .Height) }} + + {{ end }} +{{ end }} +``` + +### Quality + +Applicable to JPEG and WebP images, the `q` value determines the quality of the converted image. Higher values produce better quality images, while lower values produce smaller files. Set this value to a whole number between 1 and 100, inclusive. + +The default value is 75. You may override the default value in the [site configuration]. + +```go-html-template +{{ $image.Resize "600x webp q50" }} +``` + +### Hint + + + +Applicable to WebP images, this option corresponds to a set of predefined encoding parameters. + +Value|Example +:--|:-- +`drawing`|Hand or line drawing with high-contrast details +`icon`|Small colorful image +`photo`|Outdoor photograph with natural lighting +`picture`|Indoor photograph such as a portrait +`text`|Image that is primarily text + +The default value is `photo`. You may override the default value in the [site configuration]. + +```go-html-template +{{ $image.Resize "600x webp picture" }} +``` + +### Background Color + +When converting an image from a format that supports transparency (e.g., PNG) to a format that does _not_ support transparency (e.g., JPEG), you may specify the background color of the resulting image. + +Use either a 3-digit or a 6-digit hexadecimal color code (e.g., `#00f` or `#0000ff`). + +The default value is `#ffffff` (white). You may override the default value in the [site configuration]. + +```go-html-template +{{ $image.Resize "600x jpg #b31280" }} +``` + +### Resampling Filter + +You may specify the resampling filter used when resizing an image. Commonly used resampling filters include: + +Filter|Description +:--|:-- +`Box`|Simple and fast averaging filter appropriate for downscaling +`Lanczos`|High-quality resampling filter for photographic images yielding sharp results +`CatmullRom`|Sharp cubic filter that is faster than the Lanczos filter while providing similar results +`MitchellNetravali`|Cubic filter that produces smoother results with less ringing artifacts than CatmullRom +`Linear`|Bilinear resampling filter, produces smooth output, faster than cubic filters +`NearestNeighbor`|Fastest resampling filter, no antialiasing + +The default value is `Box`. You may override the default value in the [site configuration]. + +```go-html-template +{{ $image.Resize "600x400 Lanczos" }} +``` + +See [github.com/disintegration/imaging] for the complete list of resampling filters. If you wish to improve image quality at the expense of performance, you may wish to experiment with the alternative filters. + +## Image Processing Examples + +_The photo of the sunset used in the examples below is Copyright [Bjørn Erik Pedersen](https://commons.wikimedia.org/wiki/User:Bep) (Creative Commons Attribution-Share Alike 4.0 International license)_ + +{{< imgproc sunset Resize "300x" />}} + +{{< imgproc sunset Fill "90x120 left" />}} + +{{< imgproc sunset Fill "90x120 right" />}} + +{{< imgproc sunset Fit "90x90" />}} + +{{< imgproc sunset Crop "250x250 center" />}} + +{{< imgproc sunset Resize "300x q10" />}} + +This is the shortcode used to generate the examples above: + +{{< code file="layouts/shortcodes/imgproc.html" >}} +{{< readfile file="layouts/shortcodes/imgproc.html" >}} +{{< /code >}} + +Call the shortcode from your Markdown like this: + +```go-html-template +{{}} +``` + +{{% note %}} +Note the self-closing shortcode syntax above. You may call the `imgproc` shortcode with or without **inner content**. +{{% /note %}} + +## Imaging Configuration + +### Processing Options + +Define an `imaging` section in your site configuration to set the default [image processing options](#image-processing-options). + +{{< code-toggle file="config" copy=true >}} +[imaging] +resampleFilter = "Box" +quality = 75 +hint = "photo" +anchor = "Smart" +bgColor = "#ffffff" +{{< /code-toggle >}} + +anchor +: See image processing options: [anchor](#anchor). + +bgColor +: See image processing options: [background color](#background-color). + +hint +: See image processing options: [hint](#hint). + +quality +: See image processing options: [quality](#quality). + +resampleFilter +: See image processing options: [resampling filter](#resampling-filter). + +### Exif Data + +Define an `imaging.exif` section in your site configuration to control the availability of Exif data. + +{{< code-toggle file="config" copy=true >}} +[imaging.exif] +includeFields = "" +excludeFields = "" +disableDate = false +disableLatLong = false +{{< /code-toggle >}} + +disableDate +: Hugo extracts the image creation date/time into `.Date`. Set this to `true` to disable. Default is `false`. + +disableLatLong +: Hugo extracts the GPS latitude and longitude into `.Lat` and `.Long`. Set this to `true` to disable. Default is `false`. + +excludeFields +: Regular expression matching the Exif tags to exclude from the `.Tags` collection. Default is `""`. + +includeFields +: Regular expression matching the Exif tags to include in the `.Tags` collection. Default is `""`. To include all available tags, set this value to `".*"`. + +{{% note %}} +To improve performance and decrease cache size, if you set neither `excludeFields` nor `includeFields`, Hugo excludes the following tags: `ColorSpace`, `Contrast`, `Exif`, `Exposure[M|P|B]`, `Flash`, `GPS`, `JPEG`, `Metering`, `Resolution`, `Saturation`, `Sensing`, `Sharp`, and `WhiteBalance`. +{{% /note %}} + +## Smart Cropping of Images + +By default, Hugo uses the [Smartcrop] library when cropping images with the `Crop` or`Fill` methods. You can set the anchor point manually, but in most cases the `Smart` option will make a good choice. + +Examples using the sunset image from above: + +{{< imgproc sunset Fill "200x200 smart" />}} + +{{< imgproc sunset Crop "200x200 smart" />}} + +## Image Processing Performance Consideration + +Hugo caches processed images in the `resources` directory. If you include this directory in source control, Hugo will not have to regenerate the images in a CI/CD workflow (e.g., GitHub Pages, GitLab Pages, Netlify, etc.). This results in faster builds. + +If you change image processing methods or options, or if you rename or remove images, the `resources` directory will contain unused images. To remove the unused images, perform garbage collection with: + +```bash +hugo --gc +``` + - [`anchor`]: {{< relref "content-management/image-processing#anchor" >}} - [`lang.FormatNumber`]: {{< relref "functions/lang#langformatnumber" >}} - [Exif]: - [filters]: {{< relref "functions/images" >}} ++[time.Format]: /functions/dateformat ++[`anchor`]: /content-management/image-processing#anchor ++[mounted]: /hugo-modules/configuration#module-config-mounts ++[page bundle]: /content-management/page-bundles ++[`lang.FormatNumber`]: /functions/lang ++[filters]: /functions/images +[github.com/disintegration/imaging]: - [mounted]: {{< relref "hugo-modules/configuration#module-config-mounts">}} - [page bundle]: {{< relref "content-management/page-bundles" >}} +[Smartcrop]: - [time.Format]: {{< relref "functions/dateformat" >}} ++[Exif]: +[`Colors`]: #colors +[`Crop`]: #crop +[`Exif`]: #exif +[`Fill`]: #fill +[`Filter`]: #filter +[`Fit`]: #fit +[`Resize`]: #resize +[site configuration]: #processing-options +[`with`]: /functions/with/ diff --cc docs/content/en/content-management/menus.md index b9fab2ca4,000000000..369938aba mode 100644,000000..100644 --- a/docs/content/en/content-management/menus.md +++ b/docs/content/en/content-management/menus.md @@@ -1,129 -1,0 +1,225 @@@ +--- +title: Menus - linkTitle: Menus - description: Hugo has a simple yet powerful menu system. ++description: Create menus by defining entries, localizing each entry, and rendering the resulting data structure. +categories: [content management] +keywords: [menus] +menu: + docs: + parent: content-management + weight: 190 +toc: true +weight: 190 +aliases: [/extras/menus/] +--- + - {{% note "Lazy Blogger"%}} - If all you want is a simple menu for your sections, see the ["Section Menu for Lazy Bloggers" in Menu Templates](/templates/menu-templates/#section-menu-for-lazy-bloggers). - {{% /note %}} ++## Overview ++ ++To create a menu for your site: + - You can do this: ++1. Define the menu entries ++2. [Localize] each entry ++3. Render the menu with a [template] + - * Place content in one or many menus - * Handle nested menus with unlimited depth - * Create menu entries without being attached to any content - * Distinguish active element (and active branch) ++Create multiple menus, either flat or nested. For example, create a main menu for the header, and a separate menu for the footer. + - ## What is a Menu in Hugo? ++There are three ways to define menu entries: + - A **menu** is a named array of menu entries accessible by name via the [`.Site.Menus` site variable][sitevars]. For example, you can access your site's `main` menu via `.Site.Menus.main`. ++1. Automatically ++1. In front matter ++1. In site configuration + - {{% note "Menus on Multilingual Sites" %}} - If you make use of the [multilingual feature](/content-management/multilingual/), you can define language-independent menus. ++{{% note %}} ++Although you can use these methods in combination when defining a menu, the menu will be easier to conceptualize and maintain if you use one method throughout the site. +{{% /note %}} + - See the [Menu Entry Properties][me-props] for all the variables and functions related to a menu entry. ++## Define automatically + - ## Add content to menus ++To automatically define menu entries for each top-level section of your site, enable the section pages menu in your site configuration. + - Hugo allows you to add content to a menu via the content's [front matter](/content-management/front-matter/). ++{{< code-toggle file="config" copy=false >}} ++sectionPagesMenu = "main" ++{{< /code-toggle >}} + - ### Simple ++This creates a menu structure that you can access with `site.Menus.main` in your templates. See [menu templates] for details. + - If all you need to do is add an entry to a menu, the simple form works well. ++## Define in front matter + - #### A Single Menu ++To add a page to the "main" menu: + - {{< code-toggle >}} - menu: "main" ++{{< code-toggle file="content/about.md" copy=false fm=true >}} ++title = 'About' ++menu = 'main' +{{< /code-toggle >}} + - #### Multiple Menus ++Access the entry with `site.Menus.main` in your templates. See [menu templates] for details. ++ ++To add a page to the "main" and "footer" menus: + - {{< code-toggle >}} - menu: ["main", "footer"] ++{{< code-toggle file="content/contact.md" copy=false fm=true >}} ++title = 'Contact' ++menu = ['main','footer'] +{{< /code-toggle >}} + - #### Advanced ++Access the entry with `site.Menus.main` and `site.Menus.footer` in your templates. See [menu templates] for details. + - {{< code-toggle >}} - menu: - docs: - parent: 'extras' - weight: 20 ++### Properties {#properties-front-matter} ++ ++Use these properties when defining menu entries in front matter: ++ ++identifier ++: (`string`) Required when two or more menu entries have the same `name`, or when localizing the `name` using translation tables. Must start with a letter, followed by letters, digits, or underscores. ++ ++name ++: (`string`) The text to display when rendering the menu entry. ++ ++params ++: (`map`) User-defined properties for the menu entry. ++ ++parent ++: (`string`) The `identifier` of the parent menu entry. If `identifier` is not defined, use `name`. Required for child entries in a nested menu. ++ ++post ++: (`string`) The HTML to append when rendering the menu entry. ++ ++pre ++: (`string`) The HTML to prepend when rendering the menu entry. ++ ++title ++: (`string`) The HTML `title` attribute of the rendered menu entry. ++ ++weight ++: (`int`) A non-zero integer indicating the entry's position relative the root of the menu, or to its parent for a child entry. Lighter entries float to the top, while heavier entries sink to the bottom. ++ ++### Example {#example-front-matter} ++ ++This front matter menu entry demonstrates some of the available properties: ++ ++{{< code-toggle file="content/products/software.md" copy=false fm=true >}} ++title = 'Software' ++[menu.main] ++parent = 'Products' ++weight = 20 ++pre = '' ++[menu.main.params] ++class = 'center' +{{< /code-toggle >}} + - ## Add Non-content Entries to a Menu ++Access the entry with `site.Menus.main` in your templates. See [menu templates] for details. ++ + - You can also add entries to menus that aren’t attached to a piece of content. This takes place in your Hugo project's [`config` file][config] (see [Menu Entry Properties][me-props] for full details of available variables). ++## Define in site configuration + - Here’s an example snippet pulled from a configuration file: ++To define entries for the "main" menu: + - {{< code-toggle file="config" >}} ++{{< code-toggle file="config" copy=false >}} +[[menu.main]] - name = "about hugo" - pre = "" - weight = -110 - identifier = "about" - url = "/about/" ++name = 'Home' ++pageRef = '/' ++weight = 10 ++ +[[menu.main]] - name = "getting started" - pre = "" - post = "New!" - weight = -100 - url = "/getting-started/" ++name = 'Products' ++pageRef = '/products' ++weight = 20 ++ ++[[menu.main]] ++name = 'Services' ++pageRef = '/services' ++weight = 30 ++{{< /code-toggle >}} ++ ++This creates a menu structure that you can access with `site.Menus.main` in your templates. See [menu templates] for details. ++ ++To define entries for the "footer" menu: ++ ++{{< code-toggle file="config" copy=false >}} ++[[menu.footer]] ++name = 'Terms' ++pageRef = '/terms' ++weight = 10 ++ ++[[menu.footer]] ++name = 'Privacy' ++pageRef = '/privacy' ++weight = 20 +{{< /code-toggle >}} + ++This creates a menu structure that you can access with `site.Menus.footer` in your templates. See [menu templates] for details. ++ ++### Properties {#properties-site-configuration} ++ +{{% note %}} - The URLs must be relative to the context root. If the `baseURL` is `https://example.com/mysite/`, then the URLs in the menu must not include the context root `mysite`. Using an absolute URL will override the baseURL. If the value used for `URL` in the above example is `https://subdomain.example.com/`, the output will be `https://subdomain.example.com`. ++The [properties available to entries defined in front matter] are also available to entries defined in site configuration. ++ ++[properties available to entries defined in front matter]: /content-management/menus/#properties-front-matter +{{% /note %}} + - ## Nesting ++Each menu entry defined in site configuration requires two or more properties: + - All nesting of content is done via the `parent` field. ++- Specify `name` and `pageRef` for internal links ++- Specify `name` and `url` for external links + - The parent of an entry should be the identifier of another entry. The identifier should be unique (within a menu). ++pageRef ++: (`string`) The file path of the target page, relative to the `content` directory. Omit language code and file extension. Required for *internal* links. + - The following order is used to determine an Identifier: ++Kind|pageRef ++:--|:-- ++home|`/` ++page|`/books/book-1` ++section|`/books` ++taxonomy|`/tags` ++term|`/tags/foo` + - `.Name > .LinkTitle > .Title` ++url ++: (`string`) Required for *external* links. + - This means that `.Title` will be used unless `.LinkTitle` is present, etc. In practice, `.Name` and `.Identifier` are only used to structure relationships and therefore never displayed. ++### Example {#example-site-configuration} + - In this example, the top level of the menu is defined in your [site `config` file][config]. All content entries are attached to one of these entries via the `.Parent` field. ++This nested menu demonstrates some of the available properties: + - ## Params ++{{< code-toggle file="config" copy=false >}} ++[[menu.main]] ++name = 'Products' ++pageRef = '/products' ++weight = 10 + - You can also add user-defined content to menu items via the `params` field. ++[[menu.main]] ++name = 'Hardware' ++pageRef = '/products/hardware' ++parent = 'Products' ++weight = 1 + - A common use case is to define a custom param to add a css class to a specific menu item. ++[[menu.main]] ++name = 'Software' ++pageRef = '/products/software' ++parent = 'Products' ++weight = 2 ++ ++[[menu.main]] ++name = 'Services' ++pageRef = '/services' ++weight = 20 + - {{< code-toggle file="config" >}} +[[menu.main]] - name = "about hugo" - pre = "" - weight = -110 - identifier = "about" - url = "/about/" - [menu.main.params] - class = "highlight-menu-item" - {{}} - - ## Render Menus - - See [Menu Templates](/templates/menu-templates/) for information on how to render your site menus within your templates. - - [config]: /getting-started/configuration/ - [multilingual]: /content-management/multilingual/ - [sitevars]: /variables/ - [me-props]: /variables/menus/ ++name = 'Hugo' ++pre = '' ++url = 'https://gohugo.io/' ++weight = 30 ++[menu.main.params] ++rel = 'external' ++{{< /code-toggle >}} ++ ++This creates a menu structure that you can access with `site.Menus.main` in your templates. See [menu templates] for details. ++ ++## Localize ++ ++Hugo provides two methods to localize your menu entries. See [multilingual]. ++ ++## Render ++ ++See [menu templates]. ++ ++[localize]: /content-management/multilingual/#menus ++[menu templates]: /templates/menu-templates/ ++[multilingual]: /content-management/multilingual/#menus ++[template]: /templates/menu-templates/ diff --cc docs/content/en/content-management/multilingual.md index 5eb5506d9,000000000..f1f25086a mode 100644,000000..100644 --- a/docs/content/en/content-management/multilingual.md +++ b/docs/content/en/content-management/multilingual.md @@@ -1,600 -1,0 +1,652 @@@ +--- +title: Multilingual Mode +linkTitle: Multilingual +description: Hugo supports the creation of websites with multiple languages side by side. +categories: [content management] +keywords: [multilingual,i18n, internationalization] +menu: + docs: + parent: content-management + weight: 230 +toc: true +weight: 230 +aliases: [/content/multilingual/,/tutorials/create-a-multilingual-site/] +--- + +You should define the available languages in a `languages` section in your site configuration. + - > Also See [Hugo Multilingual Part 1: Content translation] ++Also See [Hugo Multilingual Part 1: Content translation]. + +## Configure Languages + +The following is an example of a site configuration for a multilingual Hugo project: + +{{< code-toggle file="config" >}} +defaultContentLanguage = "en" +copyright = "Everything is mine" + +[params] +[params.navigation] +help = "Help" + +[languages] +[languages.en] +title = "My blog" +weight = 1 +[languages.en.params] +linkedin = "https://linkedin.com/whoever" + +[languages.fr] +title = "Mon blogue" +weight = 2 +[languages.fr.params] +linkedin = "https://linkedin.com/fr/whoever" +[languages.fr.params.navigation] +help = "Aide" + +[languages.ar] +title = "مدونتي" +weight = 2 +languagedirection = "rtl" + +[languages.pt-pt] +title = "O meu blog" +weight = 3 +{{< /code-toggle >}} + +Anything not defined in a `languages` block will fall back to the global value for that key (e.g., `copyright` for the English `en` language). This also works for `params`, as demonstrated with `help` above: You will get the value `Aide` in French and `Help` in all the languages without this parameter set. + +With the configuration above, all content, sitemap, RSS feeds, pagination, +and taxonomy pages will be rendered below `/` in English (your default content language) and then below `/fr` in French. + +When working with front matter `Params` in [single page templates], omit the `params` in the key for the translation. + +`defaultContentLanguage` sets the project's default language. If not set, the default language will be `en`. + +If the default language needs to be rendered below its own language code (`/en`) like the others, set `defaultContentLanguageInSubdir: true`. + +Only the obvious non-global options can be overridden per language. Examples of global options are `baseURL`, `buildDrafts`, etc. + +**Please note:** use lowercase language codes, even when using regional languages (ie. use pt-pt instead of pt-PT). Currently Hugo language internals lowercase language codes, which can cause conflicts with settings like `defaultContentLanguage` which are not lowercased. Please track the evolution of this issue in [Hugo repository issue tracker](https://github.com/gohugoio/hugo/issues/7344) + ++### Changes in Hugo 0.112.0 ++ ++{{< new-in "0.112.0" >}} ++ ++In version `0.112.0` of Hugo we did a major we consolidated all configuration options, but also improved how the languages and their params gets merged with the main configuration. But while testing this on Hugo sites out there, we got some error reports. ++ ++1. `site.Language.Params` is deprecated. Use `site.Params` directly. ++1. The `params` sections on site and language is the only place to put custom user parameters, and `site.Params` will only contain these user defined parameters (see example below). ++ ++```toml ++title = "My blog" ++languageCode = "en-us" ++ ++[languages] ++[languages.sv] ++title = "Min blogg" ++languageCode = "sv" ++[languages.en.params] ++color = "blue" ++``` ++ ++In the example above, all the settings exept the `color` below `params` maps to predefined configuration options in Hguo for the site and its language, and should be accessed via the documented accessors: ++ ++``` ++{{ site.Title }} ++{{ site.LanguageCode }} ++{{ site.Params.color }} ++``` ++ +### Disable a Language + +You can disable one or more languages. This can be useful when working on a new translation. + +{{< code-toggle file="config" >}} +disableLanguages = ["fr", "ja"] +{{< /code-toggle >}} + +Note that you cannot disable the default content language. + +We kept this as a standalone setting to make it easier to set via [OS environment]: + +```bash +HUGO_DISABLELANGUAGES="fr ja" hugo +``` + +If you have already a list of disabled languages in `config.toml`, you can enable them in development like this: + +```bash +HUGO_DISABLELANGUAGES=" " hugo server +``` + +### Configure Multilingual Multihost + +From **Hugo 0.31** we support multiple languages in a multihost configuration. See [this issue](https://github.com/gohugoio/hugo/issues/4027) for details. + +This means that you can now configure a `baseURL` per `language`: + - > If a `baseURL` is set on the `language` level, then all languages must have one and they must all be different. ++{{% note %}} ++If a `baseURL` is set on the `language` level, then all languages must have one and they must all be different. ++{{% /note %}} + +Example: + +{{< code-toggle file="config" >}} +[languages] +[languages.fr] +baseURL = "https://example.fr" +languageName = "Français" +weight = 1 +title = "En Français" + +[languages.en] +baseURL = "https://example.com" +languageName = "English" +weight = 2 +title = "In English" +{{}} + +With the above, the two sites will be generated into `public` with their own root: + +```text +public +├── en +└── fr +``` + +**All URLs (i.e `.Permalink` etc.) will be generated from that root. So the English home page above will have its `.Permalink` set to `https://example.com/`.** + +When you run `hugo server` we will start multiple HTTP servers. You will typically see something like this in the console: + +```text +Web Server is available at 127.0.0.1:1313 (bind address 127.0.0.1) +Web Server is available at 127.0.0.1:1314 (bind address 127.0.0.1) +Press Ctrl+C to stop +``` + +Live reload and `--navigateToChanged` between the servers work as expected. + + +## Translate Your Content + +There are two ways to manage your content translations. Both ensure each page is assigned a language and is linked to its counterpart translations. + +### Translation by filename + +Considering the following example: + +1. `/content/about.en.md` +2. `/content/about.fr.md` + +The first file is assigned the English language and is linked to the second. +The second file is assigned the French language and is linked to the first. + +Their language is __assigned__ according to the language code added as a __suffix to the filename__. + +By having the same **path and base filename**, the content pieces are __linked__ together as translated pages. + - {{< note >}} ++{{% note %}} +If a file has no language code, it will be assigned the default language. - {{}} ++{{% /note %}} + +### Translation by content directory + +This system uses different content directories for each of the languages. Each language's content directory is set using the `contentDir` param. + +{{< code-toggle file="config" >}} +languages: + en: + weight: 10 + languageName: "English" + contentDir: "content/english" + fr: + weight: 20 + languageName: "Français" + contentDir: "content/french" +{{< /code-toggle >}} + +The value of `contentDir` can be any valid path -- even absolute path references. The only restriction is that the content directories cannot overlap. + +Considering the following example in conjunction with the configuration above: + +1. `/content/english/about.md` +2. `/content/french/about.md` + +The first file is assigned the English language and is linked to the second. +The second file is assigned the French language and is linked to the first. + +Their language is __assigned__ according to the content directory they are __placed__ in. + +By having the same **path and basename** (relative to their language content directory), the content pieces are __linked__ together as translated pages. + +### Bypassing default linking + +Any pages sharing the same `translationKey` set in front matter will be linked as translated pages regardless of basename or location. + +Considering the following example: + +1. `/content/about-us.en.md` +2. `/content/om.nn.md` +3. `/content/presentation/a-propos.fr.md` + +{{< code-toggle >}} +translationKey: "about" +{{< /code-toggle >}} + +By setting the `translationKey` front matter param to `about` in all three pages, they will be __linked__ as translated pages. + +### Localizing permalinks + +Because paths and filenames are used to handle linking, all translated pages will share the same URL (apart from the language subdirectory). + - To localize the URLs, the [`slug`]({{< ref "/content-management/organization/index.md#slug" >}}) or [`url`]({{< ref "/content-management/organization/index.md#url" >}}) front matter param can be set in any of the non-default language file. ++To localize URLs: + - For example, a French translation (`content/about.fr.md`) can have its own localized slug. ++- For a regular page, set either [`slug`] or [`url`] in front matter ++- For a section page, set [`url`] in front matter + - {{< code-toggle >}} - Title: A Propos ++[`slug`]: /content-management/urls/#slug ++[`url`]: /content-management/urls/#url ++ ++For example, a French translation can have its own localized slug. ++ ++{{< code-toggle file="content/about.fr.md" fm=true copy=false >}} ++title: A Propos +slug: "a-propos" +{{< /code-toggle >}} + - At render, Hugo will build both `/about/` and `/fr/a-propos/` while maintaining their translation linking. ++At render, Hugo will build both `/about/` and `/fr/a-propos/` without affecting the translation link. + +### Page Bundles + +To avoid the burden of having to duplicate files, each Page Bundle inherits the resources of its linked translated pages' bundles except for the content files (Markdown files, HTML files etc...). + +Therefore, from within a template, the page will have access to the files from all linked pages' bundles. + +If, across the linked bundles, two or more files share the same basename, only one will be included and chosen as follows: + +* File from current language bundle, if present. +* First file found across bundles by order of language `Weight`. + +{{% note %}} +Page Bundle resources follow the same language assignment logic as content files, both by filename (`image.jpg`, `image.fr.jpg`) and by directory (`english/about/header.jpg`, `french/about/header.jpg`). +{{%/ note %}} + +## Reference the Translated Content + +To create a list of links to translated content, use a template similar to the following: + +{{< code file="layouts/partials/i18nlist.html" >}} +{{ if .IsTranslated }} +

{{ i18n "translations" }}

+ +{{ end }} +{{< /code >}} + +The above can be put in a `partial` (i.e., inside `layouts/partials/`) and included in any template, whether a [single content page][contenttemplate] or the [homepage]. It will not print anything if there are no translations for a given page. + +The above also uses the [`i18n` function][i18func] described in the next section. + +### List All Available Languages + +`.AllTranslations` on a `Page` can be used to list all translations, including the page itself. On the home page it can be used to build a language navigator: + +{{< code file="layouts/partials/allLanguages.html" >}} + +{{< /code >}} + +## Translation of Strings + +Hugo uses [go-i18n] to support string translations. [See the project's source repository][go-i18n-source] to find tools that will help you manage your translation workflows. + +Translations are collected from the `themes//i18n/` folder (built into the theme), as well as translations present in `i18n/` at the root of your project. In the `i18n`, the translations will be merged and take precedence over what is in the theme folder. Language files should be named according to [RFC 5646] with names such as `en-US.toml`, `fr.toml`, etc. + +Artificial languages with private use subtags as defined in [RFC 5646 § 2.2.7](https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.7) are also supported. You may omit the `art-x-` prefix for brevity. For example: + +```text +art-x-hugolang +hugolang +``` + +Private use subtags must not exceed 8 alphanumeric characters. + +### Query basic translation + +From within your templates, use the `i18n` function like this: + +```go-html-template +{{ i18n "home" }} +``` + +The function will search for the `"home"` id: + +{{< code-toggle file="i18n/en-US" >}} +[home] +other = "Home" +{{< /code-toggle >}} + +The result will be + +```text +Home +``` + +### Query a flexible translation with variables + +Often you will want to use the page variables in the translation strings. To do so, pass the `.` context when calling `i18n`: + +```go-html-template +{{ i18n "wordCount" . }} +``` + +The function will pass the `.` context to the `"wordCount"` id: + +{{< code-toggle file="i18n/en-US" >}} +[wordCount] +other = "This article has {{ .WordCount }} words." +{{< /code-toggle >}} + +Assume `.WordCount` in the context has value is 101. The result will be: + +```text +This article has 101 words. +``` + +### Query a singular/plural translation + +In other to meet singular/plural requirement, you must pass a dictionary (map) with a numeric `.Count` property to the `i18n` function. The below example uses `.ReadingTime` variable which has a built-in `.Count` property. + +```go-html-template +{{ i18n "readingTime" .ReadingTime }} +``` + +The function will read `.Count` from `.ReadingTime` and evaluate whether the number is singular (`one`) or plural (`other`). After that, it will pass to `readingTime` id in `i18n/en-US.toml` file: + +{{< code-toggle file="i18n/en-US" >}} +[readingTime] +one = "One minute to read" - other = "{{.Count}} minutes to read" ++other = "{{ .Count }} minutes to read" +{{< /code-toggle >}} + +Assuming `.ReadingTime.Count` in the context has value is 525600. The result will be: + +```text +525600 minutes to read +``` + +If `.ReadingTime.Count` in the context has value is 1. The result is: + +```text +One minute to read +``` + +In case you need to pass a custom data: (`(dict "Count" numeric_value_only)` is minimum requirement) + +```go-html-template +{{ i18n "readingTime" (dict "Count" 25 "FirstArgument" true "SecondArgument" false "Etc" "so on, so far") }} +``` + +## Localization + +The following localization examples assume your site's primary language is English, with translations to French and German. + +{{< code-toggle file="config" >}} +defaultContentLanguage = 'en' + +[languages] +[languages.en] +contentDir = 'content/en' +languageName = 'English' +weight = 1 +[languages.fr] +contentDir = 'content/fr' +languageName = 'Français' +weight = 2 +[languages.de] +contentDir = 'content/de' +languageName = 'Deutsch' +weight = 3 + +{{< /code-toggle >}} + +### Dates + +With this front matter: + +{{< code-toggle >}} +date = 2021-11-03T12:34:56+01:00 +{{< /code-toggle >}} + +And this template code: + +```go-html-template +{{ .Date | time.Format ":date_full" }} +``` + +The rendered page displays: + +Language|Value +:--|:-- +English|Wednesday, November 3, 2021 +Français|mercredi 3 novembre 2021 +Deutsch|Mittwoch, 3. November 2021 + +See [time.Format] for details. + +### Currency + +With this template code: + +```go-html-template +{{ 512.5032 | lang.FormatCurrency 2 "USD" }} +``` + +The rendered page displays: + +Language|Value +:--|:-- +English|$512.50 +Français|512,50 $US +Deutsch|512,50 $ + +See [lang.FormatCurrency] and [lang.FormatAccounting] for details. + +### Numbers + +With this template code: + +```go-html-template +{{ 512.5032 | lang.FormatNumber 2 }} +``` + +The rendered page displays: + +Language|Value +:--|:-- +English|512.50 +Français|512,50 +Deutsch|512,50 + +See [lang.FormatNumber] and [lang.FormatNumberCustom] for details. + +### Percentages + +With this template code: + +```go-html-template +{{ 512.5032 | lang.FormatPercent 2 }} ---> 512.50% +``` + +The rendered page displays: + +Language|Value +:--|:-- +English|512.50% +Français|512,50 % +Deutsch|512,50 % + +See [lang.FormatPercent] for details. + +## Menus + - You can define your menus for each language independently. Creating multilingual menus works just like [creating regular menus][menus], except they're defined in language-specific blocks in the configuration file: - - {{< code-toggle file="config" >}} - defaultContentLanguage = "en" - - [languages.en] - weight = 0 - languageName = "English" ++Localization of menu entries depends on the how you define them: + - [[languages.en.menu.main]] - url = "/" - name = "Home" - weight = 0 ++- When you define menu entries [automatically] using the section pages menu, you must use translation tables to localize each entry. ++- When you define menu entries [in front matter], they are already localized based on the front matter itself. If the front matter values are insufficient, use translation tables to localize each entry. ++- When you define menu entries [in site configuration], you can (a) use translation tables, or (b) create language-specific menu entries under each language key. + - [languages.de] - weight = 10 - languageName = "Deutsch" ++### Use translation tables + - [[languages.de.menu.main]] - url = "/" - name = "Startseite" - weight = 0 - {{< /code-toggle >}} - - The rendering of the main navigation works as usual. `.Site.Menus` will just contain the menu in the current language. Note that `absLangURL` below will link to the correct locale of your website. Without it, menu entries in all languages would link to the English version, since it's the default content language that resides in the root directory. ++When rendering the text that appears in menu each entry, the [example menu template] does this: + +```go-html-template -
    - {{- $currentPage := . -}} - {{ range .Site.Menus.main -}} -
  • - {{ .Name }} -
  • - {{- end }} -
++{{ or (T .Identifier) .Name | safeHTML }} +``` + - ### Dynamically localizing menus with i18n ++It queries the translation table for the current language using the menu entry's `identifier` and returns the translated string. If the translation table does not exist, or if the `identifier` key is not present in the translation table, it falls back to `name`. + - While customizing menus per language is useful, your config file can become hard to maintain if you have a lot of languages ++The `identifier` depends on how you define menu entries: + - If your menus are the same in all languages (ie. if the only thing that changes is the translated name) you can use the `.Identifier` as a translation key for the menu name: ++- If you define the menu entry [automatically] using the section pages menu, the `identifier` is the page's `.Section`. ++- If you define the menu entry [in site configuration] or [in front matter], set the `identifier` property to the desired value. + - {{< code-toggle file="config" >}} ++For example, if you define menu entries in site configuration: ++ ++{{< code-toggle file="config" copy=false >}} ++[[menu.main]] ++ identifier = 'products' ++ name = 'Products' ++ pageRef = '/products' ++ weight = 10 +[[menu.main]] - name = "About me" - url = "about" ++ identifier = 'services' ++ name = 'Services' ++ pageRef = '/services' ++ weight = 20 ++{{< / code-toggle >}} ++ ++Create corresponding entries in the translation tables: ++ ++{{< code-toggle file="i18n/de" copy=false >}} ++products = 'Produkte' ++services = 'Leistungen' ++{{< / code-toggle >}} ++ ++[example menu template]: /templates/menu-templates/#example ++[automatically]: /content-management/menus/#define-automatically ++[in front matter]: /content-management/menus/#define-in-front-matter ++[in site configuration]: /content-management/menus/#define-in-site-configuration ++ ++### Create language-specific menu entries ++ ++For example: ++ ++{{< code-toggle file="config" copy=false >}} ++[languages.de] ++languageCode = 'de-DE' ++languageName = 'Deutsch' +weight = 1 - identifier = "about" - {{< /code-toggle >}} + - You now need to specify the translations for the menu keys in the i18n files: ++[[languages.de.menu.main]] ++name = 'Produkte' ++pageRef = '/products' ++weight = 10 + - {{< code file="i18n/pt.toml" >}} - [about] - other="Sobre mim" - {{< /code >}} ++[[languages.de.menu.main]] ++name = 'Leistungen' ++pageRef = '/services' ++weight = 20 + - And do the appropriate changes in the menu code to use the `i18n` tag with the `.Identifier` as a key. You will also note that here we are using a `default` to fall back to `.Name`, in case the `.Identifier` key is also not present in the language specified in the `defaultContentLanguage` configuration. ++[languages.en] ++languageCode = 'en-US' ++languageName = 'English' ++weight = 2 + - {{< code file="layouts/partials/menu.html" >}} - - {{< /code >}} ++[[languages.en.menu.main]] ++name = 'Products' ++pageRef = '/products' ++weight = 10 ++ ++[[languages.en.menu.main]] ++name = 'Services' ++pageRef = '/services' ++weight = 20 ++{{< /code-toggle >}} ++ ++For a simple menu with two languages, these menu entries are easy to create and maintain. For a larger menu, or with more than two languages, using translation tables as described above is preferable. + +## Missing Translations + +If a string does not have a translation for the current language, Hugo will use the value from the default language. If no default value is set, an empty string will be shown. + +While translating a Hugo website, it can be handy to have a visual indicator of missing translations. The [`enableMissingTranslationPlaceholders` configuration option][config] will flag all untranslated strings with the placeholder `[i18n] identifier`, where `identifier` is the id of the missing translation. + +{{% note %}} +Hugo will generate your website with these missing translation placeholders. It might not be suitable for production environments. +{{% /note %}} + +For merging of content from other languages (i.e. missing content translations), see [lang.Merge]. + +To track down missing translation strings, run Hugo with the `--printI18nWarnings` flag: + +```bash +hugo --printI18nWarnings | grep i18n +i18n|MISSING_TRANSLATION|en|wordCount +``` + +## Multilingual Themes support + +To support Multilingual mode in your themes, some considerations must be taken for the URLs in the templates. If there is more than one language, URLs must meet the following criteria: + +* Come from the built-in `.Permalink` or `.RelPermalink` +* Be constructed with the [`relLangURL` template function][rellangurl] or the [`absLangURL` template function][abslangurl] **OR** be prefixed with `{{ .LanguagePrefix }}` + +If there is more than one language defined, the `LanguagePrefix` variable will equal `/en` (or whatever your `CurrentLanguage` is). If not enabled, it will be an empty string (and is therefore harmless for single-language Hugo websites). + + +## Generate multilingual content with `hugo new` + +If you organize content with translations in the same directory: + +```text +hugo new post/test.en.md +hugo new post/test.de.md +``` + +If you organize content with translations in different directories: + +```text +hugo new content/en/post/test.md +hugo new content/de/post/test.md +``` + +[abslangurl]: /functions/abslangurl +[config]: /getting-started/configuration/ +[contenttemplate]: /templates/single-page-templates/ +[go-i18n-source]: https://github.com/nicksnyder/go-i18n +[go-i18n]: https://github.com/nicksnyder/go-i18n +[homepage]: /templates/homepage/ +[Hugo Multilingual Part 1: Content translation]: https://regisphilibert.com/blog/2018/08/hugo-multilingual-part-1-managing-content-translation/ +[i18func]: /functions/i18n/ - [lang.FormatAccounting]: /functions/lang/#langformataccounting - [lang.FormatCurrency]: /functions/lang/#langformatcurrency - [lang.FormatNumber]: /functions/lang/#langformatnumber - [lang.FormatNumberCustom]: /functions/lang/#langformatnumbercustom - [lang.FormatPercent]: /functions/lang/#langformatpercent ++[lang.FormatAccounting]: /functions/lang ++[lang.FormatCurrency]: /functions/lang ++[lang.FormatNumber]: /functions/lang ++[lang.FormatNumberCustom]: /functions/lang ++[lang.FormatPercent]: /functions/lang +[lang.Merge]: /functions/lang.merge/ +[menus]: /content-management/menus/ +[OS environment]: /getting-started/configuration/#configure-with-environment-variables +[rellangurl]: /functions/rellangurl +[RFC 5646]: https://tools.ietf.org/html/rfc5646 +[single page templates]: /templates/single-page-templates/ +[time.Format]: /functions/dateformat diff --cc docs/content/en/content-management/organization/index.md index 94c0cfd5a,000000000..efa355ddc mode 100644,000000..100644 --- a/docs/content/en/content-management/organization/index.md +++ b/docs/content/en/content-management/organization/index.md @@@ -1,235 -1,0 +1,161 @@@ +--- +title: Content Organization +linkTitle: Organization +description: Hugo assumes that the same structure that works to organize your source content is used to organize the rendered site. +categories: [content management,fundamentals] +keywords: [sections,content,organization,bundle,resources] +menu: + docs: + parent: content-management + weight: 20 +toc: true +weight: 20 +aliases: [/content/sections/] +--- + +## Page Bundles + +Hugo `0.32` announced page-relative images and other resources packaged into `Page Bundles`. + - These terms are connected, and you also need to read about [Page Resources]({{< relref "/content-management/page-resources" >}}) and [Image Processing]({{< relref "/content-management/image-processing" >}}) to get the full picture. ++These terms are connected, and you also need to read about [Page Resources](/content-management/page-resources) and [Image Processing](/content-management/image-processing) to get the full picture. + +{{< imgproc 1-featured Resize "300x" >}} +The illustration shows three bundles. Note that the home page bundle cannot contain other content pages, although other files (images etc.) are allowed. +{{< /imgproc >}} + + +{{% note %}} +The bundle documentation is a **work in progress**. We will publish more comprehensive docs about this soon. +{{% /note %}} + + +## Organization of Content Source + +In Hugo, your content should be organized in a manner that reflects the rendered website. + +While Hugo supports content nested at any level, the top levels (i.e. `content/`) are special in Hugo and are considered the content type used to determine layouts etc. To read more about sections, including how to nest them, see [sections]. + +Without any additional configuration, the following will automatically work: + +```txt +. +└── content + └── about + | └── index.md // <- https://example.com/about/ + ├── posts + | ├── firstpost.md // <- https://example.com/posts/firstpost/ + | ├── happy + | | └── ness.md // <- https://example.com/posts/happy/ness/ + | └── secondpost.md // <- https://example.com/posts/secondpost/ + └── quote + ├── first.md // <- https://example.com/quote/first/ + └── second.md // <- https://example.com/quote/second/ +``` + +## Path Breakdown in Hugo + + +The following demonstrates the relationships between your content organization and the output URL structure for your Hugo website when it renders. These examples assume you are [using pretty URLs][pretty], which is the default behavior for Hugo. The examples also assume a key-value of `baseURL = "https://example.com"` in your [site's configuration file][config]. + +### Index Pages: `_index.md` + +`_index.md` has a special role in Hugo. It allows you to add front matter and content to your [list templates][lists]. These templates include those for [section templates], [taxonomy templates], [taxonomy terms templates], and your [homepage template]. + +{{% note %}} +**Tip:** You can get a reference to the content and metadata in `_index.md` using the [`.Site.GetPage` function](/functions/getpage/). +{{% /note %}} + +You can create one `_index.md` for your homepage and one in each of your content sections, taxonomies, and taxonomy terms. The following shows typical placement of an `_index.md` that would contain content and front matter for a `posts` section list page on a Hugo website: + + +```txt +. url +. ⊢--^-⊣ +. path slug +. ⊢--^-⊣⊢---^---⊣ +. filepath +. ⊢------^------⊣ +content/posts/_index.md +``` + +At build, this will output to the following destination with the associated values: + +```txt + + url ("/posts/") + ⊢-^-⊣ + baseurl section ("posts") +⊢--------^---------⊣⊢-^-⊣ + permalink +⊢----------^-------------⊣ +https://example.com/posts/index.html +``` + +The [sections] can be nested as deeply as you want. The important thing to understand is that to make the section tree fully navigational, at least the lower-most section must include a content file. (i.e. `_index.md`). + + +### Single Pages in Sections + +Single content files in each of your sections will be rendered as [single page templates][singles]. Here is an example of a single `post` within `posts`: + + +```txt + path ("posts/my-first-hugo-post.md") +. ⊢-----------^------------⊣ +. section slug +. ⊢-^-⊣⊢--------^----------⊣ +content/posts/my-first-hugo-post.md +``` + +When Hugo builds your site, the content will be output to the following destination: + +```txt + + url ("/posts/my-first-hugo-post/") + ⊢------------^----------⊣ + baseurl section slug +⊢--------^--------⊣⊢-^--⊣⊢-------^---------⊣ + permalink +⊢--------------------^---------------------⊣ +https://example.com/posts/my-first-hugo-post/index.html +``` + + +## Paths Explained + +The following concepts provide more insight into the relationship between your project's organization and the default Hugo behavior when building output for the website. + +### `section` + +A default content type is determined by the section in which a content item is stored. `section` is determined by the location within the project's `content` directory. `section` *cannot* be specified or overridden in front matter. + +### `slug` + - A content's `slug` is either `name.extension` or `name/`. The value for `slug` is determined by - - * the name of the content file (e.g., `lollapalooza.md`) OR - * front matter overrides ++The `slug` is the last segment of the URL path, defined by the file name and optionally overridden by a `slug` value in front matter. See [URL Management](/content-management/urls/#slug) for details. + +### `path` + +A content's `path` is determined by the section's path to the file. The file `path` + +* is based on the path to the content's location AND +* does not include the slug + +### `url` + - The `url` is the relative URL for the piece of content. The `url` - - * is based on the content item's location within the directory structure OR - * is defined in front matter, in which case it *overrides all the above* - - ## Override Destination Paths via Front Matter - - Hugo assumes that your content is organized with a purpose. The same structure that you use to organize your source content is used to organize the rendered site. As displayed above, the organization of the source content will be mirrored at the destination. - - There are times when you may need more fine-grained control over the content organization. In such cases, the front matter field can be used to determine the destination of a specific piece of content. - - The following items are defined in a specific order for a reason: items explained lower down in the list override higher items. Note that not all items can be defined in front matter. - - ### `filename` - - `filename` is not a front matter field. It is the actual file name, minus the extension. This will be the name of the file in the destination (e.g., `content/posts/my-post.md` becomes `example.com/posts/my-post/`). - - ### `slug` - - When defined in the front matter, the `slug` can take the place of the filename in the destination. - - {{< code file="content/posts/old-post.md" >}} - --- - title: A new post with the filename old-post.md - slug: "new-post" - --- - {{< /code >}} - - This will render to the following destination according to Hugo's default behavior: - - ```txt - example.com/posts/new-post/ - ``` - - ### `section` - - `section` is determined by a content item's location on disk and *cannot* be specified in the front matter. See [sections] for more information. - - ### `type` - - A content item's `type` is also determined by its location on disk but, unlike `section`, it *can* be specified in the front matter. See [types]. This can come in especially handy when you want a piece of content to render using a different layout. In the following example, you can create a layout at `layouts/new/mylayout.html` that Hugo will use to render this piece of content, even in the midst of many other posts. - - {{< code file="content/posts/my-post.md" >}} - --- - title: My Post - type: new - layout: mylayout - --- - {{< /code >}} - - - - - - ### `url` - - A complete URL can be provided. This will override all the above as it pertains to the end destination. This must be the path from the baseURL (starting with a `/`). `url` will be used exactly as it is defined in the front matter, and will ignore the `--uglyURLs` setting in your site configuration: - - {{< code file="content/posts/old-url.md" >}} - --- - title: Old URL - url: /blog/new-url/ - --- - {{< /code >}} - - Assuming your `baseURL` is [configured][config] to `https://example.com`, the addition of `url` to the front matter will make `old-url.md` render to the following destination: - - ```txt - https://example.com/blog/new-url/ - ``` - - You can see more information on how to control output paths in [URL Management][urls]. ++The `url` is the entire URL path, defined by the file path and optionally overridden by a `url` value in front matter. See [URL Management](/content-management/urls/#slug) for details. + +[config]: /getting-started/configuration/ +[formats]: /content-management/formats/ +[front matter]: /content-management/front-matter/ +[getpage]: /functions/getpage/ +[homepage template]: /templates/homepage/ +[homepage]: /templates/homepage/ +[lists]: /templates/lists/ - [pretty]: /content-management/urls/#pretty-urls ++[pretty]: /content-management/urls/#appearance +[section templates]: /templates/section-templates/ +[sections]: /content-management/sections/ +[singles]: /templates/single-page-templates/ +[taxonomy templates]: /templates/taxonomy-templates/ +[taxonomy terms templates]: /templates/taxonomy-templates/ +[types]: /content-management/types/ +[urls]: /content-management/urls/ diff --cc docs/content/en/content-management/page-bundles.md index 28ab004c5,000000000..2a5147c21 mode 100644,000000..100644 --- a/docs/content/en/content-management/page-bundles.md +++ b/docs/content/en/content-management/page-bundles.md @@@ -1,189 -1,0 +1,186 @@@ +--- +title: Page Bundles - linkTitle: Page Bundles +description: Content organization using Page Bundles - linkTitle: Page Bundles +keywords: [page, bundle, leaf, branch] +categories: [content management] +menu : + docs: - identifier: "page-bundles" - parent: "content-management" ++ parent: content-management + weight: 30 +toc: true +weight: 30 +--- + +Page Bundles are a way to group [Page Resources](/content-management/page-resources/). + +A Page Bundle can be one of: + +- Leaf Bundle (leaf means it has no children) +- Branch Bundle (home page, section, taxonomy terms, taxonomy list) + +| | Leaf Bundle | Branch Bundle | +|-------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Usage | Collection of content and attachments for single pages | Collection of attachments for section pages (home page, section, taxonomy terms, taxonomy list) | +| Index filename | `index.md` [^fn:1] | `_index.md` [^fn:1] | +| Allowed Resources | Page and non-page (like images, PDF, etc.) types | Only non-page (like images, PDF, etc.) types | +| Where can the Resources live? | At any directory level within the leaf bundle directory. | Only in the directory level **of** the branch bundle directory i.e. the directory containing the `_index.md` ([ref](https://discourse.gohugo.io/t/question-about-content-folder-structure/11822/4?u=kaushalmodi)). | +| Layout type | `single` | `list` | +| Nesting | Does not allow nesting of more bundles under it | Allows nesting of leaf or branch bundles under it | +| Example | `content/posts/my-post/index.md` | `content/posts/_index.md` | +| Content from non-index page files... | Accessed only as page resources | Accessed only as regular pages | + + +## Leaf Bundles {#leaf-bundles} + +A _Leaf Bundle_ is a directory at any hierarchy within the `content/` +directory, that contains an **`index.md`** file. + +### Examples of Leaf Bundle organization {#examples-of-leaf-bundle-organization} + +```text +content/ +├── about +│ ├── index.md +├── posts +│ ├── my-post +│ │ ├── content1.md +│ │ ├── content2.md +│ │ ├── image1.jpg +│ │ ├── image2.png +│ │ └── index.md +│ └── my-other-post +│    └── index.md +│ +└── another-section + ├── .. +    └── not-a-leaf-bundle + ├── .. +    └── another-leaf-bundle +    └── index.md +``` + +In the above example `content/` directory, there are four leaf +bundles: + +`about` +: This leaf bundle is at the root level (directly under + `content` directory) and has only the `index.md`. + +`my-post` +: This leaf bundle has the `index.md`, two other content + Markdown files and two image files. + +- image1, image2: +These images are page resources of `my-post` + and only available in `my-post/index.md` resources. + +- content1, content2: +These content files are page resources of `my-post` + and only available in `my-post/index.md` resources. + They will **not** be rendered as individual pages. + +`my-other-post` +: This leaf bundle has only the `index.md`. + +`another-leaf-bundle` +: This leaf bundle is nested under couple of + directories. This bundle also has only the `index.md`. + +{{% note %}} +The hierarchy depth at which a leaf bundle is created does not matter, +as long as it is not inside another **leaf** bundle. +{{% /note %}} + + +### Headless Bundle {#headless-bundle} + +A headless bundle is a bundle that is configured to not get published +anywhere: + +- It will have no `Permalink` and no rendered HTML in `public/`. +- It will not be part of `.Site.RegularPages`, etc. + +But you can get it by `.Site.GetPage`. Here is an example: + +```go-html-template +{{ $headless := .Site.GetPage "/some-headless-bundle" }} +{{ $reusablePages := $headless.Resources.Match "author*" }} +

Authors

+{{ range $reusablePages }} +

{{ .Title }}

+ {{ .Content }} +{{ end }} +``` + +_In this example, we are assuming the `some-headless-bundle` to be a headless + bundle containing one or more **page** resources whose `.Name` matches + `"author*"`._ + +Explanation of the above example: + +1. Get the `some-headless-bundle` Page "object". +2. Collect a _slice_ of resources in this _Page Bundle_ that matches + `"author*"` using `.Resources.Match`. +3. Loop through that _slice_ of nested pages, and output their `.Title` and + `.Content`. + +--- + +A leaf bundle can be made headless by adding below in the Front Matter +(in the `index.md`): + - ```toml ++{{< code-toggle file="content/headless/index.md" fm=true copy=false >}} +headless = true - ``` ++{{< /code-toggle >}} + +There are many use cases of such headless page bundles: + +- Shared media galleries +- Reusable page content "snippets" + +## Branch Bundles {#branch-bundles} + +A _Branch Bundle_ is any directory at any hierarchy within the +`content/` directory, that contains at least an **`_index.md`** file. + +This `_index.md` can also be directly under the `content/` directory. + +{{% note %}} +Here `md` (markdown) is used just as an example. You can use any file +type as a content resource as long as it is a content type recognized by Hugo. +{{% /note %}} + + +### Examples of Branch Bundle organization {#examples-of-branch-bundle-organization} + +```text +content/ +├── branch-bundle-1 +│   ├── branch-content1.md +│   ├── branch-content2.md +│   ├── image1.jpg +│   ├── image2.png +│   └── _index.md +└── branch-bundle-2 + ├── _index.md + └── a-leaf-bundle + └── index.md +``` + +In the above example `content/` directory, there are two branch +bundles (and a leaf bundle): + +`branch-bundle-1` +: This branch bundle has the `_index.md`, two + other content Markdown files and two image files. + +`branch-bundle-2` +: This branch bundle has the `_index.md` and a + nested leaf bundle. + +{{% note %}} +The hierarchy depth at which a branch bundle is created does not +matter. +{{% /note %}} + +[^fn:1]: The `.md` extension is just an example. The extension can be `.html`, `.json` or any valid MIME type. diff --cc docs/content/en/content-management/page-resources.md index 16c9fc0ab,000000000..4bbd159be mode 100644,000000..100644 --- a/docs/content/en/content-management/page-resources.md +++ b/docs/content/en/content-management/page-resources.md @@@ -1,205 -1,0 +1,203 @@@ +--- +title: Page Resources - linkTitle: Page Resources +description: Page resources -- images, other pages, documents, etc. -- have page-relative URLs and their own metadata. +categories: [content management] +keywords: [bundle,content,resources] +menu: + docs: + parent: content-management + weight: 80 +toc: true +weight: 80 +--- - Page resources are only accessible from [page bundles]({{< relref - "/content-management/page-bundles" >}}), those directories with `index.md` or ++Page resources are only accessible from [page bundles](/content-management/page-bundles), those directories with `index.md` or +`_index.md` files at their root. Page resources are only available to the +page with which they are bundled. + +In this example, `first-post` is a page bundle with access to 10 page resources including audio, data, documents, images, and video. Although `second-post` is also a page bundle, it has no page resources and is unable to directly access the page resources associated with `first-post`. + +```text +content +└── post + ├── first-post + │ ├── images + │ │ ├── a.jpg + │ │ ├── b.jpg + │ │ └── c.jpg + │ ├── index.md (root of page bundle) + │ ├── latest.html + │ ├── manual.json + │ ├── notice.md + │ ├── office.mp3 + │ ├── pocket.mp4 + │ ├── rating.pdf + │ └── safety.txt + └── second-post + └── index.md (root of page bundle) +``` + +## Properties + +ResourceType +: The main type of the resource's [Media Type](/templates/output-formats/#media-types). For example, a file of MIME type `image/jpeg` has the ResourceType `image`. A `Page` will have `ResourceType` with value `page`. + +Name +: Default value is the filename (relative to the owning page). Can be set in front matter. + +Title +: Default value is the same as `.Name`. 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. + +Content +: The content of the resource itself. For most resources, this returns a string +with the contents of the file. Use this to create inline resources. + +```go-html-template +{{ with .Resources.GetMatch "script.js" }} + +{{ end }} + +{{ with .Resources.GetMatch "style.css" }} + +{{ end }} + +{{ with .Resources.GetMatch "img.png" }} + +{{ end }} +``` + +MediaType +: The MIME type of the resource, such as `image/jpeg`. + +MediaType.MainType +: The main type of the resource's MIME type. For example, a file of MIME type `application/pdf` has for MainType `application`. + +MediaType.SubType +: The subtype of the resource's MIME type. For example, a file of MIME type `application/pdf` has for SubType `pdf`. Note that this is not the same as the file extension - PowerPoint files have a subtype of `vnd.mspowerpoint`. + +MediaType.Suffixes +: A slice of possible suffixes for the resource's MIME type. + +## Methods + +ByType +: Returns the page resources of the given type. + +```go-html-template +{{ .Resources.ByType "image" }} +``` +Match +: 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. + +```go-html-template +{{ .Resources.Match "images/*" }} +``` + +GetMatch +: Same as `Match` but will return the first match. + +### Pattern Matching + +```go +// 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 + +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). + +{{% note %}} +Resources of type `page` get `Title` etc. from their own front matter. +{{% /note %}} + +name +: Sets the value returned in `Name`. + - {{% warning %}} ++{{% note %}} +The methods `Match`, `Get` and `GetMatch` use `Name` to match the resources. - {{%/ warning %}} ++{{% /note %}} + +title +: Sets the value returned in `Title` + +params +: A map of custom key/values. + +### Resources metadata example + - {{< code-toggle copy="false">}} ++{{< 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" +{{}} + +From the example above: + +- `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`](#the-counter-placeholder-in-name-and-title), so the `Name` will be `pdf-file-1`, `pdf-file-2`, `pdf-file-3`. +- Every docx in the bundle will receive the `word` icon. + - {{% warning %}} ++{{% note %}} +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. In the above example, `.Params.icon` is 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 %}} ++{{% /note %}} + +### 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">}} ++{{< code-toggle copy=false >}} +[[resources]] + src = "*specs.pdf" + title = "Specification #:counter" +[[resources]] + src = "**.pdf" + name = "pdf-file-:counter" +{{}} + +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"` | diff --cc docs/content/en/content-management/related.md index c25b0ed61,000000000..823e3035c mode 100644,000000..100644 --- a/docs/content/en/content-management/related.md +++ b/docs/content/en/content-management/related.md @@@ -1,190 -1,0 +1,188 @@@ +--- +title: Related Content - linkTitle: Related Content +description: List related content in "See Also" sections. +categories: [content management] +keywords: [content] +menu: + docs: + parent: content-management + weight: 110 +toc: true +weight: 110 +aliases: [/content/related/,/related/] +--- + +Hugo uses a set of factors to identify a page's related content based on Front Matter parameters. This can be tuned to the desired set of indices and parameters or left to Hugo's default [Related Content configuration](#configure-related-content). + +## List Related Content + +To list up to 5 related pages (which share the same _date_ or _keyword_ parameters) is as simple as including something similar to this partial in your single page template: + +{{< code file="layouts/partials/related.html" >}} +{{ $related := .Site.RegularPages.Related . | first 5 }} +{{ with $related }} +

See Also

+ +{{ end }} +{{< /code >}} + +The `Related` method takes one argument which may be a `Page` or a options map. The options map have these options: + +indices +: The indices to search in. + +document +: The document to search for related content for. + +namedSlices +: The keywords to search for. + +fragments +: Fragments holds a a list of special keywords that is used for indices configured as type "fragments". This will match the fragment identifiers of the documents. + +A fictional example using all of the above options: + +```go-html-template +{{ $page := . }} +{{ $opts := + "indices" (slice "tags" "keywords") + "document" $page + "namedSlices" (slice (keyVals "tags" "hugo" "rocks") (keyVals "date" $page.Date)) + "fragments" (slice "heading-1" "heading-2") +}} +``` + +{{% note %}} +We improved and simplified this feature in Hugo 0.111.0. Before this we had 3 different methods: `Related`, `RelatedTo` and `RelatedIndicies`. Now we have only one method: `Related`. The old methods are still available but deprecated. Also see [this blog article](https://regisphilibert.com/blog/2018/04/hugo-optmized-relashionships-with-related-content/) for a great explanation of more advanced usage of this feature. +{{% /note %}} + +## Index Content Headings in Related Content + +{{< new-in "0.111.0" >}} + +Hugo can index the headings in your content and use this to find related content. You can enable this by adding a index of type `fragments` to your `related` configuration: + - - ```toml ++{{< code-toggle file="config" copy=false >}} +[related] +threshold = 20 +includeNewer = true +toLower = false +[[related.indices]] +name = "fragmentrefs" +type = "fragments" +applyFilter = false +weight = 80 - ``` ++{{< /code-toggle >}} + +* The `name` maps to a optional front matter slice attribute that can be used to link from the page level down to the fragment/heading level. +* If `applyFilter`is enabled, the `.HeadingsFiltered` on each page in the result will reflect the filtered headings. This is useful if you want to show the headings in the related content listing: + +```go-html-template +{{ $related := .Site.RegularPages.Related . | first 5 }} +{{ with $related }} +

See Also

+
    + {{ range $i, $p := . }} +
  • + {{ .Title }} + {{ with .HeadingsFiltered }} +
      + {{ range . }} + {{ $link := printf "%s#%s" $p.RelPermalink .ID | safeURL }} +
    • + {{ .Title }} +
    • + {{ end }} +
    + {{ end }} +
  • + {{ end }} +
+{{ end }} +``` + +## Configure Related Content + +Hugo provides a sensible default configuration of Related Content, but you can fine-tune this in your configuration, on the global or language level if needed. + +### Default configuration + +Without any `related` configuration set on the project, Hugo's Related Content methods will use the following. + +{{< code-toggle file="config" >}} +related: + threshold: 80 + includeNewer: false + toLower: false + indices: + - name: keywords + weight: 100 + - name: date + weight: 10 +{{< /code-toggle >}} + +Note that if you have configured `tags` as a taxonomy, `tags` will also be added to the default configuration above with the weight of `80`. + +Custom configuration should be set using the same syntax. + +{{% note %}} +If you add a `related` config section, you need to add a complete configuration. It is not possible to just set, say, `includeNewer` and use the rest from the Hugo defaults. +{{% /note %}} + +### Top Level Config Options + +threshold +: A value between 0-100. Lower value will give more, but maybe not so relevant, matches. + +includeNewer +: Set to true to include **pages newer than the current page** in the related content listing. This will mean that the output for older posts may change as new related content gets added. + +toLower +: Set to true to lower case keywords in both the indexes and the queries. This may give more accurate results at a slight performance penalty. Note that this can also be set per index. + +### Config Options per Index + +name +: The index name. This value maps directly to a page param. Hugo supports string values (`author` in the example) and lists (`tags`, `keywords` etc.) and time and date objects. + +type +: {{< new-in "0.111.0" >}}. One of `basic`(default) or `fragments`. + +applyFilter +: {{< new-in "0.111.0" >}}. Apply a `type` specific filter to the result of a search. This is currently only used for the `fragments` type. + +weight +: An integer weight that indicates _how important_ this parameter is relative to the other parameters. It can be 0, which has the effect of turning this index off, or even negative. Test with different values to see what fits your content best. + + +cardinalityThreshold (default 0) +: {{< new-in "0.111.0" >}}. A percentage (0-100) used to remove common keywords from the index. As an example, setting this to 50 will remove all keywords that are used in more than 50% of the documents in the index. + +pattern +: This is currently only relevant for dates. When listing related content, we may want to list content that is also close in time. Setting "2006" (default value for date indexes) as the pattern for a date index will add weight to pages published in the same year. For busier blogs, "200601" (year and month) may be a better default. + +toLower +: See above. + +## Performance Considerations + +**Fast is Hugo's middle name** and we would not have released this feature had it not been blistering fast. + +This feature has been in the back log and requested by many for a long time. The development got this recent kick start from this Twitter thread: + +{{< tweet user="scott_lowe" id="898398437527363585" >}} + +Scott S. Lowe removed the "Related Content" section built using the `intersect` template function on tags, and the build time dropped from 30 seconds to less than 2 seconds on his 1700 content page sized blog. + +He should now be able to add an improved version of that "Related Content" section without giving up the fast live-reloads. But it's worth noting that: + +* If you don't use any of the `Related` methods, you will not use the Relate Content feature, and performance will be the same as before. +* Calling `.RegularPages.Related` etc. will create one inverted index, also sometimes named posting list, that will be reused for any lookups in that same page collection. Doing that in addition to, as an example, calling `.Pages.Related` will work as expected, but will create one additional inverted index. This should still be very fast, but worth having in mind, especially for bigger sites. + +{{% note %}} +We currently do not index **Page content**. We thought we would release something that will make most people happy before we start solving [Sherlock's last case](https://github.com/joearms/sherlock). +{{% /note %}} diff --cc docs/content/en/content-management/sections.md index b68a5bdb9,000000000..10c87e6cb mode 100644,000000..100644 --- a/docs/content/en/content-management/sections.md +++ b/docs/content/en/content-management/sections.md @@@ -1,97 -1,0 +1,96 @@@ +--- +title: Content Sections +linkTitle: Sections +description: Hugo generates a **section tree** that matches your content. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [content management] +keywords: [lists,sections,content types,organization] +menu: + docs: + parent: content-management + weight: 120 +toc: true +weight: 120 +aliases: [/content/sections/] +--- + +A **Section** is a collection of pages that gets defined based on the +organization structure under the `content/` directory. + +By default, all the **first-level** directories under `content/` form their own +sections (**root sections**) provided they constitute [Branch Bundles][branch bundles]. +Directories which are just [Leaf Bundles][leaf bundles] do *not* form +their own sections, despite being first-level directories. + +If a user needs to define a section `foo` at a deeper level, they need to create +a directory named `foo` with an `_index.md` file (see [Branch Bundles][branch bundles] +for more information). + + +{{% note %}} +A **section** cannot be defined or overridden by a front matter parameter -- it +is strictly derived from the content organization structure. +{{% /note %}} + +## Nested Sections + +The sections can be nested as deeply as you need. + +```bash +content +└── blog <-- Section, because first-level dir under content/ + ├── funny-cats + │   ├── mypost.md + │   └── kittens <-- Section, because contains _index.md + │   └── _index.md + └── tech <-- Section, because contains _index.md + └── _index.md +``` + +**The important part to understand is, that to make the section tree fully navigational, at least the lower-most section needs a content file. (e.g. `_index.md`).** + +{{% note %}} +When we talk about a **section** in correlation with template selection, it is +currently always the *root section* only (`/blog/funny-cats/mypost/ => blog`). + +If you need a specific template for a sub-section, you need to adjust either the `type` or `layout` in front matter. +{{% /note %}} + +## Example: Breadcrumb Navigation + +With the available [section variables and methods](#section-page-variables-and-methods) you can build powerful navigation. One common example would be a partial to show Breadcrumb navigation: + - {{< code file="layouts/partials/breadcrumb.html" download="breadcrumb.html" >}} - ++{{< code file="layouts/partials/breadcrumb.html" >}} ++ +{{< /code >}} + +## Section Page Variables and Methods + +Also see [Page Variables](/variables/page/). + +{{< readfile file="/content/en/readfiles/sectionvars.md" markdown="true" >}} + +## Content Section Lists + +Hugo will automatically create a page for each *root section* that lists all the content in that section. See the documentation on [section templates] for details on customizing the way these pages are rendered. + +## Content *Section* vs Content *Type* + +By default, everything created within a section will use the [content `type`][content type] that matches the *root section* name. For example, Hugo will assume that `posts/post-1.md` has a `posts` content `type`. If you are using an [archetype] for your `posts` section, Hugo will generate front matter according to what it finds in `archetypes/posts.md`. + +[archetype]: /content-management/archetypes/ +[content type]: /content-management/types/ +[directory structure]: /getting-started/directory-structure/ +[section templates]: /templates/section-templates/ +[leaf bundles]: /content-management/page-bundles/#leaf-bundles +[branch bundles]: /content-management/page-bundles/#branch-bundles diff --cc docs/content/en/content-management/shortcodes.md index a9269c216,000000000..35ffc390f mode 100644,000000..100644 --- a/docs/content/en/content-management/shortcodes.md +++ b/docs/content/en/content-management/shortcodes.md @@@ -1,437 -1,0 +1,411 @@@ +--- +title: Shortcodes - linkTitle: Shortcodes +description: Shortcodes are simple snippets inside your content files calling built-in or custom templates. +categories: [content management] +keywords: [markdown,content,shortcodes] +menu: + docs: + parent: content-management + weight: 100 +toc: true +weight: 100 +aliases: [/extras/shortcodes/] +testparam: "Hugo Rocks!" +--- + +## What a Shortcode is + +Hugo loves Markdown because of its simple content format, but there are times when Markdown falls short. Often, content authors are forced to add raw HTML (e.g., video ` + +{{< /code >}} + - {{< code file="youtube-embed.html" copy="false" >}} ++{{< code file="youtube-embed.html" copy=false >}} +
+ +
+{{< /code >}} + +### Single Named Example: `image` + +Let's say you want to create your own `img` shortcode rather than use Hugo's built-in [`figure` shortcode][figure]. Your goal is to be able to call the shortcode as follows in your content files: + +{{< code file="content-image.md" >}} +{{}} +{{< /code >}} + +You have created the shortcode at `/layouts/shortcodes/img.html`, which loads the following shortcode template: + +{{< code file="/layouts/shortcodes/img.html" >}} + -
- {{ with .Get "link" }}{{ end }} - ++
++ {{ with .Get "link" }}{{ end }} ++ + {{ if .Get "link" }}{{ end }} + {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr") }} -
{{ if isset .Params "title" }} ++
{{ if isset .Params "title" }} +

{{ .Get "title" }}

{{ end }} + {{ if or (.Get "caption") (.Get "attr") }}

+ {{ .Get "caption" }} + {{ with .Get "attrlink" }} {{ end }} - {{ .Get "attr" }} ++ {{ .Get "attr" }} + {{ if .Get "attrlink" }} {{ end }} +

{{ end }} -
- {{ end }} ++
++ {{ end }} +
+ +{{< /code >}} + +Would be rendered as: + - {{< code file="img-output.html" copy="false" >}} ++{{< code file="img-output.html" copy=false >}} +
- -
-

Steve Francia

-
++ ++
++

Steve Francia

++
+
+{{< /code >}} + +### Single Flexible Example: `vimeo` + +```go-html-template +{{}} +{{}} +``` + +Would load the template found at `/layouts/shortcodes/vimeo.html`: + +{{< code file="/layouts/shortcodes/vimeo.html" >}} +{{ if .IsNamedParams }} +
+ +
+{{ else }} +
+ +
+{{ end }} +{{< /code >}} + +Would be rendered as: + - {{< code file="vimeo-iframes.html" copy="false" >}} ++{{< code file="vimeo-iframes.html" copy=false >}} +
+ +
+
+ +
+{{< /code >}} + +### Paired Example: `highlight` + +The following is taken from `highlight`, which is a [built-in shortcode] that ships with Hugo. + +{{< code file="highlight-example.md" >}} +{{}} + + This HTML + +{{}} +{{< /code >}} + +The template for the `highlight` shortcode uses the following code, which is already included in Hugo: + +```go-html-template +{{ .Get 0 | highlight .Inner }} +``` + +The rendered output of the HTML example code block will be as follows: + - {{< code file="syntax-highlighted.html" copy="false" >}} ++{{< code file="syntax-highlighted.html" copy=false >}} +
<html>
 +    <body> This HTML </body>
 +</html>
 +
+{{< /code >}} + +### Nested Shortcode: Image Gallery + +Hugo's [`.Parent` shortcode variable][parent] provides access to the parent shortcode context when the shortcode in question is called within the context of a *parent* shortcode. This provides an inheritance model for common shortcode parameters. + +The following example is contrived but demonstrates the concept. Assume you have a `gallery` shortcode that expects one named `class` parameter: + +{{< code file="layouts/shortcodes/gallery.html" >}} +
+ {{ .Inner }} +
+{{< /code >}} + +You also have an `img` shortcode with a single named `src` parameter that you want to call inside of `gallery` and other shortcodes, so that the parent defines the context of each `img`: + +{{< code file="layouts/shortcodes/img.html" >}} +{{- $src := .Get "src" -}} +{{- with .Parent -}} - ++ +{{- else -}} - ++ +{{- end -}} +{{< /code >}} + +You can then call your shortcode in your content as follows: + +```go-html-template +{{}} + {{}} + {{}} +{{}} +{{}} +``` + +This will output the following HTML. Note how the first two `img` shortcodes inherit the `class` value of `content-gallery` set with the call to the parent `gallery`, whereas the third `img` only uses `src`: + +```html + + +``` + +## Error Handling in Shortcodes + +Use the [errorf](/functions/errorf) template func and [.Position](/variables/shortcodes/) variable to get useful error messages in shortcodes: + +```bash +{{ with .Get "name" }} +{{ else }} +{{ errorf "missing value for param 'name': %s" .Position }} +{{ end }} +``` + +When the above fails, you will see an `ERROR` log similar to the below: + +```bash +ERROR 2018/11/07 10:05:55 missing value for param name: "/Users/bep/dev/go/gohugoio/hugo/docs/content/en/variables/shortcodes.md:32:1" +``` + +## More Shortcode Examples + +More shortcode examples can be found in the [shortcodes directory for spf13.com][spfscs] and the [shortcodes directory for the Hugo docs][docsshortcodes]. + +## Inline Shortcodes + +You can also implement your shortcodes inline -- e.g. where you use them in the content file. This can be useful for scripting that you only need in one place. + +This feature is disabled by default, but can be enabled in your site config: + +{{< code-toggle file="config">}} +enableInlineShortcodes = true +{{< /code-toggle >}} + +It is disabled by default for security reasons. The security model used by Hugo's template handling assumes that template authors are trusted, but that the content files are not, so the templates are injection-safe from malformed input data. But in most situations you have full control over the content, too, and then `enableInlineShortcodes = true` would be considered safe. But it's something to be aware of: It allows ad-hoc [Go Text templates](https://golang.org/pkg/text/template/) to be executed from the content files. + +And once enabled, you can do this in your content files: + + ```go-text-template + {{}}{{ now }}{{}} + ``` + +The above will print the current date and time. + + Note that an inline shortcode's inner content is parsed and executed as a Go text template with the same context as a regular shortcode template. + +This means that the current page can be accessed via `.Page.Title` etc. This also means that there are no concept of "nested inline shortcodes". + +The same inline shortcode can be reused later in the same content file, with different params if needed, using the self-closing syntax: + + ```go-text-template +{{}} +``` + +[basic content files]: /content-management/formats/ "See how Hugo leverages markdown--and other supported formats--to create content for your website." +[built-in shortcode]: /content-management/shortcodes/ +[config]: /getting-started/configuration/ "Learn more about Hugo's built-in configuration variables as well as how to us your site's configuration file to include global key-values that can be used throughout your rendered website." +[Content Management: Shortcodes]: /content-management/shortcodes/#using-hugo-s-built-in-shortcodes "Check this section if you are not familiar with the definition of what a shortcode is or if you are unfamiliar with how to use Hugo's built-in shortcodes in your content files." +[source organization]: /getting-started/directory-structure/#directory-structure-explained "Learn how Hugo scaffolds new sites and what it expects to find in each of your directories." +[docsshortcodes]: https://github.com/gohugoio/hugo/tree/master/docs/layouts/shortcodes "See the shortcode source directory for the documentation site you're currently reading." +[figure]: /content-management/shortcodes/#figure +[hugosc]: /content-management/shortcodes/#using-hugo-s-built-in-shortcodes +[lookup order]: /templates/lookup-order/ "See the order in which Hugo traverses your template files to decide where and how to render your content at build time" +[pagevars]: /variables/page/ "See which variables you can leverage in your templating for page vs list templates." +[parent]: /variables/shortcodes/ +[shortcodesvars]: /variables/shortcodes/ "Certain variables are specific to shortcodes, although most .Page variables can be accessed within your shortcode template." +[spfscs]: https://github.com/spf13/spf13.com/tree/master/layouts/shortcodes "See more examples of shortcodes by visiting the shortcode directory of the source for spf13.com, the blog of Hugo's creator, Steve Francia." +[templates]: /templates/ "The templates section of the Hugo docs." +[vimeoexample]: #single-flexible-example-vimeo +[youtubeshortcode]: /content-management/shortcodes/#youtube "See how to use Hugo's built-in YouTube shortcode." diff --cc docs/content/en/templates/single-page-templates.md index 925f97b03,000000000..559f2fb17 mode 100644,000000..100644 --- a/docs/content/en/templates/single-page-templates.md +++ b/docs/content/en/templates/single-page-templates.md @@@ -1,93 -1,0 +1,87 @@@ +--- +title: Single Page Templates - linktitle: +description: The primary view of content in Hugo is the single view. Hugo will render every Markdown file provided with a corresponding single template. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-04-06 +categories: [templates] +keywords: [page, templates] +menu: + docs: - parent: "templates" ++ parent: templates + weight: 60 +weight: 60 - sections_weight: 60 - draft: false +aliases: [/layout/content/] +toc: true +--- + +## Single Page Template Lookup Order + +See [Template Lookup](/templates/lookup-order/). + +## Example Single Page Templates + +Content pages are of the type `page` and will therefore have all the [page variables][pagevars] and [site variables] available to use in their templates. + +### `posts/single.html` + +This single page template makes use of Hugo [base templates], the [`.Format` function] for dates, the [`.WordCount` page variable][pagevars], and ranges through the single content's specific [taxonomies][pagetaxonomy]. [`with`] is also used to check whether the taxonomies are set in the front matter. + - {{< code file="layouts/posts/single.html" download="single.html" >}} ++{{< code file="layouts/posts/single.html" >}} +{{ define "main" }} + +
+

{{ .Title }}

+
-
- {{ .Content }} -
++
++ {{ .Content }} ++
+
+
+ +{{ end }} +{{< /code >}} + +To easily generate new instances of a content type (e.g., new `.md` files in a section like `project/`) with preconfigured front matter, use [content archetypes][archetypes]. + +[archetypes]: /content-management/archetypes/ +[base templates]: /templates/base/ +[config]: /getting-started/configuration/ +[content type]: /content-management/types/ +[directory structure]: /getting-started/directory-structure/ +[dry]: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself +[`.format` function]: /functions/format/ +[front matter]: /content-management/front-matter/ +[pagetaxonomy]: /templates/taxonomy-templates/#display-a-single-piece-of-contents-taxonomies +[pagevars]: /variables/page/ +[partials]: /templates/partials/ +[section]: /content-management/sections/ +[site variables]: /variables/site/ +[spf13]: https://spf13.com/ +[`with`]: /functions/with/ diff --cc docs/content/en/templates/sitemap-template.md index 9fc817020,000000000..d0738a362 mode 100644,000000..100644 --- a/docs/content/en/templates/sitemap-template.md +++ b/docs/content/en/templates/sitemap-template.md @@@ -1,87 -1,0 +1,84 @@@ +--- +title: Sitemap Templates +description: Hugo provides built-in sitemap templates. - date: 2017-02-01 +categories: [templates] +keywords: [sitemap, xml, templates] +menu: + docs: - parent: "templates" ++ parent: templates + weight: 160 +weight: 160 - sections_weight: 160 - draft: false +aliases: [/layout/sitemap/,/templates/sitemap/] +toc: true +--- + +## Overview + +Hugo's built-in sitemap templates conform to v0.9 of the [sitemap protocol]. + +With a monolingual project, Hugo generates a sitemap.xml file in the root of the [`publishDir`] using the built-in [sitemap.xml] template. + +With a multilingual project, Hugo generates: + +- A sitemap.xml file in the root of each site (language) using the built-in [sitemap.xml] template +- A sitemap.xml file in the root of the [`publishDir`] using the built-in [sitemapindex.xml] template + +## Configuration + +Set the default values for [change frequency] and [priority], and the name of the generated file, in your site configuration. + +{{< code-toggle file="config" >}} +[sitemap] + changefreq = 'monthly' + filename = 'sitemap.xml' + priority = 0.5 +{{}} + +changefreq +: How frequently a page is likely to change. Valid values are `always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, and `never`. Default is `""` (change frequency omitted from rendered sitemap). + +filename +: The name of the generated file. Default is `sitemap.xml`. + +priority +: The priority of a page relative to any other page on the site. Valid values range from 0.0 to 1.0. Default is `-1` (priority omitted from rendered sitemap). + +## Override Default Values + +Override the default values for a given page in front matter. + +{{< code-toggle file="news.md" fm=true >}} +title = 'News' +[sitemap] + changefreq = 'weekly' + priority = 0.8 +{{}} + +## Override Built-in Templates + +To override the built-in sitemap.xml template, create a new file in either of these locations: + +- layouts/sitemap.xml +- layouts/_default/sitemap.xml + +When ranging through the page collection, access the _change frequency_ and _priority_ with `.Sitemap.ChangeFreq` and `.Sitemap.Priority` respectively. + +To override the built-in sitemapindex.xml template, create a new file in either of these locations: + +- layouts/sitemapindex.xml +- layouts/_default/sitemapindex.xml + +## Disable Sitemap Generation + +You may disable sitemap generation in your site configuration: + +{{< code-toggle file="config" >}} +disableKinds = ['sitemap'] +{{}} + - [`publishDir`]: {{< relref "getting-started/configuration#publishdir" >}} ++[`publishDir`]: /getting-started/configuration#publishdir +[change frequency]: +[priority]: +[sitemap protocol]: +[sitemap.xml]: +[sitemapindex.xml]: diff --cc docs/content/en/templates/taxonomy-templates.md index e9fc80525,000000000..e343df471 mode 100644,000000..100644 --- a/docs/content/en/templates/taxonomy-templates.md +++ b/docs/content/en/templates/taxonomy-templates.md @@@ -1,341 -1,0 +1,333 @@@ +--- +title: Taxonomy Templates - # linktitle: +description: Taxonomy templating includes taxonomy list pages, taxonomy terms pages, and using taxonomies in your single page templates. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [templates] +keywords: [taxonomies,metadata,front matter,terms,templates] +menu: + docs: - parent: "templates" ++ parent: templates + weight: 50 +weight: 50 - sections_weight: 50 - draft: false +aliases: [/taxonomies/displaying/,/templates/terms/,/indexes/displaying/,/taxonomies/templates/,/indexes/ordering/, /templates/taxonomies/, /templates/taxonomy/] +toc: true +--- + + + +Hugo includes support for user-defined groupings of content called **taxonomies**. Taxonomies are classifications that demonstrate logical relationships between content. See [Taxonomies under Content Management](/content-management/taxonomies) if you are unfamiliar with how Hugo leverages this powerful feature. + +Hugo provides multiple ways to use taxonomies throughout your project templates: + +* Order the way content associated with a taxonomy term is displayed in a [taxonomy list template](#taxonomy-list-templates) +* Order the way the terms for a taxonomy are displayed in a [taxonomy terms template](#taxonomy-terms-templates) +* List a single content's taxonomy terms within a [single page template] + +## Taxonomy List Templates + +Taxonomy list page templates are lists and therefore have all the variables and methods available to [list pages][lists]. + +### Taxonomy List Template Lookup Order + +See [Template Lookup](/templates/lookup-order/). + +## Taxonomy Terms Templates + +### Taxonomy Terms Templates Lookup Order + +See [Template Lookup](/templates/lookup-order/). + +### Taxonomy Methods + +A Taxonomy is a `map[string]WeightedPages`. + +.Get(term) +: Returns the WeightedPages for a term. + +.Count(term) +: The number of pieces of content assigned to this term. + +.Alphabetical +: Returns an OrderedTaxonomy (slice) ordered by Term. + +.ByCount +: Returns an OrderedTaxonomy (slice) ordered by number of entries. + +.Reverse +: Returns an OrderedTaxonomy (slice) in reverse order. Must be used with an OrderedTaxonomy. + +### OrderedTaxonomy + +Since Maps are unordered, an OrderedTaxonomy is a special structure that has a defined order. + +```go +[]struct { + Name string + WeightedPages WeightedPages +} +``` + +Each element of the slice has: + +.Term +: The Term used. + +.WeightedPages +: A slice of Weighted Pages. + +.Count +: The number of pieces of content assigned to this term. + +.Pages +: All Pages assigned to this term. All [list methods][renderlists] are available to this. + +## WeightedPages + +WeightedPages is simply a slice of WeightedPage. + +```go +type WeightedPages []WeightedPage +``` + +.Count(term) +: The number of pieces of content assigned to this term. + +.Pages +: Returns a slice of pages, which then can be ordered using any of the [list methods][renderlists]. + +## Displaying custom metadata in Taxonomy Terms Templates + +If you need to display custom metadata for each taxonomy term, you will need to create a page for that term at `/content///_index.md` and add your metadata in its front matter, [as explained in the taxonomies documentation](/content-management/taxonomies/#add-custom-metadata-to-a-taxonomy-or-term). Based on the Actors taxonomy example shown there, within your taxonomy terms template, you may access your custom fields by iterating through the variable `.Pages` as such: + +```go-html-template +
    + {{ range .Pages }} +
  • + {{ .Title }} + {{ .Params.wikipedia }} +
  • + {{ end }} +
+``` + + + +## Order Taxonomies + +Taxonomies can be ordered by either alphabetical key or by the number of content pieces assigned to that key. + +### Order Alphabetically Example + +```go-html-template +
    + {{ range .Data.Terms.Alphabetical }} +
  • {{ .Page.Title }} {{ .Count }}
  • + {{ end }} +
+``` + + + +## Order Content within Taxonomies + +Hugo uses both `date` and `weight` to order content within taxonomies. + +Each piece of content in Hugo can optionally be assigned a date. It can also be assigned a weight for each taxonomy it is assigned to. + +When iterating over content within taxonomies, the default sort is the same as that used for section and list pages: first by weight, then by date. This means that if the weights for two pieces of content are the same, then the more recent content will be displayed first. + +The default weight for any piece of content is 0. Zero means "does not have a weight", not "has a weight of numerical value zero". + +Weights of zero are thus treated specially: if two pages have unequal weights, and one of them is zero, then the zero-weighted page will always appear after the other one, regardless of the other's weight. Zero weights should thus be used with care: for example, if both positive and negative weights are used to extend a sequence in both directions, a zero-weighted page will appear not in the middle of the list, but at the end. + +### Assign Weight + +Content can be assigned weight for each taxonomy that it's assigned to. + - ```txt - +++ ++ ++{{< code-toggle file="content/example.md" fm=true copy=false >}} +tags = [ "a", "b", "c" ] +tags_weight = 22 +categories = ["d"] - title = "foo" ++title = "Example" +categories_weight = 44 - +++ - Front Matter with weighted tags and categories - ``` ++{{< /code-toggle >}} + +The convention is `taxonomyname_weight`. + +In the above example, this piece of content has a weight of 22 which applies to the sorting when rendering the pages assigned to the "a", "b" and "c" values of the 'tag' taxonomy. + +It has also been assigned the weight of 44 when rendering the 'd' category. + +With this the same piece of content can appear in different positions in different taxonomies. + +Currently taxonomies only support the default ordering of content which is weight -> date. + + + +There are two different templates that the use of taxonomies will require you to provide. + +Both templates are covered in detail in the templates section. + - A [list template](/templates/list/) is any template that will be used to render multiple pieces of content in a single html page. This template will be used to generate all the automatically created taxonomy pages. ++A [list template](/templates/lists/) is any template that will be used to render multiple pieces of content in a single html page. This template will be used to generate all the automatically created taxonomy pages. + - A [taxonomy terms template](/templates/terms/) is a template used to ++A [taxonomy template](/templates/taxonomy-templates/) is a template used to +generate the list of terms for a given template. + + + +There are four common ways you can display the data in your +taxonomies in addition to the automatic taxonomy pages created by hugo - using the [list templates](/templates/list/): ++using the [list templates](/templates/lists/): + +1. For a given piece of content, you can list the terms attached +2. For a given piece of content, you can list other content with the same + term +3. You can list all terms for a taxonomy +4. You can list all taxonomies (with their terms) + +## Display a Single Piece of Content's Taxonomies + +Within your content templates, you may wish to display the taxonomies that piece of content is assigned to. + +Because we are leveraging the front matter system to define taxonomies for content, the taxonomies assigned to each content piece are located in the usual place (i.e., `.Params.`). + +### Example: List Tags in a Single Page Template + +```go-html-template + +``` + +If you want to list taxonomies inline, you will have to take care of optional plural endings in the title (if multiple taxonomies), as well as commas. Let's say we have a taxonomy "directors" such as `directors: [ "Joel Coen", "Ethan Coen" ]` in the TOML-format front matter. + +To list such taxonomies, use the following: + +### Example: Comma-delimit Tags in a Single Page Template + +```go-html-template +{{ $taxo := "directors" }} +{{ with .Param $taxo }} + Director{{ if gt (len .) 1 }}s{{ end }}: + {{ range $index, $director := . }} + {{- if gt $index 0 }}, {{ end -}} + {{ with $.Site.GetPage (printf "/%s/%s" $taxo $director) -}} + {{ $director }} + {{- end -}} + {{- end -}} +{{ end }} +``` + +Alternatively, you may use the [delimit template function][delimit] as a shortcut if the taxonomies should just be listed with a separator. See {{< gh 2143 >}} on GitHub for discussion. + +## List Content with the Same Taxonomy Term + +If you are using a taxonomy for something like a series of posts, you can list individual pages associated with the same taxonomy. This is also a quick and dirty method for showing related content: + +### Example: Showing Content in Same Series + +```go-html-template + +``` + +## List All content in a Given taxonomy + +This would be very useful in a sidebar as “featured content”. You could even have different sections of “featured content” by assigning different terms to the content. + +### Example: Grouping "Featured" Content + +```go-html-template + +``` + +## Render a Site's Taxonomies + +If you wish to display the list of all keys for your site's taxonomy, you can retrieve them from the [`.Site` variable][sitevars] available on every page. + +This may take the form of a tag cloud, a menu, or simply a list. + +The following example displays all terms in a site's tags taxonomy: + +### Example: List All Site Tags {#example-list-all-site-tags} + +```go-html-template + +``` + +### Example: List All Taxonomies, Terms, and Assigned Content + +This example will list all taxonomies and their terms, as well as all the content assigned to each of the terms. + - {{< code file="layouts/partials/all-taxonomies.html" download="all-taxonomies.html" download="all-taxonomies.html" >}} ++{{< code file="layouts/partials/all-taxonomies.html" >}} +
+
    + {{ range $taxonomy_term, $taxonomy := .Site.Taxonomies }} + {{ with $.Site.GetPage (printf "/%s" $taxonomy_term) }} +
  • {{ $taxonomy_term }} + +
  • + {{ end }} + {{ end }} +
+
+{{< /code >}} + +## `.Site.GetPage` for Taxonomies + - Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to get all the pages associated with a particular taxonomy term using a terse syntax. The following ranges over the full list of tags on your site and links to each of the individual taxonomy pages for each term without having to use the more fragile URL construction of the ["List All Site Tags" example above]({{< relref "#example-list-all-site-tags" >}}): ++Because taxonomies are lists, the [`.GetPage` function][getpage] can be used to get all the pages associated with a particular taxonomy term using a terse syntax. The following ranges over the full list of tags on your site and links to each of the individual taxonomy pages for each term without having to use the more fragile URL construction of the ["List All Site Tags" example above](#example-list-all-site-tags): + +{{< code file="links-to-all-tags.html" >}} +{{ $taxo := "tags" }} +
    + {{ with ($.Site.GetPage (printf "/%s" $taxo)) }} + {{ range .Pages }} -
  • {{ .Title}}
  • ++
  • {{ .Title }}
  • + {{ end }} + {{ end }} +
+{{< /code >}} + + + + + + +[delimit]: /functions/delimit/ +[getpage]: /functions/getpage/ +[lists]: /templates/lists/ +[renderlists]: /templates/lists/ +[single page template]: /templates/single-page-templates/ +[sitevars]: /variables/site/ diff --cc docs/content/en/templates/template-debugging.md index b8938890f,000000000..0f32fa732 mode 100644,000000..100644 --- a/docs/content/en/templates/template-debugging.md +++ b/docs/content/en/templates/template-debugging.md @@@ -1,69 -1,0 +1,64 @@@ +--- +title: Template Debugging +description: You can use Go templates' `printf` function to debug your Hugo templates. These snippets provide a quick and easy visualization of the variables available to you in different contexts. - date: 2017-02-01 - publishdate: 2017-02-01 +categories: [templates] +keywords: [debugging,troubleshooting] +menu: + docs: - parent: "templates" ++ parent: templates + weight: 180 +weight: 180 - sections_weight: 180 - aliases: [] - toc: false +--- + +Here are some snippets you can add to your template to answer some common questions. + +These snippets use the `printf` function available in all Go templates. This function is an alias to the Go function, [fmt.Printf](https://pkg.go.dev/fmt). + +## What Variables are Available in this Context? + +You can use the template syntax, `$.`, to get the top-level template context from anywhere in your template. This will print out all the values under, `.Site`. + +```go-html-template +{{ printf "%#v" $.Site }} +``` + +This will print out the value of `.Permalink`: + +```go-html-template +{{ printf "%#v" .Permalink }} +``` + +This will print out a list of all the variables scoped to the current context +(`.`, aka ["the dot"][tempintro]). + +```go-html-template +{{ printf "%#v" . }} +``` + +When developing a [homepage], what does one of the pages you're looping through look like? + +```go-html-template +{{ range .Pages }} + {{/* The context, ".", is now each one of the pages as it goes through the loop */}} + {{ printf "%#v" . }} +{{ end }} +``` + +## Why Am I Showing No Defined Variables? + +Check that you are passing variables in the `partial` function: + +```go-html-template +{{ partial "header.html" }} +``` + +This example will render the header partial, but the header partial will not have access to any contextual variables. You need to pass variables explicitly. For example, note the addition of ["the dot"][tempintro]. + +```go-html-template +{{ partial "header.html" . }} +``` + +The dot (`.`) is considered fundamental to understanding Hugo templating. For more information, see [Introduction to Hugo Templating][tempintro]. + +[homepage]: /templates/homepage/ +[tempintro]: /templates/introduction/ diff --cc docs/content/en/templates/views.md index 495f701bd,000000000..24ff61150 mode 100644,000000..100644 --- a/docs/content/en/templates/views.md +++ b/docs/content/en/templates/views.md @@@ -1,121 -1,0 +1,114 @@@ +--- +title: Content View Templates - # linktitle: Content Views +description: Hugo can render alternative views of your content, which is especially useful in list and summary views. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [templates] +keywords: [views] +menu: + docs: - parent: "templates" ++ parent: templates + weight: 70 +weight: 70 - sections_weight: 70 - draft: false - aliases: [] +toc: true +--- + +These alternative **content views** are especially useful in [list templates][lists]. + +The following are common use cases for content views: + +* You want content of every type to be shown on the homepage but only with limited [summary views][summaries]. +* You only want a bulleted list of your content on a [taxonomy list page][taxonomylists]. Views make this very straightforward by delegating the rendering of each different type of content to the content itself. + +## Create a Content View + +To create a new view, create a template in each of your different content type directories with the view name. The following example contains an "li" view and a "summary" view for the `posts` and `project` content types. As you can see, these sit next to the [single content view][single] template, `single.html`. You can even provide a specific view for a given type and continue to use the `_default/single.html` for the primary view. + +```txt + ▾ layouts/ + ▾ posts/ + li.html + single.html + summary.html + ▾ project/ + li.html + single.html + summary.html +``` + +Hugo also has support for a default content template to be used in the event that a specific content view template has not been provided for that type. Content views can also be defined in the `_default` directory and will work the same as list and single templates who eventually trickle down to the `_default` directory as a matter of the lookup order. + + +```txt +▾ layouts/ + ▾ _default/ + li.html + single.html + summary.html +``` + +## Which Template Will be Rendered? + +The following is the [lookup order][lookup] for content views: + +1. `/layouts//.html` +2. `/layouts/_default/.html` +3. `/themes//layouts//.html` +4. `/themes//layouts/_default/.html` + +## Example: Content View Inside a List + +The following example demonstrates how to use content views inside your [list templates][lists]. + +### `list.html` + +In this example, `.Render` is passed into the template to call the [render function][render]. `.Render` is a special function that instructs content to render itself with the view template provided as the first argument. In this case, the template is going to render the `summary.html` view that follows: + - {{< code file="layouts/_default/list.html" download="list.html" >}} ++{{< code file="layouts/_default/list.html" >}} +
+
-

{{ .Title }}

- {{ range .Pages }} - {{ .Render "summary"}} - {{ end }} ++

{{ .Title }}

++ {{ range .Pages }} ++ {{ .Render "summary" }} ++ {{ end }} +
+
+{{< /code >}} + +### `summary.html` + +Hugo will pass the entire page object to the following `summary.html` view template. (See [Page Variables][pagevars] for a complete list.) + - {{< code file="layouts/_default/summary.html" download="summary.html" >}} ++{{< code file="layouts/_default/summary.html" >}} + +{{< /code >}} + +### `li.html` + +Continuing on the previous example, we can change our render function to use a smaller `li.html` view by changing the argument in the call to the `.Render` function (i.e., `{{ .Render "li" }}`). + - {{< code file="layouts/_default/li.html" download="li.html" >}} ++{{< code file="layouts/_default/li.html" >}} +
  • + {{ .Title }} +
    {{ .Date.Format "Mon, Jan 2, 2006" }}
    +
  • +{{< /code >}} + +[lists]: /templates/lists/ +[lookup]: /templates/lookup-order/ +[pagevars]: /variables/page/ +[render]: /functions/render/ +[single]: /templates/single-page-templates/ +[spf]: https://spf13.com +[spfsourceli]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/li.html +[spfsourcesection]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/section.html +[spfsourcesummary]: https://github.com/spf13/spf13.com/blob/master/layouts/_default/summary.html +[summaries]: /content-management/summaries/ +[taxonomylists]: /templates/taxonomy-templates/ diff --cc docs/content/en/tools/_index.md index a63041819,000000000..b553dac9c mode 100644,000000..100644 --- a/docs/content/en/tools/_index.md +++ b/docs/content/en/tools/_index.md @@@ -1,23 -1,0 +1,19 @@@ +--- +title: Developer Tools +linktitle: Developer Tools Overview +description: In addition to Hugo's powerful CLI, there is a large number of community-developed tool chains for Hugo developers. - date: 2016-12-05 - publishdate: 2016-12-05 - lastmod: 2017-02-26 +categories: [developer tools] +keywords: [] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 01 +weight: 01 - sections_weight: 01 +--- + +One of Hugo's greatest strengths is its passionate---and always evolving---developer community. With the exception of the `highlight` shortcode mentioned in [Syntax Highlighting][syntax], the tools and other projects featured in this section are offerings from both commercial services and open-source projects, many of which are developed by Hugo developers just like you. + +[See the popularity of Hugo compared with other static site generators.][staticgen] + +[staticgen]: https://staticgen.com - [syntax]: /tools/syntax-highlighting/ ++[syntax]: /content-management/syntax-highlighting/ diff --cc docs/content/en/tools/editors.md index ed67885fc,000000000..55ab47090 mode 100644,000000..100644 --- a/docs/content/en/tools/editors.md +++ b/docs/content/en/tools/editors.md @@@ -1,50 -1,0 +1,44 @@@ +--- +title: Editor Plug-ins for Hugo +linktitle: Editor Plug-ins +description: The Hugo community uses a wide range of preferred tools and has developed plug-ins for some of the most popular text editors to help automate parts of your workflow. - date: 2017-02-01 - publishdate: 2017-02-01 +categories: [developer tools] +keywords: [editor, plug-ins] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 50 +weight: 50 - sections_weight: 50 - draft: false - aliases: [] - toc: false +--- + +The Hugo community uses a wide range of preferred tools and has developed plug-ins for some of the most popular text editors to help automate parts of your workflow. + +## Sublime Text + +* [Hugofy](https://github.com/akmittal/Hugofy). Hugofy is a plugin for Sublime Text 3 to make life easier to use Hugo static site generator. +* [Hugo Snippets](https://packagecontrol.io/packages/Hugo%20Snippets). Hugo Snippets is a useful plugin for adding automatic snippets to Sublime Text 3. + +## Visual Studio Code + +* [Hugofy](https://marketplace.visualstudio.com/items?itemName=akmittal.hugofy). Hugofy is a plugin for Visual Studio Code to "make life easier" when developing with Hugo. The source code can be found [here](https://github.com/akmittal/hugofy-vscode). +* [Hugo Helper](https://marketplace.visualstudio.com/items?itemName=rusnasonov.vscode-hugo). Hugo Helper is a plugin for Visual Studio Code that has some useful commands for Hugo. The source code can be found [here](https://github.com/rusnasonov/vscode-hugo). +* [Hugo Language and Syntax Support](https://marketplace.visualstudio.com/items?itemName=budparr.language-hugo-vscode). Hugo Language and Syntax Support is a Visual Studio Code plugin for Hugo syntax highlighting and snippets. The source code can be found [here](https://github.com/budparr/language-hugo-vscode). +* [Hugo Themer](https://marketplace.visualstudio.com/items?itemName=eliostruyf.vscode-hugo-themer). Hugo Themer is an extension to help you while developing themes. It allows you to easily navigate through your theme files. +* [Front Matter](https://marketplace.visualstudio.com/items?itemName=eliostruyf.vscode-front-matter). Once you go for a static site, you need to think about how you are going to manage your articles. Front matter is a tool that helps you maintain the metadata/front matter of your articles like: creation date, modified date, slug, tile, SEO check, and many more... +* [Syntax Highlighting for Hugo Shortcodes](https://marketplace.visualstudio.com/items?itemName=kaellarkin.hugo-shortcode-syntax). This extension add some syntax highlighting for Shortcodes, making visual identification of individual pieces easier. + +## Emacs + +* [emacs-easy-hugo](https://github.com/masasam/emacs-easy-hugo). Emacs major mode for managing hugo blogs. Note that Hugo also supports [Org-mode][formats]. +* [ox-hugo.el](https://ox-hugo.scripter.co). Native Org-mode exporter that exports to Blackfriday Markdown with Hugo front-matter. `ox-hugo` supports two common Org blogging flows --- exporting multiple Org subtrees in a single file to multiple Hugo posts, and exporting a single Org file to a single Hugo post. It also leverages the Org tag and property inheritance features. See [*Why ox-hugo?*](https://ox-hugo.scripter.co/doc/why-ox-hugo/) for more. + +## Vim + +* [Vim Hugo Helper](https://github.com/robertbasic/vim-hugo-helper). A small Vim plugin to help me with writing posts with Hugo. + +## Atom + +* [Hugofy](https://atom.io/packages/hugofy). A Hugo Static Website Generator package for Atom. +* [language-hugo](https://atom.io/packages/language-hugo). Adds syntax highlighting to Hugo files. + +[formats]: /content-management/formats/ diff --cc docs/content/en/tools/frontends.md index 7ad44df53,000000000..1bfaf0995 mode 100644,000000..100644 --- a/docs/content/en/tools/frontends.md +++ b/docs/content/en/tools/frontends.md @@@ -1,29 -1,0 +1,22 @@@ +--- +title: Frontend Interfaces with Hugo +linktitle: Frontends +description: Do you prefer a graphical user interface over a text editor? Give these frontends a try. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [developer tools] +keywords: [frontend, gui] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 40 +weight: 40 - sections_weight: 40 - draft: false - aliases: [] - toc: false +--- + +- [enwrite](https://github.com/zzamboni/enwrite). Enwrite enables evernote-powered, statically generated blogs and websites. Now posting to your blog or updating your website is as easy as writing a new note in Evernote! +- [Lipi](https://github.com/SohanChy/Lipi). Lipi is a native GUI frontend written in Java to manage your Hugo websites. +- [Netlify CMS](https://netlifycms.org). Netlify CMS is an open source, serverless solution for managing Git based content in static sites, and it works on any platform that can host static sites. A [Hugo/Netlify CMS starter](https://github.com/netlify-templates/one-click-hugo-cms) is available to get new projects running quickly. +- [Hokus CMS](https://github.com/julianoappelklein/hokus). Hokus CMS is an open source, multi-platform, easy to use, desktop application for Hugo. Build from simple to complex user interfaces for Hugo websites by choosing from a dozen ready-to-use components — all for free, with no vendor lock-in. + +## Commercial Services + +- [DATOCMS](https://www.datocms.com) DatoCMS is a fully customizable administrative area for your static websites. Use your favorite website generator, let your clients publish new content independently, and the host the site anywhere you like. +- [CloudCannon](https://cloudcannon.com/hugo-cms/). The intuitive Git-based CMS for your Hugo website. CloudCannon syncs changes from your Git repository and pushes content changes back, so your development and content teams are always in sync. Edit all of your content on the page with visual editing, build entire pages with reusable custom components and then publish confidently. diff --cc docs/content/en/tools/migrations.md index d6ca14ab5,000000000..0156c46db mode 100644,000000..100644 --- a/docs/content/en/tools/migrations.md +++ b/docs/content/en/tools/migrations.md @@@ -1,85 -1,0 +1,80 @@@ +--- +title: Migrate to Hugo +linktitle: Migrations +description: A list of community-developed tools for migrating from your existing static site generator or content management system to Hugo. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2022-03-26 +keywords: [migrations, jekyll, wordpress, drupal, ghost, contentful] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 10 +weight: 10 - sections_weight: 10 - draft: false +aliases: [/developer-tools/migrations/, /developer-tools/migrated/] +toc: true +--- + +This section highlights some projects around Hugo that are independently developed. These tools try to extend the functionality of our static site generator or help you to get started. + +{{% note %}} +Do you know or maintain a similar project around Hugo? Feel free to open a [pull request](https://github.com/gohugoio/hugoDocs/pulls) on GitHub if you think it should be added. +{{% /note %}} + +Take a look at this list of migration tools if you currently use other blogging tools like Jekyll or WordPress but intend to switch to Hugo instead. They'll take care to export your content into Hugo-friendly formats. + +## Jekyll + +Alternatively, you can use the new [Jekyll import command](/commands/hugo_import_jekyll/). + +- [JekyllToHugo](https://github.com/fredrikloch/JekyllToHugo) - A Small script for converting Jekyll blog posts to a Hugo site. +- [ConvertToHugo](https://github.com/coderzh/ConvertToHugo) - Convert your blog from Jekyll to Hugo. + +## Ghost + +- [ghostToHugo](https://github.com/jbarone/ghostToHugo) - Convert Ghost blog posts and export them to Hugo. + +## Octopress + +- [octohug](https://github.com/codebrane/octohug) - Octopress to Hugo migrator. + +## DokuWiki + +- [dokuwiki-to-hugo](https://github.com/wgroeneveld/dokuwiki-to-hugo) - Migrates your DokuWiki source pages from [DokuWiki syntax](https://www.dokuwiki.org/wiki:syntax) to Hugo Markdown syntax. Includes extra's like the TODO plugin. Written with extensibility in mind using python 3. Also generates a TOML header for each page. Designed to copypaste the wiki directory into your /content directory. + +## WordPress + +- [wordpress-to-hugo-exporter](https://github.com/SchumacherFM/wordpress-to-hugo-exporter) - A one-click WordPress plugin that converts all posts, pages, taxonomies, metadata, and settings to Markdown and YAML which can be dropped into Hugo. (Note: If you have trouble using this plugin, you can [export your site for Jekyll](https://wordpress.org/plugins/jekyll-exporter/) and use Hugo's built in Jekyll converter listed above.) +- [blog2md](https://github.com/palaniraja/blog2md) - Works with [exported xml](https://en.support.wordpress.com/export/) file of your free YOUR-TLD.wordpress.com website. It also saves approved comments to `YOUR-POST-NAME-comments.md` file along with posts. +- [wordhugopress](https://github.com/nantipov/wordhugopress) - A small utility written in Java, exports the entire WordPress site from the database and resource (e.g. images) files stored locally or remotely. Therefore, migration from the backup files is possible. Supports merging of the multiple WordPress sites into a single Hugo one. + +## Medium + +- [medium2md](https://github.com/gautamdhameja/medium-2-md) - A simple Medium to Hugo exporter able to import stories in one command, including Front Matter. +- [medium-to-hugo](https://github.com/bgadrian/medium-to-hugo) - CLI tool written in Go to export medium posts into a Hugo compatible Markdown format. Tags and images are included. All images will be downloaded locally and linked appropriately. + +## Tumblr + +- [tumblr-importr](https://github.com/carlmjohnson/tumblr-importr) - An importer that uses the Tumblr API to create a Hugo static site. +- [tumblr2hugomarkdown](https://github.com/Wysie/tumblr2hugomarkdown) - Export all your Tumblr content to Hugo Markdown files with preserved original formatting. +- [Tumblr to Hugo](https://github.com/jipiboily/tumblr-to-hugo) - A migration tool that converts each of your Tumblr posts to a content file with a proper title and path. Furthermore, "Tumblr to Hugo" creates a CSV file with the original URL and the new path on Hugo, to help you setup the redirections. + +## Drupal + +- [drupal2hugo](https://github.com/danapsimer/drupal2hugo) - Convert a Drupal site to Hugo. + +## Joomla + +- [hugojoomla](https://github.com/davetcc/hugojoomla) - This utility written in Java takes a Joomla database and converts all the content into Markdown files. It changes any URLs that are in Joomla's internal format and converts them to a suitable form. + +## Blogger + +- [blogimport](https://github.com/natefinch/blogimport) - A tool to import from Blogger posts to Hugo. +- [blogger-to-hugo](https://pypi.org/project/blogger-to-hugo/) - Another tool to import Blogger posts to Hugo. It also downloads embedded images so they will be stored locally. +- [blog2md](https://github.com/palaniraja/blog2md) - Works with [exported xml](https://support.google.com/blogger/answer/41387?hl=en) file of your YOUR-TLD.blogspot.com website. It also saves comments to `YOUR-POST-NAME-comments.md` file along with posts. +- [BloggerToHugo](https://github.com/huanlin/blogger-to-hugo) - Yet another tool to import Blogger posts to Hugo. For Windows platform only, and .NET Framework 4.5 is required. See README.md before using this tool. + +## Contentful + - - [contentful2hugo](https://github.com/ArnoNuyts/contentful2hugo) - A tool to create content-files for Hugo from content on [Contentful](https://www.contentful.com/). ++- [contentful-hugo](https://github.com/ModiiMedia/contentful-hugo) - A tool to create content-files for Hugo from content on [Contentful](https://www.contentful.com/). + +## BlogML + +- [BlogML2Hugo](https://github.com/jijiechen/BlogML2Hugo) - A tool that helps you convert BlogML xml file to Hugo Markdown files. Users need to take care of links to attachments and images by themselves. This helps the blogs that export BlogML files (e.g. BlogEngine.NET) transform to hugo sites easily. diff --cc docs/content/en/tools/other.md index ed7c530d0,000000000..3f8aeebbb mode 100644,000000..100644 --- a/docs/content/en/tools/other.md +++ b/docs/content/en/tools/other.md @@@ -1,28 -1,0 +1,23 @@@ +--- +title: Other Hugo Community Projects +linktitle: Other Projects +description: Some interesting projects developed by the Hugo community that don't quite fit into our other developer tool categories. - date: 2017-02-01 - publishdate: 2017-02-01 +categories: [developer tools] +keywords: [frontend, gui] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 70 +weight: 70 - sections_weight: 70 - aliases: [] - toc: false +--- + +And for all the other small things around Hugo: + +- [hugo-gallery](https://github.com/icecreammatt/hugo-gallery) lets you create an image gallery for Hugo sites. +- [flickr-hugo-embed](https://github.com/nikhilm/flickr-hugo-embed) prints shortcodes to embed a set of images from an album on Flickr into Hugo. +- [hugo-openapispec-shortcode](https://github.com/tenfourty/hugo-openapispec-shortcode) A shortcode that allows you to include [Open API Spec](https://openapis.org) (formerly known as Swagger Spec) in a page. +- [HugoPhotoSwipe](https://github.com/GjjvdBurg/HugoPhotoSwipe) makes it easy to create image galleries using PhotoSwipe. +- [Hugo SFTP Upload](https://github.com/thomasmey/HugoSftpUpload) Syncs the local build of your Hugo website with your remote webserver via SFTP. +- [Emacs Easy Hugo](https://github.com/masasam/emacs-easy-hugo) Emacs package for writing blog posts in markdown or org-mode and building your site with Hugo. +- [JAMStack Themes](https://jamstackthemes.dev/ssg/hugo/). JAMStack themes is a collection of site themes filterable by static site generator and supported CMS to help build CMS-connected sites using Hugo (linking to Hugo-specific themes). +- [plausible-hugo](https://github.com/divinerites/plausible-hugo). Easy Hugo integration for Plausible Analytics, a simple, open-source, lightweight and privacy-friendly web analytics alternative to Google Analytics. diff --cc docs/content/en/tools/search.md index 464aa9107,000000000..030e9f2c7 mode 100644,000000..100644 --- a/docs/content/en/tools/search.md +++ b/docs/content/en/tools/search.md @@@ -1,36 -1,0 +1,30 @@@ +--- +title: Search for your Hugo Website +linktitle: Search +description: See some of the open-source and commercial search options for your newly created Hugo website. - date: 2017-02-01 - publishdate: 2017-02-01 - categories: [developer tools] - keywords: [search,tools] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 60 +weight: 60 - sections_weight: 60 - aliases: [] +toc: true +--- + +A static website with a dynamic search function? Yes, Hugo provides an alternative to embeddable scripts from Google or other search engines for static websites. Hugo allows you to provide your visitors with a custom search function by indexing your content files directly. + +* [GitHub Gist for Hugo Workflow](https://gist.github.com/sebz/efddfc8fdcb6b480f567). This gist contains a simple workflow to create a search index for your static website. It uses a simple Grunt script to index all your content files and [lunr.js](https://lunrjs.com/) to serve the search results. + +* [hugo-lunr](https://www.npmjs.com/package/hugo-lunr). A simple way to add site search to your static Hugo site using [lunr.js](https://lunrjs.com/). Hugo-lunr will create an index file of any HTML and Markdown documents in your Hugo project. +* [hugo-lunr-zh](https://www.npmjs.com/package/hugo-lunr-zh). A bit like Hugo-lunr, but Hugo-lunr-zh can help you separate the Chinese keywords. +* [GitHub Gist for Fuse.js integration](https://gist.github.com/eddiewebb/735feb48f50f0ddd65ae5606a1cb41ae). This gist demonstrates how to leverage Hugo's existing build time processing to generate a searchable JSON index used by [Fuse.js](https://fusejs.io/) on the client-side. Although this gist uses Fuse.js for fuzzy matching, any client-side search tool capable of reading JSON indexes will work. Does not require npm, grunt or other build-time tools except Hugo! +* [hugo-search-index](https://www.npmjs.com/package/hugo-search-index). A library containing Gulp tasks and a prebuilt browser script that implements search. Gulp generates a search index from project markdown files. +* [hugofastsearch](https://gist.github.com/cmod/5410eae147e4318164258742dd053993). A usability and speed update to "GitHub Gist for Fuse.js integration" — global, keyboard-optimized search. +* [JS & Fuse.js tutorial](https://makewithhugo.com/add-search-to-a-hugo-site/) A simple client-side search solution, using FuseJS (does not require jQuery). +* [Pagefind](https://github.com/cloudcannon/pagefind). A fully static search library that aims to perform well on large sites, while using as little of your users' bandwidth as possible. +* [Hugo Lyra](https://github.com/paolomainardi/hugo-lyra). Hugo-Lyra is a JavaScript module to integrate [Lyra](https://github.com/LyraSearch/lyra) into a Hugo website. It contains the server-side part to generate the index and the client-side library (optional) to bootstrap the search engine easily. + +## Commercial Search Services + +* [Algolia](https://www.algolia.com/)'s Search API makes it easy to deliver a great search experience in your apps and websites. Algolia Search provides hosted full-text, numerical, faceted, and geolocalized search. - * [Bonsai](https://www.bonsai.io) is a fully-managed hosted Elasticsearch service that is fast, reliable, and simple to set up. Easily ingest your docs from Hugo into Elasticsearch following [this guide from the docs](https://docs.bonsai.io/docs/hugo). ++* [Bonsai](https://www.bonsai.io) is a fully-managed hosted Elasticsearch service that is fast, reliable, and simple to set up. Easily ingest your docs from Hugo into Elasticsearch following [this guide from the docs](https://docs.bonsai.io/hc/en-us/articles/13929190788756-Hugo). +* [ExpertRec](https://www.expertrec.com/) is a hosted search-as-a-service solution that is fast and scalable. Set-up and integration is extremely easy and takes only a few minutes. The search settings can be modified without coding using a dashboard. diff --cc docs/content/en/tools/starter-kits.md index 8399e99df,000000000..69c8f3e0b mode 100644,000000..100644 --- a/docs/content/en/tools/starter-kits.md +++ b/docs/content/en/tools/starter-kits.md @@@ -1,38 -1,0 +1,31 @@@ +--- +title: Starter Kits - linktitle: Starter Kits +description: A list of community-developed projects designed to help you get up and running with Hugo. - date: 2017-02-22 - publishdate: 2017-02-01 - lastmod: 2018-08-11 +keywords: [starters,assets,pipeline] +menu: + docs: - parent: "tools" ++ parent: tools + weight: 30 +weight: 30 - sections_weight: 30 - draft: false +aliases: [/developer-tools/migrations/,/developer-tools/migrated/] - toc: false +--- + +Know of a Hugo-related starter kit that isn't mentioned here? [Please add it to the list.][addkit] + - {{% note "Starter Kits are Not Maintained by the Hugo Team"%}} ++{{% note %}} +The following starter kits are developed by active members of the Hugo community. If you find yourself having issues with any of the projects, it's best to file an issue directly with the project's maintainer(s). +{{% /note %}} + +* [Wowchemy]. Wowchemy is the 5,500+ star open source Hugo starter kit and website builder trusted by 750,000+ sites since 2016. Create _any_ kind of site with [50+ templates, widgets, and extensions](https://wowchemy.com/). Translated into 35+ languages and backed by a large, active community of 150+ contributors. +* [Hugo Wrapper][hugow]. Hugo Wrapper is a POSIX-style shell script which acts as a wrapper to download and run Hugo binary for your platform. It can be executed in variety of [Operating Systems][hugow-test] and [Command Shells][hugow-test]. +* [GOHUGO AMP]. GoHugo AMP is a starter theme that aims to make it easy to adopt [Google's AMP Project][amp]. The starter kit comes with 40+ shortcodes and partials plus automatic structured data. The project also includes a [separate site with extensive documentation][gohugodocs]. +* [Hyas]. Hyas is a Hugo starter helping you build modern websites that are secure, fast, and SEO-ready — by default. It is Netlify-ready (functions, redirects, headers) and comes with [documentation](https://gethyas.com/) to easily make it your own. + +[Wowchemy]: https://github.com/wowchemy/wowchemy-hugo-modules +[addkit]: https://github.com/gohugoio/hugo/edit/master/docs/content/en/tools/starter-kits.md +[amp]: https://amp.dev +[GOHUGO AMP]: https://github.com/wildhaber/gohugo-amp - [gohugodocs]: https://gohugo-amp.gohugohq.com/ ++[gohugodocs]: https://github.com/wildhaber/gohugo-amp.gohugohq.com +[hugow]: https://github.com/khos2ow/hugo-wrapper +[hugow-test]: https://github.com/khos2ow/hugo-wrapper#tested-on +[Hyas]: https://github.com/h-enk/hyas diff --cc docs/content/en/troubleshooting/_index.md index 3170dc7d8,000000000..51f1791a3 mode 100644,000000..100644 --- a/docs/content/en/troubleshooting/_index.md +++ b/docs/content/en/troubleshooting/_index.md @@@ -1,23 -1,0 +1,14 @@@ +--- +title: Troubleshoot - linktitle: Troubleshoot +description: Frequently asked questions and known issues pulled from the Hugo Discuss forum. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +menu: + docs: - parent: "troubleshooting" ++ parent: troubleshooting + weight: 1 +weight: 1 - draft: false - hidesectioncontents: false - slug: +aliases: [/troubleshooting/faqs/,/faqs/] - toc: false - notesforauthors: +--- + +The Troubleshooting section includes known issues, recent workarounds, and FAQs pulled from the [Hugo Discussion Forum][forum]. + +[forum]: https://discourse.gohugo.io diff --cc docs/content/en/troubleshooting/build-performance.md index ea31ef84b,000000000..b58cdc11f mode 100644,000000..100644 --- a/docs/content/en/troubleshooting/build-performance.md +++ b/docs/content/en/troubleshooting/build-performance.md @@@ -1,94 -1,0 +1,87 @@@ +--- +title: Build Performance - linktitle: Build Performance +description: An overview of features used for diagnosing and improving performance issues in site builds. - date: 2017-03-12 - publishdate: 2017-03-12 - keywords: [performance, build] - categories: [troubleshooting] +menu: + docs: - parent: "troubleshooting" ++ parent: troubleshooting +weight: 3 - slug: - aliases: [] +toc: true +--- + +## Template Metrics + +Hugo is a very fast static site generator, but it is possible to write +inefficient templates. Hugo's _template metrics_ feature is extremely helpful +in pinpointing which templates are executed most often and how long those +executions take **in terms of CPU time**. + +| Metric Name | Description | +| ------------------- | -------------------------------------------------------------- | +| cumulative duration | The cumulative time spent executing a given template. | +| average duration | The average time spent executing a given template. | +| maximum duration | The maximum time a single execution took for a given template. | +| count | The number of times a template was executed. | +| template | The template name. | + +```txt +▶ hugo --templateMetrics +Started building sites ... + +Built site for language en: +0 draft content +0 future content +0 expired content +2 regular pages created +22 other pages created +0 non-page files copied +0 paginator pages created +4 tags created +3 categories created +total in 18 ms + +Template Metrics: + + cumulative average maximum + duration duration duration count template + ---------- -------- -------- ----- -------- + 6.419663ms 583.605µs 994.374µs 11 _internal/_default/rss.xml + 4.718511ms 1.572837ms 3.880742ms 3 indexes/category.html + 4.642666ms 2.321333ms 3.282842ms 2 posts/single.html + 4.364445ms 396.767µs 2.451372ms 11 partials/header.html + 2.346069ms 586.517µs 903.343µs 4 indexes/tag.html + 2.330919ms 211.901µs 2.281342ms 11 partials/header.includes.html + 1.238976ms 103.248µs 446.084µs 12 posts/li.html + 972.16µs 972.16µs 972.16µs 1 _internal/_default/sitemap.xml + 953.597µs 953.597µs 953.597µs 1 index.html + 822.263µs 822.263µs 822.263µs 1 indexes/post.html + 567.498µs 51.59µs 112.205µs 11 partials/navbar.html + 348.22µs 31.656µs 88.249µs 11 partials/meta.html + 346.782µs 173.391µs 276.176µs 2 posts/summary.html + 235.184µs 21.38µs 124.383µs 11 partials/footer.copyright.html + 132.003µs 12µs 117.999µs 11 partials/menu.html + 72.547µs 6.595µs 63.764µs 11 partials/footer.html +``` + +{{% note %}} +**A Note About Parallelism** + +Hugo builds pages in parallel where multiple pages are generated +simultaneously. Because of this parallelism, the sum of "cumulative duration" +values is usually greater than the actual time it takes to build a site. +{{% /note %}} + +## Cached Partials + +Some `partial` templates such as sidebars or menus are executed many times +during a site build. Depending on the content within the `partial` template and +the desired output, the template may benefit from caching to reduce the number +of executions. The [`partialCached`][partialcached] template function provides +caching capabilities for `partial` templates. + - {{% tip %}} ++{{% note %}} +Note that you can create cached variants of each `partial` by passing additional +parameters to `partialCached` beyond the initial context. See the +`partialCached` documentation for more details. - {{% /tip %}} ++{{% /note %}} + - [partialCached]:{{< ref "/functions/partialCached.md" >}} ++[partialCached]: /functions/partialcached diff --cc docs/content/en/troubleshooting/faq.md index 998f9bbbe,000000000..04e857acb mode 100644,000000..100644 --- a/docs/content/en/troubleshooting/faq.md +++ b/docs/content/en/troubleshooting/faq.md @@@ -1,62 -1,0 +1,61 @@@ +--- +title: Frequently Asked Questions +linktitle: FAQ +description: Solutions to some common Hugo problems. - date: 2018-02-10 +categories: [troubleshooting] +menu: + docs: - parent: "troubleshooting" ++ parent: troubleshooting +keywords: [faqs] +weight: 2 +toc: true +aliases: [/faq/] +--- + +{{% note %}} +**Note:** The answers/solutions presented below are short, and may not be enough to solve your problem. Visit [Hugo Discourse](https://discourse.gohugo.io/) and use the search. It that does not help, start a new topic and ask your questions. +{{% /note %}} + +## I can't see my content! + +Is your Markdown file [in draft mode](https://gohugo.io/content-management/front-matter/#front-matter-variables)? When testing, run `hugo server` with the `-D` or `--buildDrafts` [switch](https://gohugo.io/getting-started/usage/#draft-future-and-expired-content). + +Is your Markdown file part of a [leaf bundle](/content-management/page-bundles/)? If there is an `index.md` file in the same or any parent directory then other Markdown files will not be rendered as individual pages. + +## Can I set configuration variables via OS environment? + +Yes you can! See [Configure with Environment Variables](/getting-started/configuration/#configure-with-environment-variables). + +## How do I schedule posts? + +1. Set `publishDate` in the page [Front Matter](/content-management/front-matter/) to a datetime in the future. If you want the creation and publication datetime to be the same, it's also sufficient to only set `date`[^date-hierarchy]. +2. Build and publish at intervals. + +How to automate the "publish at intervals" part depends on your situation: + +* If you deploy from your own PC/server, you can automate with [Cron](https://en.wikipedia.org/wiki/Cron) or similar. +* If your site is hosted on a service similar to [Netlify](https://www.netlify.com/) you can: + * Use a service such as [ifttt](https://ifttt.com/date_and_time) to schedule the updates + * Set up a deploy hook which you can run with a cron service to deploy your site at intervals, such as [cron-job.org](https://cron-job.org/) (both Netlify and Cloudflare Pages support deploy hooks) + +Also see this Twitter thread: + +{{< tweet user="ChrisShort" id="962380712027590657" >}} + +[^date-hierarchy]: See [Configure Dates](https://gohugo.io/getting-started/configuration/#configure-dates) for the order in which the different date variables are complemented by each other when not explicitly set. + +## Can I use the latest Hugo version on Netlify? + +Yes you can! Read [this](/hosting-and-deployment/hosting-on-netlify/#configure-hugo-version-in-netlify). + +## I get "... this feature is not available in your current Hugo version" + +If you process `SCSS` or `Sass` to `CSS` in your Hugo project with `libsass` as the transpiler or if you convert images to the `webp` format, you need the Hugo `extended` version, or else you may see an error message similar to the below: + +```bash +error: failed to transform resource: TOCSS: failed to transform "scss/main.scss" (text/x-scss): this feature is not available in your current Hugo version +``` + +We release two set of binaries for technical reasons. The extended version is not what you get by default for some installation methods. On the [release page](https://github.com/gohugoio/hugo/releases), look for archives with `extended` in the name. To build `hugo-extended`, use `go install --tags extended` + +To confirm, run `hugo version` and look for the word `extended`. diff --cc docs/content/en/variables/_index.md index 382ee25d4,000000000..9b5289573 mode 100644,000000..100644 --- a/docs/content/en/variables/_index.md +++ b/docs/content/en/variables/_index.md @@@ -1,23 -1,0 +1,17 @@@ +--- +title: Variables and Params +linktitle: Variables Overview +description: Page-, file-, taxonomy-, and site-level variables and parameters available in templates. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [variables and params] +keywords: [variables,params,values,globals] - draft: false +menu: + docs: - parent: "variables" ++ parent: variables + weight: 1 - weight: 01 #rem - sections_weight: 01 ++weight: 01 +aliases: [/templates/variables/] - toc: false +--- + +Hugo's templates are context aware and make a large number of values available to you as you're creating views for your website. + +[Go templates]: /templates/introduction/ "Understand context in Go templates by learning the language's fundamental templating functions." diff --cc docs/content/en/variables/files.md index 4e6c0632f,000000000..784ab7c64 mode 100644,000000..100644 --- a/docs/content/en/variables/files.md +++ b/docs/content/en/variables/files.md @@@ -1,54 -1,0 +1,102 @@@ +--- +title: File Variables - linktitle: - description: "You can access filesystem-related data for a content file in the `.File` variable." - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 ++description: "Use File variables to access file-related values for each page that is backed by a file." +categories: [variables and params] +keywords: [files] - draft: false +menu: + docs: - parent: "variables" ++ parent: variables + weight: 40 ++toc: true +weight: 40 - sections_weight: 40 +aliases: [/variables/file-variables/] - toc: false +--- ++## Variables + - {{% note "Rendering Local Files" %}} - For information on creating shortcodes and templates that tap into Hugo's file-related feature set, see [Local File Templates](/templates/files/). ++{{% note %}} ++The path separators (slash or backslash) in `.File.Path`, `.File.Dir`, and `.File.Filename` depend on the operating system. +{{% /note %}} + - The `.File` object contains the following fields: - +.File.Path - : the original relative path of the page, relative to the content dir (e.g., `posts/foo.en.md`) - - .File.LogicalName - : the name of the content file that represents a page (e.g., `foo.en.md`) ++: (`string`) The file path, relative to the `content` directory. + - .File.TranslationBaseName - : the filename without extension or optional language identifier (e.g., `foo`) ++.File.Dir ++: (`string`) The file path, excluding the file name, relative to the `content` directory. + - .File.ContentBaseName - : is either a TranslationBaseName or name of containing folder if file is a leaf bundle. ++.File.LogicalName ++: (`string`) The file name. + +.File.BaseFileName - : the filename without extension (e.g., `foo.en`) ++: (`string`) The file name, excluding the extension. ++ ++.File.TranslationBaseName ++: (`string`) The file name, excluding the extension and language identifier. + +.File.Ext - : the file extension of the content file (e.g., `md`). ++: (`string`) The file extension. + +.File.Lang - : the language associated with the given file if Hugo's [Multilingual features][multilingual] are enabled (e.g., `en`) ++: (`string`) The language associated with the given file. + - .File.Dir - : given the path `content/posts/dir1/dir2/`, the relative directory path of the content file will be returned (e.g., `posts/dir1/dir2/`). Note that the path separator (`\` or `/`) could be dependent on the operating system. ++ ++.File.ContentBaseName ++: (`string`) If the page is a branch or leaf bundle, the name of the containing directory, else the `.TranslationBaseName`. ++ ++.File.Filename ++: (`string`) The absolute file path. + +.File.UniqueID - : the MD5-checksum of the content file's path. ++: (`string`) The MD5 hash of `.File.Path`. ++ ++## Examples ++ ++```text ++content/ ++├── news/ ++│   ├── b/ ++│   │   ├── index.de.md <-- leaf bundle ++│   │   └── index.en.md <-- leaf bundle ++│   ├── a.de.md <-- regular content ++│   ├── a.en.md <-- regular content ++│   ├── _index.de.md <-- branch bundle ++│   └── _index.en.md <-- branch bundle ++├── _index.de.md ++└── _index.en.md ++``` ++ ++With the content structure above, the `.File` objects for the English pages contain the following properties: ++ ++ |regular content|leaf bundle|branch bundle ++:--|:--|:--|:-- ++Path|news/a.en.md|news/b/index.en.md|news/_index.en.md ++Dir|news/|news/b/|news/ ++LogicalName|a.en.md|index.en.md|_index.en.md ++BaseFileName|a.en|index.en|_index.en ++TranslationBaseName|a|index|_index ++Ext|md|md|md ++Lang|en|en|en ++ContentBaseName|a|b|news ++Filename|/home/user/...|/home/user/...|/home/user/... ++UniqueID|15be14b...|186868f...|7d9159d... ++ ++## Defensive coding ++ ++Some of the pages on a site may not be backed by a file. For example: ++ ++- Top level section pages ++- Taxonomy pages ++- Term pages ++ ++Without a backing file, Hugo will throw a warning if you attempt to access a `.File` property. For example: ++ ++```text ++WARN .File.ContentBaseName on zero object. Wrap it in if or with... ++``` ++ ++To code defensively: + - [Multilingual]: /content-management/multilingual/ ++```go-html-template ++{{ with .File }} ++ {{ .ContentBaseName }} ++{{ end }} ++``` diff --cc docs/content/en/variables/git.md index 24878e350,000000000..dfd6e5407 mode 100644,000000..100644 --- a/docs/content/en/variables/git.md +++ b/docs/content/en/variables/git.md @@@ -1,58 -1,0 +1,51 @@@ +--- +title: Git Info Variables +linktitle: Git Variables +description: Get the last Git revision information for every content file. - date: 2017-03-12 - publishdate: 2017-03-12 - lastmod: 2017-03-12 +categories: [variables and params] +keywords: [git] - draft: false +menu: + docs: - parent: "variables" ++ parent: variables + weight: 70 +weight: 70 - sections_weight: 70 +aliases: [/extras/gitinfo/] - toc: false - wip: false +--- + - {{% note "`.GitInfo` Performance Considerations" %}} ++{{% note %}} +Hugo's Git integrations should be fairly performant but *can* increase your build time. This will depend on the size of your Git history. +{{% /note %}} + +## `.GitInfo` Prerequisites + +1. The Hugo site must be in a Git-enabled directory. +2. The Git executable must be installed and in your system `PATH`. +3. The `.GitInfo` feature must be enabled in your Hugo project by passing `--enableGitInfo` flag on the command line or by setting `enableGitInfo` to `true` in your [site's configuration file][configuration]. + +## The `.GitInfo` Object + +The `GitInfo` object contains the following fields: + +.AbbreviatedHash +: the abbreviated commit hash (e.g., `866cbcc`) + +.AuthorName +: the author's name, respecting [`.mailmap`](https://git-scm.com/docs/gitmailmap) + +.AuthorEmail +: the author's email address, respecting [`.mailmap`](https://git-scm.com/docs/gitmailmap) + +.AuthorDate +: the author date + +.Hash +: the commit hash (e.g., `866cbccdab588b9908887ffd3b4f2667e94090c3`) + +.Subject +: commit message subject (e.g., `tpl: Add custom index function`) + +## `.Lastmod` + +If the `.GitInfo` feature is enabled, `.Lastmod` (on `Page`) is fetched from Git i.e. `.GitInfo.AuthorDate`. This behavior can be changed by adding your own [front matter configuration for dates](/getting-started/configuration/#configure-front-matter). + +[configuration]: /getting-started/configuration/ diff --cc docs/content/en/variables/menus.md index a59560729,000000000..b88514803 mode 100644,000000..100644 --- a/docs/content/en/variables/menus.md +++ b/docs/content/en/variables/menus.md @@@ -1,127 -1,0 +1,92 @@@ +--- - title: Menu Entry Properties - linktitle: Menu Entry Properties - description: A menu entry in a menu-template has specific variables and functions to make menu management easier. - date: 2017-03-12 - publishdate: 2017-03-12 - lastmod: 2017-03-12 ++title: Menu Variables ++description: Use these variables and methods in your menu templates. +categories: [variables and params] +keywords: [menus] - draft: false +menu: + docs: - title: "variables defined by a menu entry" - parent: "variables" ++ parent: variables + weight: 50 +weight: 50 - sections_weight: 50 +aliases: [/variables/menu/] - toc: false +--- + - A **menu entry** has the following properties available that can be used in a - [menu template][menu-template]. ++## Variables + - ## Menu Entry Variables ++After [defining menu entries], access their properties in [menu templates] with these variables. ++ ++.Children ++: (`menu`) A collection of child menu entries, if any, under the current menu entry. ++ ++.Identifier ++: (`string`) The `identifier` property of the menu entry. If you define the menu entry [automatically], the page's `.Section`. ++ ++.KeyName ++: (`string`) The `identifier` property of the menu entry, else the `name` property. + +.Menu - : _string_
    - Name of the **menu** that contains this **menu entry**. ++: (`string`) The identifier of the menu that contains the menu entry. + - .URL - : _string_
    - URL that the menu entry points to. The `url` key, if set for the menu entry, - sets this value. If that key is not set, and if the menu entry is set in a page - front-matter, this value defaults to the page's `.RelPermalink`. ++.Name ++: (`string`) The `name` property of the menu entry. ++ ++- If you define the menu entry [automatically], the page's `.LinkTitle`, else the page's `.Title`. ++- If you define the menu [in front matter] or [in site configuration], falls back to the page's `.LinkTitle`, then to the page's `.Title`. + +.Page - : _\*Page_
    - Reference to the [page object][page-object] associated with the menu entry. This - will be non-nil if the menu entry is set via a page's front-matter and not via - the site config. ++: (`page`) A reference to the page associated with the menu entry. + ++ + - .Name - : _string_
    - Name of the menu entry. The `name` key, if set for the menu entry, sets - this value. If that key is not set, and if the menu entry is set in a page - front-matter, this value defaults to the page's `.LinkTitle`. ++.Params ++: (`map`) The `params` property of the menu entry. + - .Identifier - : _string_
    - Value of the `identifier` key if set for the menu entry. This value must be - unique for each menu entry. **It is necessary to set a unique identifier - manually if two or more menu entries have the same `.Name`.** ++.Parent ++: (`string`) The `parent` property of the menu entry. ++ ++.Post ++: (`template.HTML`) The `post` property of the menu entry. + +.Pre - : _template.HTML_
    - Value of the `pre` key if set for the menu entry. This value typically contains - a string representing HTML. ++: (`template.HTML`) The `pre` property of the menu entry. + - .Post - : _template.HTML_
    - Value of the `post` key if set for the menu entry. This value typically contains - a string representing HTML. ++.Title ++: (`string`) The `title` property of the menu entry. + - .Weight - : _int_
    - Value of the `weight` key if set for the menu entry. By default the entries in - a menu are sorted ascending by their `weight`. If that key is not set, and if - the menu entry is set in a page front-matter, this value defaults to the page's - `.Weight`. ++- If you define the menu entry [automatically], the page's `.LinkTitle`, else the page's `.Title`. ++- If you define the menu [in front matter] or [in site configuration], falls back to the page's `.LinkTitle`, then to the page's `.Title`. + - .Parent - : _string_
    - Name (or Identifier if present) of this menu entry's parent **menu entry**. The - `parent` key, if set for the menu entry, sets this value. If this key is set, - this menu entry nests under that parent entry, else it nests directly under the - `.Menu`. ++.URL ++: (`string`) The `.RelPermalink` of the page associated with the menu entry. For menu entries pointing to external resources, the `url` property of the menu entry. + - .Children - : _Menu_
    - This value is auto-populated by Hugo. It is a collection of children menu - entries, if any, under the current menu entry. ++.Weight ++: (`int`) The `weight` property of the menu entry. + - ## Menu Entry Functions ++- If you define the menu entry [automatically], the page's `.Weight`. ++- If you define the menu [in front matter] or [in site configuration], falls back to the page's `.Weight`. + - Menus also have the following functions available: ++## Methods + +.HasChildren - : _boolean_
    - Returns `true` if `.Children` is non-nil. - - .KeyName - : _string_
    - Returns the `.Identifier` if present, else returns the `.Name`. ++: (`bool`) Returns `true` if `.Children` is non-nil. + +.IsEqual - : _boolean_
    - Returns `true` if the two compared menu entries represent the same menu entry. ++: (`bool`) Returns `true` if the compared menu entries represent the same menu entry. + +.IsSameResource - : _boolean_
    - Returns `true` if the two compared menu entries have the same `.URL`. - - .Title - : _string_
    - Link title, meant to be used in the `title` attribute of a menu entry's - ``-tags. Returns the menu entry's `title` key if set. Else, if the menu - entry was created through a page's front-matter, it returns the page's - `.LinkTitle`. Else, it just returns an empty string. - - ## Other Menu-related Functions - - Additionally, here are some relevant methods available to menus on a page: ++: (`bool`) Returns `true` if the compared menu entries point to the same resource. + - .IsMenuCurrent - : _(menu string, menuEntry *MenuEntry ) boolean_
    - See [`.IsMenuCurrent` method](/functions/ismenucurrent/). ++.Page.HasMenuCurrent ++: (`bool`) Use this method to determine ancestors of the active menu entry. See [details](/functions/hasmenucurrent/). + - .HasMenuCurrent - : _(menu string, menuEntry *MenuEntry) boolean_
    - See [`.HasMenuCurrent` method](/functions/hasmenucurrent/). ++.Page.IsMenuCurrent ++: (`bool`) Use this method to determine the active menu entry. See [details](/functions/ismenucurrent/). + - [menu-template]: /templates/menu-templates/ - [page-object]: /variables/page/ ++[automatically]: /content-management/menus/#define-automatically ++[defining menu entries]: /content-management/menus/#overview ++[in front matter]: /content-management/menus/#define-in-front-matter ++[in site configuration]: /content-management/menus/#define-in-site-configuration ++[menu templates]: /templates/menu-templates/ diff --cc docs/content/en/variables/page.md index 2de54ff8b,000000000..f8266965e mode 100644,000000..100644 --- a/docs/content/en/variables/page.md +++ b/docs/content/en/variables/page.md @@@ -1,301 -1,0 +1,325 @@@ +--- +title: Page Variables - linktitle: +description: Page-level variables are defined in a content file's front matter, derived from the content's file location, or extracted from the content body itself. - date: 2017-02-01 - publishdate: 2017-02-01 +categories: [variables and params] +keywords: [pages] - draft: false +menu: + docs: - title: "variables defined by a page" - parent: "variables" ++ parent: variables + weight: 20 +weight: 20 - sections_weight: 20 - aliases: [] +toc: true +--- + +The following is a list of page-level variables. Many of these will be defined in the front matter, derived from file location, or extracted from the content itself. + - {{% note "`.Scratch`" %}} - See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables. - {{% /note %}} - +## Page Variables + +.AlternativeOutputFormats +: contains all alternative formats for a given page; this variable is especially useful `link rel` list in your site's ``. (See [Output Formats](/templates/output-formats/).) + +.Aliases +: aliases of this page + +.Ancestors - : get the ancestors of each page, simplify [breadcrumb navigation]({{< relref "content-management/sections#example-breadcrumb-navigation" >}}) implementation complexity ++: get the ancestors of each page, simplify [breadcrumb navigation](/content-management/sections#example-breadcrumb-navigation) implementation complexity + +.BundleType +: the [bundle] type: `leaf`, `branch`, or an empty string if the page is not a bundle. + +.Content +: the content itself, defined below the front matter. + +.Data +: the data specific to this type of page. + +.Date +: the date associated with the page; `.Date` pulls from the `date` field in a content's front matter. See also `.ExpiryDate`, `.PublishDate`, and `.Lastmod`. + +.Description +: the description for the page. + +.Draft +: a boolean, `true` if the content is marked as a draft in the front matter. + +.ExpiryDate +: the date on which the content is scheduled to expire; `.ExpiryDate` pulls from the `expirydate` field in a content's front matter. See also `.PublishDate`, `.Date`, and `.Lastmod`. + +.File +: filesystem-related data for this content file. See also [File Variables]. + ++.Fragments ++: Fragments returns the fragments for this page. See [Page Fragments](#page-fragments). ++ +.FuzzyWordCount +: the approximate number of words in the content. + +.IsHome +: `true` in the context of the [homepage](/templates/homepage/). + +.IsNode +: always `false` for regular content pages. + +.IsPage +: always `true` for regular content pages. + +.IsSection +: `true` if [`.Kind`](/templates/section-templates/#page-kinds) is `section`. + +.IsTranslated +: `true` if there are translations to display. + +.Keywords +: the meta keywords for the content. + +.Kind +: the page's *kind*. Possible return values are `page`, `home`, `section`, `taxonomy`, or `term`. Note that there are also `RSS`, `sitemap`, `robotsTXT`, and `404` kinds, but these are only available during the rendering of each of these respective page's kind and therefore *not* available in any of the `Pages` collections. + +.Language +: a language object that points to the language's definition in the site `config`. `.Language.Lang` gives you the language code. + +.Lastmod +: the date the content was last modified. `.Lastmod` pulls from the `lastmod` field in a content's front matter. + + - If `lastmod` is not set, and `.GitInfo` feature is disabled, the front matter `date` field will be used. + - If `lastmod` is not set, and `.GitInfo` feature is enabled, `.GitInfo.AuthorDate` will be used instead. + +See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo]. + +.LinkTitle +: access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`. + +.Next - : Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{with .Next}}{{.Permalink}}{{end}}`. Calling `.Next` from the first page returns `nil`. ++: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{ .Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`. + +.NextInSection - : Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{with .NextInSection}}{{.Permalink}}{{end}}`. Calling `.NextInSection` from the first page returns `nil`. ++: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{ .Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`. + +.OutputFormats +: contains all formats, including the current format, for a given page. Can be combined the with [`.Get` function](/functions/get/) to grab a specific format. (See [Output Formats](/templates/output-formats/).) + +.Pages +: a collection of associated pages. This value will be `nil` within - the context of regular content pages. See [`.Pages`]({{< relref "page.md#pages" >}}). ++ the context of regular content pages. See [`.Pages`](#pages). + +.Permalink +: the Permanent link for this page; see [Permalinks](/content-management/urls/) + +.Plain +: the Page content stripped of HTML tags and presented as a string. You may need to pipe the result through the [`htmlUnescape`](/functions/htmlunescape/) function when rendering this value with the HTML [output format](/templates/output-formats#output-format-definitions). + +.PlainWords +: the slice of strings that results from splitting .Plain into words, as defined in Go's [strings.Fields](https://pkg.go.dev/strings#Fields). + +.Prev - : Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{if .Prev}}{{.Prev.Permalink}}{{end}}`. Calling `.Prev` from the last page returns `nil`. ++: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{ .Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`. + +.PrevInSection - : Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{if .PrevInSection}}{{.PrevInSection.Permalink}}{{end}}`. Calling `.PrevInSection` from the last page returns `nil`. ++: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{ .PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`. + +.PublishDate +: the date on which the content was or will be published; `.Publishdate` pulls from the `publishdate` field in a content's front matter. See also `.ExpiryDate`, `.Date`, and `.Lastmod`. + +.RawContent +: raw markdown content without the front matter. Useful with [remarkjs.com]( +https://remarkjs.com) + +.ReadingTime +: the estimated time, in minutes, it takes to read the content. + +.Resources +: resources such as images and CSS that are associated with this page + +.Ref +: returns the permalink for a given reference (e.g., `.Ref "sample.md"`). `.Ref` does *not* handle in-page fragments correctly. See [Cross References](/content-management/cross-references/). + +.RelPermalink +: the relative permanent link for this page. + +.RelRef +: returns the relative permalink for a given reference (e.g., `RelRef +"sample.md"`). `.RelRef` does *not* handle in-page fragments correctly. See [Cross References](/content-management/cross-references/). + +.Site +: see [Site Variables](/variables/site/). + +.Sites +: returns all sites (languages). A typical use case would be to link back to the main language: `
    ...`. + +.Sites.First +: returns the site for the first language. If this is not a multilingual setup, it will return itself. + +.Summary +: a generated summary of the content for easily showing a snippet in a summary view. The breakpoint can be set manually by inserting <!--more--> at the appropriate place in the content page, or the summary can be written independent of the page text. See [Content Summaries](/content-management/summaries/) for more details. + +.TableOfContents +: the rendered [table of contents](/content-management/toc/) for the page. + +.Title +: the title for this page. + +.Translations +: a list of translated versions of the current page. See [Multilingual Mode](/content-management/multilingual/) for more information. + +.TranslationKey +: the key used to map language translations of the current page. See [Multilingual Mode](/content-management/multilingual/) for more information. + +.Truncated +: a boolean, `true` if the `.Summary` is truncated. Useful for showing a "Read more..." link only when necessary. See [Summaries](/content-management/summaries/) for more information. + +.Type +: the [content type](/content-management/types/) of the content (e.g., `posts`). + +.Weight +: assigned weight (in the front matter) to this content, used in sorting. + +.WordCount +: the number of words in the content. + ++## Writable Page-scoped Variables ++ ++[.Scratch][scratch] ++: returns a Scratch to store and manipulate data. In contrast to the [`.Store`][store] method, this scratch is reset on server rebuilds. ++ ++[.Store][store] ++: returns a Scratch to store and manipulate data. In contrast to the [`.Scratch`][scratch] method, this scratch is not reset on server rebuilds. ++ +## Section Variables and Methods + +Also see [Sections](/content-management/sections/). + +{{< readfile file="/content/en/readfiles/sectionvars.md" markdown="true" >}} + +## The `.Pages` Variable {#pages} + +`.Pages` is an alias to `.Data.Pages`. It is conventional to use the +aliased form `.Pages`. + +### `.Pages` compared to `.Site.Pages` + +{{< getcontent path="readfiles/pages-vs-site-pages.md" >}} + ++## Page Fragments ++ ++{{< new-in "0.111.0" >}} ++ ++The `.Fragments` method returns a list of fragments for the current page. ++ ++.Headings ++: A recursive list of headings for the current page. Can be used to generate a table of contents. ++ ++{{< todo >}}add .Headings toc example{{< /todo >}} ++ ++.Identifiers ++: A sorted list of identifiers for the current page. Can be used to check if a page contains a specific identifier or if a page contains duplicate identifiers: ++ ++```go-html-template ++{{ if .Fragments.Identifiers.Contains "my-identifier" }} ++

    Page contains identifier "my-identifier"

    ++{{ end }} ++ ++{{ if gt (.Fragments.Identifiers.Count "my-identifier") 1 }} ++

    Page contains duplicate "my-identifier" fragments

    ++{{ end }} ++``` ++ ++.HeadingsMap ++: Holds a map of headings for the current page. Can be used to start the table of contents from a specific heading. ++ ++Also see the [Go Doc](https://pkg.go.dev/github.com/gohugoio/hugo@v0.111.0/markup/tableofcontents#Fragments) for the return type. ++ ++### Fragments in hooks and shortcodes ++ ++`.Fragments` are safe to call from render hooks, even on the page you're on (`.Page.Fragments`). For shortcodes we recommend that all `.Fragments` usage is nested inside the `{{}}` shortcode delimiter (`{{%/**/%}}` takes part in the ToC creation so it's easy to end up in a situation where you bite yourself in the tail). ++ ++ ++## The global page function ++ ++{{< new-in "0.111.1" >}} ++ ++Hugo almost always passes a `Page` as the data context into the top level template (e.g. `single.html`) (the one exception is the multihost sitemap template). This means that you can access the current page with the `.` variable in the template. ++ ++But when you're deeply nested inside `.Render`, partial etc., accessing that `Page` object isn't always practical or possible. ++ ++For this reason, Hugo provides a global `page` function that you can use to access the current page from anywhere in any template. ++ ++```go-html-template ++{{ page.Title }} ++``` ++ ++There are one caveat with this, and this isn't new, but it's worth mentioning here: There are situations in Hugo where you may see a cached value, e.g. when using `partialCached` or in a shortcode. ++ +## Page-level Params + +Any other value defined in the front matter in a content file, including taxonomies, will be made available as part of the `.Params` variable. + - ```yml - --- - title: My First Post - date: 2017-02-20T15:26:23-06:00 ++{{< code-toggle file="content/example.md" fm=true copy=false >}} ++title: Example +categories: [one] +tags: [two,three,four] - ``` ++{{< /code-toggle >}} + +With the above front matter, the `tags` and `categories` taxonomies are accessible via the following: + +* `.Params.tags` +* `.Params.categories` + - {{% note "Casing of Params" %}} - Page-level `.Params` are *only* accessible in lowercase. - {{% /note %}} - - The `.Params` variable is particularly useful for the introduction of user-defined front matter fields in content files. For example, a Hugo website on book reviews could have the following front matter in `/content/review/book01.md`: ++The `.Params` variable is particularly useful for the introduction of user-defined front matter fields in content files. For example, a Hugo website on book reviews could have the following front matter: + - ```yml - --- - ... ++{{< code-toggle file="content/example.md" fm=true copy=false >}} ++title: Example +affiliatelink: "http://www.my-book-link.here" +recommendedby: "My Mother" - ... - --- - ``` ++{{< /code-toggle >}} + - These fields would then be accessible to the `/themes/yourtheme/layouts/review/single.html` template through `.Params.affiliatelink` and `.Params.recommendedby`, respectively. ++These fields would then be accessible to via `.Params.affiliatelink` and `.Params.recommendedby`. + - Two common situations where this type of front matter field could be introduced is as a value of a certain attribute like `href=""` or by itself to be displayed as text to the website's visitors. - - {{< code file="/themes/yourtheme/layouts/review/single.html" >}} -

    Buy this book

    ++```go-html-template ++

    Buy this book

    +

    It was recommended by {{ .Params.recommendedby }}.

    - {{< /code >}} ++``` + - This template would render as follows, assuming you've set [`uglyURLs`](/content-management/urls/) to `false` in your [site `config`](/getting-started/configuration/): ++This template would render as follows: + - {{< output file="yourbaseurl/review/book01/index.html" >}} ++```html +

    Buy this book

    +

    It was recommended by my Mother.

    - {{< /output >}} ++``` + +{{% note %}} +See [Archetypes](/content-management/archetypes/) for consistency of `Params` across pieces of content. +{{% /note %}} + +### The `.Param` Method + +In Hugo, you can declare params in individual pages and globally for your entire website. A common use case is to have a general value for the site param and a more specific value for some of the pages (i.e., a header image): + +```go-html-template +{{ $.Param "header_image" }} +``` + +The `.Param` method provides a way to resolve a single value according to it's definition in a page parameter (i.e. in the content's front matter) or a site parameter (i.e., in your `config`). + +### Access Nested Fields in Front Matter + +When front matter contains nested fields like the following: + - ```yml - --- ++{{< code-toggle file="content/example.md" fm=true copy=false >}} ++title: Example +author: + given_name: John + family_name: Feminella + display_name: John Feminella - --- - ``` ++{{< /code-toggle >}} ++ +`.Param` can access these fields by concatenating the field names together with a dot: + +```go-html-template +{{ $.Param "author.display_name" }} +``` + - If your front matter contains a top-level key that is ambiguous with a nested key, as in the following case: - - ```yml - --- - favorites.flavor: vanilla - favorites: - flavor: chocolate - --- - ``` - - The top-level key will be preferred. Therefore, the following method, when applied to the previous example, will print `vanilla` and not `chocolate`: - - ```txt - {{ $.Param "favorites.flavor" }} - => vanilla - ``` - +[gitinfo]: /variables/git/ +[File Variables]: /variables/files/ - [bundle]: {{< relref "content-management/page-bundles" >}} ++[bundle]: /content-management/page-bundles ++[scratch]: /functions/scratch ++[store]: /functions/store diff --cc docs/content/en/variables/pages.md index 61036dd74,000000000..15904de95 mode 100644,000000..100644 --- a/docs/content/en/variables/pages.md +++ b/docs/content/en/variables/pages.md @@@ -1,30 -1,0 +1,25 @@@ +--- +title: Pages Methods - linktitle: +description: Pages is the core page collection in Hugo and has many useful methods. - date: 2019-10-20 +categories: [variables and params] +keywords: [pages] - draft: false +menu: + docs: - title: "methods defined on a page collection" - parent: "variables" ++ parent: variables + weight: 21 +weight: 21 - sections_weight: 20 +aliases: [/pages] +toc: true +--- + +Also see [List templates](/templates/lists) for an overview of sort methods. + +## .Next PAGE + +`.Next` and `.Prev` on `Pages` work similar to the methods with the same names on `.Page`, but are more flexible (and slightly slower) as they can be used on any page collection. + - `.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{with .Site.RegularPages.Next . }}{{.RelPermalink}}{{end}}`. Calling `.Next` with the first page in the collection returns `nil`. ++`.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Next . }}{{ .RelPermalink }}{{ end }}`. Calling `.Next` with the first page in the collection returns `nil`. + +## .Prev PAGE + - `.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{with .Site.RegularPages.Prev . }}{{.RelPermalink}}{{end}}`. Calling `.Prev` with the last page in the collection returns `nil`. ++`.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Prev . }}{{ .RelPermalink }}{{ end }}`. Calling `.Prev` with the last page in the collection returns `nil`. diff --cc docs/content/en/variables/shortcodes.md index a7c9e475b,000000000..3d4185b45 mode 100644,000000..100644 --- a/docs/content/en/variables/shortcodes.md +++ b/docs/content/en/variables/shortcodes.md @@@ -1,47 -1,0 +1,45 @@@ +--- +title: Shortcode Variables - linktitle: Shortcode Variables +description: Shortcodes can access page variables and also have their own specific built-in variables. - date: 2017-03-12 - publishdate: 2017-03-12 +categories: [variables and params] +keywords: [shortcodes] +menu: + docs: - parent: "variables" ++ parent: variables + weight: 20 +weight: 20 - sections_weight: 20 - aliases: [] - toc: false +--- + +[Shortcodes][shortcodes] have access to parameters delimited in the shortcode declaration via [`.Get`][getfunction], page- and site-level variables, and also the following shortcode-specific fields: + +.Name +: Shortcode name. + +.Ordinal +: Zero-based ordinal in relation to its parent. If the parent is the page itself, this ordinal will represent the position of this shortcode in the page content. + +.Page +: The owning ´Page`. + +.Parent +: provides access to the parent shortcode context in nested shortcodes. This can be very useful for inheritance of common shortcode parameters from the root. + +.Position +: Contains [filename and position](https://godoc.org/github.com/gohugoio/hugo/common/text#Position) for the shortcode in a page. Note that this can be relatively expensive to calculate, and is meant for error reporting. See [Error Handling in Shortcodes](/templates/shortcode-templates/#error-handling-in-shortcodes). + +.IsNamedParams +: boolean that returns `true` when the shortcode in question uses [named rather than positional parameters][shortcodes] + +.Inner +: represents the content between the opening and closing shortcode tags when a [closing shortcode][markdownshortcode] is used + - [getfunction]: /functions/get/ - [markdownshortcode]: /content-management/shortcodes/#shortcodes-with-markdown - [shortcodes]: /templates/shortcode-templates/ ++.Scratch ++: returns a writable [`Scratch`][scratch] to store and manipulate data which will be attached to the shortcode context. This scratch is reset on server rebuilds. + +.InnerDeindent {{< new-in "0.100.0" >}} +: Gets the `.Inner` with any indentation removed. This is what's used in the built-in `{{}}` shortcode. ++ ++[getfunction]: /functions/get/ ++[markdownshortcode]: /content-management/shortcodes/#shortcodes-with-markdown ++[shortcodes]: /templates/shortcode-templates/ ++[scratch]: /functions/scratch diff --cc docs/content/en/variables/site.md index 34239ad44,000000000..71111eb83 mode 100644,000000..100644 --- a/docs/content/en/variables/site.md +++ b/docs/content/en/variables/site.md @@@ -1,129 -1,0 +1,123 @@@ +--- +title: Site Variables - linktitle: Site Variables +description: Many, but not all, site-wide variables are defined in your site's configuration. However, Hugo provides a number of built-in variables for convenient access to global values in your templates. - date: 2017-02-01 - publishdate: 2017-02-01 - lastmod: 2017-02-01 +categories: [variables and params] +keywords: [global,site] - draft: false +menu: + docs: - parent: "variables" ++ parent: variables + weight: 10 +weight: 10 - sections_weight: 10 +aliases: [/variables/site-variables/] +toc: true +--- + +The following is a list of site-level (aka "global") variables. Many of these variables are defined in your site's [configuration file][config], whereas others are built into Hugo's core for convenient usage in your templates. + +## Get the Site object from a partial + +All the methods below, e.g. `.Site.RegularPages` can also be reached via the global [`site`](/functions/site/) function, e.g. `site.RegularPages`, which can be handy in partials where the `Page` object isn't easily available. + +## Site Variables List + +.Site.AllPages +: array of all pages, regardless of their translation. + +.Site.BaseURL +: the base URL for the site as defined in the site configuration. + +.Site.BuildDrafts +: a boolean (default: `false`) to indicate whether to build drafts as defined in the site configuration. + +.Site.Copyright +: a string representing the copyright of your website as defined in the site configuration. + +.Site.Data +: custom data, see [Data Templates](/templates/data-templates/). + +.Site.DisqusShortname +: a string representing the shortname of the Disqus shortcode as defined in the site configuration. + +.Site.GoogleAnalytics +: a string representing your tracking code for Google Analytics as defined in the site configuration. + +.Site.Home +: reference to the homepage's [page object](https://gohugo.io/variables/page/) + +.Site.IsMultiLingual +: whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information. + +.Site.IsServer +: a boolean to indicate if the site is being served with Hugo's built-in server. See [`hugo server`](/commands/hugo_server/) for more information. + +.Site.Language.Lang +: the language code of the current locale (e.g., `en`). + +.Site.Language.LanguageName +: the full language name (e.g. `English`). + +.Site.Language.Weight +: the weight that defines the order in the `.Site.Languages` list. + +.Site.Language +: indicates the language currently being used to render the website. This object's attributes are set in site configurations' language definition. + +.Site.LanguageCode +: a string representing the language tag as defined in the site configuration. + +.Site.LanguagePrefix +: this can be used to prefix URLs to point to the correct language. It will even work when only one defined language. See also the functions [absLangURL](/functions/abslangurl/) and [relLangURL](/functions/rellangurl). + +.Site.Languages +: an ordered list (ordered by defined weight) of languages. + +.Site.LastChange +: a string representing the date/time of the most recent change to your site. This string is based on the [`date` variable in the front matter](/content-management/front-matter) of your content pages. + +.Site.Menus +: all the menus in the site. + +.Site.Pages - : array of all content ordered by Date with the newest first. This array contains only the pages in the current language. See [`.Site.Pages`]({{< relref "site.md#site-pages" >}}). ++: array of all content ordered by Date with the newest first. This array contains only the pages in the current language. See [`.Site.Pages`](#site-pages). + +.Site.RegularPages - : a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`. See [`.Site.Pages`]({{< relref "site.md#site-pages" >}}). ++: a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`. See [`.Site.Pages`](#site-pages). + +.Site.Sections +: top-level directories of the site. + +.Site.Taxonomies - : the [taxonomies](/taxonomies/usage/) for the entire site. Also see section [Use `.Site.Taxonomies` Outside of Taxonomy Templates](/variables/taxonomy/#use-sitetaxonomies-outside-of-taxonomy-templates). ++: the [taxonomies](/content-management/taxonomies/) for the entire site. Also see section [Access taxonomy data from any template](/variables/taxonomy/#access-taxonomy-data-from-any-template). + +.Site.Title +: a string representing the title of the site. + +## The `.Site.Params` Variable + +`.Site.Params` is a container holding the values from the `params` section of your site configuration. + +### Example: `.Site.Params` + +The following `config.[yaml|toml|json]` defines a site-wide param for `description`: + +{{< code-toggle file="config" >}} +baseURL = "https://yoursite.example.com/" + +[params] + description = "Tesla's Awesome Hugo Site" + author = "Nikola Tesla" +{{}} + +You can use `.Site.Params` in a [partial template](/templates/partials/) to call the default site description: + +{{< code file="layouts/partials/head.html" >}} - ++ +{{< /code >}} + +## The `.Site.Pages` Variable {#site-pages} + +### `.Site.Pages` compared to `.Pages` + +{{< getcontent path="readfiles/pages-vs-site-pages.md" >}} + +[config]: /getting-started/configuration/ diff --cc docs/content/en/variables/sitemap.md index 24700182a,000000000..b0b080d00 mode 100644,000000..100644 --- a/docs/content/en/variables/sitemap.md +++ b/docs/content/en/variables/sitemap.md @@@ -1,31 -1,0 +1,25 @@@ +--- +title: Sitemap Variables +linktitle: Sitemap Variables +description: - date: 2017-03-12 - publishdate: 2017-03-12 +categories: [variables and params] +keywords: [sitemap] - draft: false +menu: + docs: - parent: "variables" ++ parent: variables + weight: 80 +weight: 80 - sections_weight: 80 - aliases: [] - toc: false +--- + +A sitemap is a `Page` and therefore has all the [page variables][pagevars] available to use sitemap templates. They also have the following sitemap-specific variables available to them: + +.Sitemap.ChangeFreq +: the page change frequency + +.Sitemap.Priority +: the priority of the page + +.Sitemap.Filename +: the sitemap filename + +[pagevars]: /variables/page/ diff --cc docs/content/en/variables/taxonomy.md index 901769b31,000000000..63b552328 mode 100644,000000..100644 --- a/docs/content/en/variables/taxonomy.md +++ b/docs/content/en/variables/taxonomy.md @@@ -1,140 -1,0 +1,138 @@@ +--- +title: Taxonomy Variables - linktitle: +description: Hugo's taxonomy system exposes variables to taxonomy and term templates. +categories: [variables and params] +keywords: [taxonomy,term] +menu: + docs: - parent: "variables" ++ parent: variables + weight: 30 +toc: true +weight: 30 - aliases: [] +--- + +## Taxonomy templates + +Pages rendered by taxonomy templates have `.Kind` set to `taxonomy` and `.Type` set to the taxonomy name. + +In taxonomy templates you may access `.Site`, `.Page`. `.Section`, and `.File` variables, as well as the following _taxonomy_ variables: + +.Data.Singular +: The singular name of the taxonomy (e.g., `tags => tag`). + +.Data.Plural +: The plural name of the taxonomy (e.g., `tags => tags`). + +.Data.Pages +: The collection of term pages related to this taxonomy. Aliased by `.Pages`. + +.Data.Terms +: A map of terms and weighted pages related to this taxonomy. + +.Data.Terms.Alphabetical +: A map of terms and weighted pages related to this taxonomy, sorted alphabetically in ascending order. Reverse the sort order with`.Data.Terms.Alphabetical.Reverse`. + +.Data.Terms.ByCount +: A map of terms and weighted pages related to this taxonomy, sorted by count in ascending order. Reverse the sort order with`.Data.Terms.ByCount.Reverse`. + +## Term templates + +Pages rendered by term templates have `.Kind` set to `term` and `.Type` set to the taxonomy name. + +In term templates you may access `.Site`, `.Page`. `.Section`, and `.File` variables, as well as the following _term_ variables: + +.Data.Singular +: The singular name of the taxonomy (e.g., `tags => tag`). + +.Data.Plural +: The plural name of the taxonomy (e.g., `tags => tags`). + +.Data.Pages +: The collection of content pages related to this taxonomy. Aliased by `.Pages`. + +.Data.Term +: The term itself (e.g., `tag-one`). + +## Access taxonomy data from any template + +Access the entire taxonomy data structure from any template with `site.Taxonomies`. This returns a map of taxonomies, terms, and a collection of weighted content pages related to each term. For example: + +```json +{ + "categories": { + "news": [ + { + "Weight": 0, + "Page": { + "Title": "Post 1", + "Date": "2022-12-18T15:13:35-08:00" + ... + } + }, + { + "Weight": 0, + "Page": { + "Title": "Post 2", + "Date": "2022-12-18T15:13:46-08:00", + ... + } + } + ] + }, + "tags": { + "international": [ + { + "Weight": 0, + "Page": { + "Title": "Post 1", + "Date": "2021-01-01T00:00:00Z" + ... + } + } + ] + } +} +``` + +Access a subset of the taxonomy data structure by chaining one or more identifiers, or by using the [`index`] function with one or more keys. For example, to access the collection of weighted content pages related to the news category, use either of the following: + +[`index`]: /functions/index-function/ + +```go-html-template +{{ $pages := site.Taxonomies.categories.news }} +{{ $pages := index site.Taxonomies "categories" "news" }} +``` + +For example, to render the entire taxonomy data structure as a nested unordered list: + +```go-html-template +
      + {{ range $taxonomy, $terms := site.Taxonomies }} +
    • + {{ with site.GetPage $taxonomy }} + {{ .LinkTitle }} + {{ end }} + +
    • + {{ end }} +
    +``` + +See [Taxonomy Templates] for more examples. + +[Taxonomy Templates]: /templates/taxonomy-templates/ diff --cc docs/go.mod index 33f818ad6,000000000..07badfeaf mode 100644,000000..100644 --- a/docs/go.mod +++ b/docs/go.mod @@@ -1,5 -1,0 +1,5 @@@ +module github.com/gohugoio/hugoDocs + +go 1.16 + - require github.com/gohugoio/gohugoioTheme v0.0.0-20230124135550-462d5fe4a87f // indirect ++require github.com/gohugoio/gohugoioTheme v0.0.0-20230418063032-99f9185b8e11 // indirect diff --cc docs/go.sum index ea0d2dcbe,000000000..6783cb92e mode 100644,000000..100644 --- a/docs/go.sum +++ b/docs/go.sum @@@ -1,61 -1,0 +1,65 @@@ +github.com/gohugoio/gohugoioTheme v0.0.0-20190808163145-07b3c0f73b02/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20191014144142-1f3a01deed7b h1:PWNjl46fvtz54PKO0BdiXOF6/4L/uCP0F3gtcCxGrJs= +github.com/gohugoio/gohugoioTheme v0.0.0-20191014144142-1f3a01deed7b/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20191021162625-2e7250ca437d h1:D3DcaYkuJbotdWNNAQpQl37txX4HQ6R5uMHoxVmTw0w= +github.com/gohugoio/gohugoioTheme v0.0.0-20191021162625-2e7250ca437d/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123151337-9475fd449324 h1:UZwHDYtGY0uOKIvcm2LWd+xfFxD3X5L222LIJdI5RE4= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123151337-9475fd449324/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123204146-589b4c309025 h1:ScYFARz+bHX1rEr1donVknhRdxGY/cwqK1hHvWEfrlc= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123204146-589b4c309025/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123205007-5d6620a0db26 h1:acXfduibbWxji9tW0WkLHbjcXFsnd5uIwXe0WfwOazg= +github.com/gohugoio/gohugoioTheme v0.0.0-20200123205007-5d6620a0db26/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200128164921-1d0bc5482051 h1:cS14MnUGS6xwWYfPNshimm8HdMCZiYBxWkCD0VnvgVw= +github.com/gohugoio/gohugoioTheme v0.0.0-20200128164921-1d0bc5482051/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200327225449-368f4cbef8d7 h1:cZ+ahAjSetbFv3aDJ9ipDbKyqaVlmkbSZ5cULgBTh+w= +github.com/gohugoio/gohugoioTheme v0.0.0-20200327225449-368f4cbef8d7/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200327231942-7f80b3d02bfa h1:kG+O/wT9UXomzp5eQiUuFVZ0l7YylAW6EVPLyjMxi/c= +github.com/gohugoio/gohugoioTheme v0.0.0-20200327231942-7f80b3d02bfa/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200328100657-2bfd5f8c6aee h1:PJZhCwnuVLyafDWNPSHk9iJvk6gEIvPRnycy7Pq3peA= +github.com/gohugoio/gohugoioTheme v0.0.0-20200328100657-2bfd5f8c6aee/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200518164958-62cbad03c40f h1:Ge3JACszSUyJW2Az9cJzWdo4PUqdijJA1RxoQSVMBSI= +github.com/gohugoio/gohugoioTheme v0.0.0-20200518164958-62cbad03c40f/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200518165806-0095b7b902a7 h1:Sy0hlWyZmFtdSY0Cobvw1ZYm3G1aR5+4DuFNRbMkh48= +github.com/gohugoio/gohugoioTheme v0.0.0-20200518165806-0095b7b902a7/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20200711112515-b0dfe471654f h1:BWJyycs4HD7tUbaU8RIGeMay84bIBWRVVLE3yajPas4= +github.com/gohugoio/gohugoioTheme v0.0.0-20200711112515-b0dfe471654f/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20210301124928-2c15837dfec3 h1:ShqzOFeeg54FPSuS6q8HSeTVgj2xNZRe/YS0jNbi21g= +github.com/gohugoio/gohugoioTheme v0.0.0-20210301124928-2c15837dfec3/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20210409065807-6383d8cbaf65 h1:EJzierSWKqwsrUXU6MaFe0J97c0e5pzl5dBNRRrV2Nc= +github.com/gohugoio/gohugoioTheme v0.0.0-20210409065807-6383d8cbaf65/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20210409071416-c88da48134b7 h1:uRCgPslaBgLYy4ANXBoPbBQVM8aNiHoxIZTKUXpkuUA= +github.com/gohugoio/gohugoioTheme v0.0.0-20210409071416-c88da48134b7/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20211211125852-b85e21c1f3d6 h1:lAgdWrn8VEg0PrNCPX4DflCg2msDKpSYV6E8RTNV3N0= +github.com/gohugoio/gohugoioTheme v0.0.0-20211211125852-b85e21c1f3d6/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20220228085601-7cfbda06d135 h1:6hVzfE9YhSsZP5t6jWjvVp7MoPm7Y5fEhH/ls4ahhKk= +github.com/gohugoio/gohugoioTheme v0.0.0-20220228085601-7cfbda06d135/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20220905093719-cb8b64046950 h1:Ovlh3nuy/aNptYZHmIra2MP+ZUEqiihY0HxvhdaMqGg= +github.com/gohugoio/gohugoioTheme v0.0.0-20220905093719-cb8b64046950/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20220912070954-88dcaf003b4d h1:UYJL6RmEepprvlgHvDnFCWtPOvjmqzFCQ90cRDRBO7U= +github.com/gohugoio/gohugoioTheme v0.0.0-20220912070954-88dcaf003b4d/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20220914071648-0ef1c51685bf h1:A8Ksnvp8reNt2Ap0mUK7gFkJkCjt9R60yopGsezcOBA= +github.com/gohugoio/gohugoioTheme v0.0.0-20220914071648-0ef1c51685bf/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221116211530-5ae8dcdd68d6 h1:eG53kL1LkQuKmrDdzbvvx6d60qM07zp2Wjo/tYxkDOY= +github.com/gohugoio/gohugoioTheme v0.0.0-20221116211530-5ae8dcdd68d6/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221118083537-967e29e21382 h1:e30rl1dxWkYOcgdl0omeOK0HBzgDLI/b9MfYHrINjzU= +github.com/gohugoio/gohugoioTheme v0.0.0-20221118083537-967e29e21382/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221124154621-1451a01f406b h1:TRrIisSY7ckt9FVHOOQtmKG4jsnORCYn72UMvMu+IQ0= +github.com/gohugoio/gohugoioTheme v0.0.0-20221124154621-1451a01f406b/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221206093948-1408550ab675 h1:wjpYa1cTELeceWndBDV7IG2vRxRWICBBO79HObOfTtk= +github.com/gohugoio/gohugoioTheme v0.0.0-20221206093948-1408550ab675/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221217122332-1c1752ad8f14 h1:K6tPFpi7W0zb89QIf+lNdgdTXfDFemU6NKk46MlX9lQ= +github.com/gohugoio/gohugoioTheme v0.0.0-20221217122332-1c1752ad8f14/go.mod h1:kpw3SS48xZvLQGEXKu8u5XHgXkPvL8DX3oGa07+z8Bs= +github.com/gohugoio/gohugoioTheme v0.0.0-20221220160735-8ffa1ef883b6 h1:yEoQecRBoLGfc7yTybMD3Mhm03bTScZFYPvwe0p75vA= +github.com/gohugoio/gohugoioTheme v0.0.0-20221220160735-8ffa1ef883b6/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= +github.com/gohugoio/gohugoioTheme v0.0.0-20230109120406-12694c4a9456 h1:RSLItaapVjWkqSdQhumAmJkodFDbWMGNZmkVW/AFx0c= +github.com/gohugoio/gohugoioTheme v0.0.0-20230109120406-12694c4a9456/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= +github.com/gohugoio/gohugoioTheme v0.0.0-20230119103504-3bcd960d6f1b h1:i/iaEOOuR1mKRR0qUOET587ooVhG8c2tllpA5HsrWNU= +github.com/gohugoio/gohugoioTheme v0.0.0-20230119103504-3bcd960d6f1b/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= +github.com/gohugoio/gohugoioTheme v0.0.0-20230120185049-2c3c4d0ba232 h1:bEojKgKInbsLkID5Arh95vP4+0xydtn/+ayT6I8vkiU= +github.com/gohugoio/gohugoioTheme v0.0.0-20230120185049-2c3c4d0ba232/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= +github.com/gohugoio/gohugoioTheme v0.0.0-20230124135550-462d5fe4a87f h1:8wI3zOTWQG15aKkbAZQaoGnUQff46hO95opQndBHRE4= +github.com/gohugoio/gohugoioTheme v0.0.0-20230124135550-462d5fe4a87f/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= ++github.com/gohugoio/gohugoioTheme v0.0.0-20230330081257-7a8c9614432c h1:TyHgmowfiMyxKrqTdRxm/yWIFeN7XRh7Hm6/dOG6yDA= ++github.com/gohugoio/gohugoioTheme v0.0.0-20230330081257-7a8c9614432c/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= ++github.com/gohugoio/gohugoioTheme v0.0.0-20230418063032-99f9185b8e11 h1:mDcricMewd66x8QjKqNun7Div7iYVLtl8s1dVs9VnB8= ++github.com/gohugoio/gohugoioTheme v0.0.0-20230418063032-99f9185b8e11/go.mod h1:GOYeAPQJ/ok8z7oz1cjfcSlsFpXrmx6VkzQ5RpnyhZM= diff --cc docs/hugo.toml index da6bd9534,000000000..5bed0ab2b mode 100644,000000..100644 --- a/docs/hugo.toml +++ b/docs/hugo.toml @@@ -1,87 -1,0 +1,97 @@@ +# This his the main configuration file. There are also environment specific configuration stored in the /config directory. + +baseURL = "https://gohugo.io/" +defaultContentLanguage = "en" +enableEmoji = true +googleAnalytics = "G-MBZGKNMDWC" +ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"] +languageCode = "en-us" +paginate = 100 +pluralizeListTitles = false +timeZone = "Europe/Oslo" +title = "Hugo" + +# We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below). +disableAliases = true + +[minify] + [minify.tdewolff] + [minify.tdewolff.html] + keepWhitespace = true + +[module] + [module.hugoVersion] + min = "0.56.0" + [[module.imports]] + path = "github.com/gohugoio/gohugoioTheme" + +[outputs] + home = ["HTML", "RSS", "REDIR", "HEADERS"] + section = ["HTML", "RSS"] + +[mediaTypes] + [mediaTypes."text/netlify"] + delimiter = "" + +[outputFormats] + [outputFormats.REDIR] + mediatype = "text/netlify" + baseName = "_redirects" + isPlainText = true + notAlternative = true + [outputFormats.HEADERS] + mediatype = "text/netlify" + baseName = "_headers" + isPlainText = true + notAlternative = true + +[caches] + [caches.getjson] + dir = ":cacheDir/:project" + maxAge = -1 + [caches.getcsv] + dir = ":cacheDir/:project" + maxAge = -1 + [caches.images] + dir = ":cacheDir/images" + maxAge = "1440h" + [caches.assets] + dir = ":resourceDir/_gen" + maxAge = -1 + +[related] + threshold = 80 + includeNewer = true + toLower = false + [[related.indices]] + name = "keywords" - weight = 100 ++ weight = 60 ++ [[related.indices]] ++ # Can be used as a front matter slice to link to other page fragments (headings) using their ID. ++ # This isn't particular useful in the current docs, but we're planning on getting a auto generated ++ # reference section with a better ID setup. ++ # For now, we just use it to give pages with same headings some similarity score. ++ name = "fragmentrefs" ++ type = "fragments" ++ applyFilter = false ++ weight = 60 ++ cardinalityThreshold = 50 + [[related.indices]] + name = "date" + weight = 10 + pattern = "2006" + +[social] + twitter = "GoHugoIO" + +[imaging] + # See https://github.com/disintegration/imaging + # CatmullRom is a sharp bicubic filter which should fit the docs site well with its many screenshots. + # Note that you can also set this per image processing. + resampleFilter = "CatmullRom" + # Default JPEG quality setting. Default is 75. + quality = 75 + anchor = "smart" + +[taxonomies] + category = "categories" diff --cc docs/layouts/shortcodes/code-toggle.html index 113d85a1f,000000000..b4cfaaa20 mode 100644,000000..100644 --- a/docs/layouts/shortcodes/code-toggle.html +++ b/docs/layouts/shortcodes/code-toggle.html @@@ -1,108 -1,0 +1,87 @@@ +{{- /* +Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats. + - @param {string} config - Section of site.Data.docs.config to render. - Example: markup.highlight - Default: "" - @param {bool} copy - Display a copy button. - Default: true - @param {string} file - File name to display above the rendered code. - Default: "" - @param {bool} fm - Does Inner represent front matter? - Default: false - @param {string} Inner - Content between opening and closing shortcode tags. - Default: "" - @param {bool} skipHeader - Omit top level key(s) when rendering a section of site.Data.docs.config. - Default: false ++@param {string} [config] The section of site.Data.docs.config to render. ++@param {bool} [copy=true] If true, display a copy to clipboard button. ++@param {string} [file] The file name to display above the rendered code. ++@param {bool} [fm=false] If true, render the code as front matter. ++@param {bool} [skipHeader=false] If false, omit top level key(s) when rendering a section of site.Data.docs.config. ++ +@returns {template.HTML} - */ -}} ++*/}} + - {{- /* Initialize. */ -}} - {{- $config := "" -}} - {{- $copy := true -}} - {{- $file := "" -}} - {{- $fm := false -}} - {{- $skipHeader := false -}} ++{{- /* Initialize. */}} ++{{- $config := "" }} ++{{- $copy := true }} ++{{- $file := "" }} ++{{- $fm := false }} ++{{- $skipHeader := false }} + - {{- /* Get parameters, defend against string booleans. */ -}} - {{- if .Params -}} - {{- $config = .Get "config" -}} - {{- $file = .Get "file" -}} - {{- if (isset .Params "copy") -}} - {{- if in (slice true "true") (.Get "copy") -}} - {{- $copy = true -}} - {{- else -}} - {{- $copy = false -}} - {{- end -}} - {{- end -}} - {{- if (isset .Params "fm") -}} - {{- if in (slice true "true") (.Get "fm") -}} - {{- $fm = true -}} - {{- else -}} - {{- $fm = false -}} - {{- end -}} - {{- end -}} - {{- if (isset .Params "skipHeader") -}} - {{- if in (slice true "true") (.Get "skipHeader") -}} - {{- $skipHeader = true -}} - {{- else -}} - {{- $skipHeader = false -}} - {{- end -}} - {{- end -}} - {{- end -}} ++{{- /* Get parameters. */}} ++{{- $config = .Get "config" }} ++{{- $file = .Get "file" }} ++{{- if in (slice "false" false 0) (.Get "copy") }} ++ {{- $copy = false }} ++{{- else if in (slice "true" true 1) (.Get "copy")}} ++ {{- $copy = true }} ++{{- end }} ++{{- if in (slice "false" false 0) (.Get "fm") }} ++ {{- $fm = false }} ++{{- else if in (slice "true" true 1) (.Get "fm")}} ++ {{- $fm = true }} ++{{- end }} ++{{- if in (slice "false" false 0) (.Get "skipHeader") }} ++ {{- $skipHeader = false }} ++{{- else if in (slice "true" true 1) (.Get "skipHeader")}} ++ {{- $skipHeader = true }} ++{{- end }} + - {{- /* Define constants. */ -}} - {{- $delimiters := dict "toml" "+++" "yaml" "---" -}} - {{- $langs := slice "yaml" "toml" "json" -}} - {{- $placeHolder := "#-hugo-placeholder-#" -}} ++{{- /* Define constants. */}} ++{{- $delimiters := dict "toml" "+++" "yaml" "---" }} ++{{- $langs := slice "yaml" "toml" "json" }} ++{{- $placeHolder := "#-hugo-placeholder-#" }} + - {{- /* Render. */ -}} - {{- $code := "" -}} - {{- with $config -}} - {{- $file = $file | default "config" -}} - {{- $sections := (split . ".") -}} - {{- $configSection := index $.Site.Data.docs.config $sections -}} - {{- $code = dict $sections $configSection -}} - {{- if $skipHeader -}} - {{- $code = $configSection -}} - {{- end -}} - {{- else -}} - {{- $code = $.Inner -}} ++{{- /* Render. */}} ++{{- $code := "" }} ++{{- with $config }} ++ {{- $file = $file | default "config" }} ++ {{- $sections := (split . ".") }} ++ {{- $configSection := index $.Site.Data.docs.config $sections }} ++ {{- $code = dict $sections $configSection }} ++ {{- if $skipHeader }} ++ {{- $code = $configSection }} ++ {{- end }} ++{{- else }} ++ {{- $code = $.Inner }} +{{- end }} +
    +
    + {{- with $file }} +
    - {{- . -}}{{- if not $fm -}}.{{- end -}} ++ {{ . }}{{ if not $fm }}.{{ end }} +
    - {{- end -}} ++ {{- end }} + {{- range $langs }} + +   + {{- end }} +
    +
    + {{- range $langs }} +
    - {{- $hCode := $code | transform.Remarshal . -}} - {{- if and $fm (in (slice "toml" "yaml") .) -}} - {{- $hCode = printf "%s\n%s\n%s" $placeHolder $hCode $placeHolder -}} - {{- end -}} ++ {{- $hCode := $code | transform.Remarshal . }} ++ {{- if and $fm (in (slice "toml" "yaml") .) }} ++ {{- $hCode = printf "%s\n%s\n%s" $placeHolder $hCode $placeHolder }} ++ {{- end }} + {{- $hCode = $hCode | replaceRE `\n+` "\n" }} + {{ highlight $hCode . "" | replaceRE $placeHolder (index $delimiters .) | safeHTML }} +
    + {{- if $copy }} + - {{- /* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */ -}} - {{- end -}} ++ {{- /* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}} ++ {{- end }} + {{- end }} +
    +
    diff --cc docs/layouts/shortcodes/code.html index 0ee25149d,000000000..31ca27596 mode 100644,000000..100644 --- a/docs/layouts/shortcodes/code.html +++ b/docs/layouts/shortcodes/code.html @@@ -1,26 -1,0 +1,39 @@@ - {{ $file := .Get "file" }} - {{ $codeLang := "" }} - {{ $suffix := findRE "(\\.[^.]+)$" $file 1 }} - {{ with $suffix }} - {{ $codeLang = (index . 0 | strings.TrimPrefix ".") }} - {{ end }} - {{ with .Get "codeLang" }}{{ $codeLang = . }}{{ end }} - {{ if eq $codeLang "html" }} - {{ $codeLang = "go-html-template" }} - {{ end }} -
    - {{- with $file -}} -
    {{ . }}
    - {{- end -}} ++{{- /* ++Renders syntax highlighted code. ++ ++@param {bool} [copy=true] If true, display a copy to clipboard button. ++@param {string} [file] The file name to display above the rendered code. ++@param {string} [lang] The code language of the inner content. ++ ++@returns {template.HTML} ++*/}} + - {{ if ne (.Get "copy") "false" }} - - {{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}} - {{ end }} -
    - {{ $inner := trim .Inner "\n" | safeHTML }} - {{ if .Get "nocode" }}{{ $inner }}{{ else }}{{ with $codeLang }}{{ highlight $inner . "" }}{{ else }}
    {{ $inner }}
    {{ end }}{{ end }} -
    ++{{- /* Initialize. */}} ++{{- $copy := true }} ++{{- $file := " " }} ++{{- $lang := "" }} + ++{{- /* Get parameters. */}} ++{{- $file = .Get "file" }} ++{{- $lang = or (.Get "lang") (path.Ext $file | strings.TrimPrefix ".") "text" }} ++{{- if in (slice "false" false 0) (.Get "copy") }} ++ {{- $copy = false }} ++{{- else if in (slice "true" true 1) (.Get "copy")}} ++ {{- $copy = true }} ++{{- end }} ++ ++{{- /* Use the go-html-template Chroma lexer for HTML. */}} ++{{- if eq $lang "html" }} ++ {{- $lang = "go-html-template" }} ++{{- end }} ++ ++{{- /* Render. */}} ++
    ++
    {{ or $file "nbsp;" }}
    ++ {{- if $copy }} ++ ++ {{- end }} ++
    ++ {{- highlight (trim .Inner "\n\r") $lang }} ++
    +
    diff --cc docs/netlify.toml index d99f6d223,000000000..a07e29a94 mode 100644,000000..100644 --- a/docs/netlify.toml +++ b/docs/netlify.toml @@@ -1,35 -1,0 +1,35 @@@ +[build] +publish = "public" +command = "hugo --gc --minify" + +[context.production.environment] - HUGO_VERSION = "0.110.0" ++HUGO_VERSION = "0.111.3" +HUGO_ENV = "production" +HUGO_ENABLEGITINFO = "true" + +[context.split1] +command = "hugo --gc --minify --enableGitInfo" + +[context.split1.environment] - HUGO_VERSION = "0.110.0" ++HUGO_VERSION = "0.111.3" +HUGO_ENV = "production" + +[context.deploy-preview] +command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL" + +[context.deploy-preview.environment] - HUGO_VERSION = "0.110.0" ++HUGO_VERSION = "0.111.3" + +[context.branch-deploy] +command = "hugo --gc --minify -b $DEPLOY_PRIME_URL" + +[context.branch-deploy.environment] - HUGO_VERSION = "0.110.0" ++HUGO_VERSION = "0.111.3" + +[context.next.environment] +HUGO_ENABLEGITINFO = "true" + +[[redirects]] +from = "/npmjs/*" +to = "/npmjs/" +status = 200