mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Squashed 'docs/' changes from 7ef2dbce4..cb18a5183
cb18a5183 Fix broken link 07a0198bf Config: Place Google Analytics tag ID under the services key 4bf0c719f Fix typo 50d8ad1af Fix muiltilingual menu definition instructions 1a32519a9 Fix typos 6f34ca8e0 Explain usage of front matter to target a template 5bd977257 Improve goldmark config docs 447632938 Remove Docker notes from installation instructions 84741d173 Update reference to hugo.work 0338d7c71 Fix menu template f5d2f5ed4 Fix typos in content/en/functions/fmt a3a40ff99 Add return type to functions 85ac3e779 Remove outdated feature image d47d889e4 Fix signatures 7551ba28f Document safe.JSStr function e77993be0 Document keyVals function 4dba20db3 Update theme babf91544 Update echoparam 8c8203efa Adjust related functions 4cb1b30fc Fix example ba95eca64 Improve showcase prose 5d3dcf366 Add Overmind Studios showcase 8d634ac70 Change code blocks from indented to fenced cfab978e6 Add missing code fences 407dd5c47 Limit related pages for functions to other functions 9fa67d981 Fix .Site.LastChange doc 393aa16d0 netlify: Hugo 0.119.0 f864af97a docs: Even more about images.Process 9d772d5f0 docs: More about images.Process bc655f869 docs: Regen docshelper 41c3536d1 Merge commit '9aec42c5452b3eb224888c50ba1c3f3b68a447e9' 918ed53f4 Add images.Process filter 573645883 Add $image.Process a1151b0fd Add images.Opacity filter git-subtree-dir: docs git-subtree-split: cb18a5183fc62f301ffde50b8c39f03e4b897aec
This commit is contained in:
parent
9aec42c545
commit
e509cac533
299 changed files with 4672 additions and 2003 deletions
|
@ -1,5 +1,8 @@
|
||||||
.facebook, .twitter, .instagram, .youtube {
|
.facebook,
|
||||||
fill: #BABABA;
|
.twitter,
|
||||||
|
.instagram,
|
||||||
|
.youtube {
|
||||||
|
fill: #bababa;
|
||||||
}
|
}
|
||||||
.facebook:hover {
|
.facebook:hover {
|
||||||
fill: #3b5998;
|
fill: #3b5998;
|
||||||
|
@ -10,10 +13,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.twitter:hover {
|
.twitter:hover {
|
||||||
fill: #BABABA;
|
fill: #bababa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.instagram:hover {
|
.instagram:hover {
|
||||||
fill: #e95950;
|
fill: #e95950;
|
||||||
}
|
}
|
||||||
|
@ -21,3 +23,30 @@
|
||||||
.youtube:hover {
|
.youtube:hover {
|
||||||
fill: #bb0000;
|
fill: #bb0000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mstdn {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #282c37;
|
||||||
|
color: #d9e1e8;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 4px 10px 4px 30px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2261.076954mm%22%20height%3D%2265.47831mm%22%20viewBox%3D%220%200%20216.4144%20232.00976%22%3E%3Cpath%20d%3D%22M211.80734%20139.0875c-3.18125%2016.36625-28.4925%2034.2775-57.5625%2037.74875-15.15875%201.80875-30.08375%203.47125-45.99875%202.74125-26.0275-1.1925-46.565-6.2125-46.565-6.2125%200%202.53375.15625%204.94625.46875%207.2025%203.38375%2025.68625%2025.47%2027.225%2046.39125%2027.9425%2021.11625.7225%2039.91875-5.20625%2039.91875-5.20625l.8675%2019.09s-14.77%207.93125-41.08125%209.39c-14.50875.7975-32.52375-.365-53.50625-5.91875C9.23234%20213.82%201.40609%20165.31125.20859%20116.09125c-.365-14.61375-.14-28.39375-.14-39.91875%200-50.33%2032.97625-65.0825%2032.97625-65.0825C49.67234%203.45375%2078.20359.2425%20107.86484%200h.72875c29.66125.2425%2058.21125%203.45375%2074.8375%2011.09%200%200%2032.975%2014.7525%2032.975%2065.0825%200%200%20.41375%2037.13375-4.59875%2062.915%22%20fill%3D%22%233088d4%22%2F%3E%3Cpath%20d%3D%22M177.50984%2080.077v60.94125h-24.14375v-59.15c0-12.46875-5.24625-18.7975-15.74-18.7975-11.6025%200-17.4175%207.5075-17.4175%2022.3525v32.37625H96.20734V85.42325c0-14.845-5.81625-22.3525-17.41875-22.3525-10.49375%200-15.74%206.32875-15.74%2018.7975v59.15H38.90484V80.077c0-12.455%203.17125-22.3525%209.54125-29.675%206.56875-7.3225%2015.17125-11.07625%2025.85-11.07625%2012.355%200%2021.71125%204.74875%2027.8975%2014.2475l6.01375%2010.08125%206.015-10.08125c6.185-9.49875%2015.54125-14.2475%2027.8975-14.2475%2010.6775%200%2019.28%203.75375%2025.85%2011.07625%206.36875%207.3225%209.54%2017.22%209.54%2029.675%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E");
|
||||||
|
background-size: 16px;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: top 50% left 8px;
|
||||||
|
transition: all 0.5s;
|
||||||
|
}
|
||||||
|
.mstdn:hover {
|
||||||
|
background-color: #484c56;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mstdn > span {
|
||||||
|
color: #9baec8;
|
||||||
|
font-size: 12px;
|
||||||
|
padding-left: 3px;
|
||||||
|
}
|
||||||
|
.mstdn > span:before {
|
||||||
|
content: "@";
|
||||||
|
}
|
||||||
|
|
|
@ -804,8 +804,6 @@ img { max-width: 100%; }
|
||||||
.b--washed-red { border-color: #ffdfdf; }
|
.b--washed-red { border-color: #ffdfdf; }
|
||||||
.b--transparent { border-color: transparent; }
|
.b--transparent { border-color: transparent; }
|
||||||
.b--inherit { border-color: inherit; }
|
.b--inherit { border-color: inherit; }
|
||||||
.b--initial { border-color: currentColor; border-color: initial; }
|
|
||||||
.b--unset { border-color: unset; }
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
BORDER RADIUS
|
BORDER RADIUS
|
||||||
|
@ -854,9 +852,6 @@ img { max-width: 100%; }
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
}
|
}
|
||||||
.br-inherit { border-radius: inherit; }
|
|
||||||
.br-initial { border-radius: 0; border-radius: initial; }
|
|
||||||
.br-unset { border-radius: unset; }
|
|
||||||
@media screen and (min-width: 30em) {
|
@media screen and (min-width: 30em) {
|
||||||
.br0-ns { border-radius: 0; }
|
.br0-ns { border-radius: 0; }
|
||||||
.br1-ns { border-radius: .125rem; }
|
.br1-ns { border-radius: .125rem; }
|
||||||
|
@ -881,9 +876,6 @@ img { max-width: 100%; }
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
}
|
}
|
||||||
.br-inherit-ns { border-radius: inherit; }
|
|
||||||
.br-initial-ns { border-radius: 0; border-radius: initial; }
|
|
||||||
.br-unset-ns { border-radius: unset; }
|
|
||||||
}
|
}
|
||||||
@media screen and (min-width: 30em) and (max-width: 60em) {
|
@media screen and (min-width: 30em) and (max-width: 60em) {
|
||||||
.br0-m { border-radius: 0; }
|
.br0-m { border-radius: 0; }
|
||||||
|
@ -909,9 +901,6 @@ img { max-width: 100%; }
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
}
|
}
|
||||||
.br-inherit-m { border-radius: inherit; }
|
|
||||||
.br-initial-m { border-radius: 0; border-radius: initial; }
|
|
||||||
.br-unset-m { border-radius: unset; }
|
|
||||||
}
|
}
|
||||||
@media screen and (min-width: 60em) {
|
@media screen and (min-width: 60em) {
|
||||||
.br0-l { border-radius: 0; }
|
.br0-l { border-radius: 0; }
|
||||||
|
@ -937,9 +926,6 @@ img { max-width: 100%; }
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
}
|
}
|
||||||
.br-inherit-l { border-radius: inherit; }
|
|
||||||
.br-initial-l { border-radius: 0; border-radius: initial; }
|
|
||||||
.br-unset-l { border-radius: unset; }
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -2381,7 +2367,6 @@ img { max-width: 100%; }
|
||||||
.washed-yellow { color: #fffceb; }
|
.washed-yellow { color: #fffceb; }
|
||||||
.washed-red { color: #ffdfdf; }
|
.washed-red { color: #ffdfdf; }
|
||||||
.color-inherit { color: inherit; }
|
.color-inherit { color: inherit; }
|
||||||
/* Background colors */
|
|
||||||
.bg-black-90 { background-color: rgba(0, 0, 0, .9); }
|
.bg-black-90 { background-color: rgba(0, 0, 0, .9); }
|
||||||
.bg-black-80 { background-color: rgba(0, 0, 0, .8); }
|
.bg-black-80 { background-color: rgba(0, 0, 0, .8); }
|
||||||
.bg-black-70 { background-color: rgba(0, 0, 0, .7); }
|
.bg-black-70 { background-color: rgba(0, 0, 0, .7); }
|
||||||
|
@ -2401,6 +2386,7 @@ img { max-width: 100%; }
|
||||||
.bg-white-30 { background-color: rgba(255, 255, 255, .3); }
|
.bg-white-30 { background-color: rgba(255, 255, 255, .3); }
|
||||||
.bg-white-20 { background-color: rgba(255, 255, 255, .2); }
|
.bg-white-20 { background-color: rgba(255, 255, 255, .2); }
|
||||||
.bg-white-10 { background-color: rgba(255, 255, 255, .1); }
|
.bg-white-10 { background-color: rgba(255, 255, 255, .1); }
|
||||||
|
/* Background colors */
|
||||||
.bg-black { background-color: #000; }
|
.bg-black { background-color: #000; }
|
||||||
.bg-near-black { background-color: #111; }
|
.bg-near-black { background-color: #111; }
|
||||||
.bg-dark-gray { background-color: #333; }
|
.bg-dark-gray { background-color: #333; }
|
||||||
|
@ -4685,7 +4671,6 @@ h6:hover .header-link {
|
||||||
.searchbox__input::-webkit-input-placeholder{color:#aaa}
|
.searchbox__input::-webkit-input-placeholder{color:#aaa}
|
||||||
.searchbox__input:-ms-input-placeholder{color:#aaa}
|
.searchbox__input:-ms-input-placeholder{color:#aaa}
|
||||||
.searchbox__input::-ms-input-placeholder{color:#aaa}
|
.searchbox__input::-ms-input-placeholder{color:#aaa}
|
||||||
.searchbox__input::-moz-placeholder{color:#aaa}
|
|
||||||
.searchbox__input::placeholder{color:#aaa}
|
.searchbox__input::placeholder{color:#aaa}
|
||||||
.searchbox__submit{position:absolute;top:0;margin:0;border:0;border-radius:16px 0 0 16px;background-color:rgba(69, 142, 225, 0);padding:0;width:32px;height:100%;vertical-align:middle;text-align:center;font-size:inherit;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;right:inherit;left:0}
|
.searchbox__submit{position:absolute;top:0;margin:0;border:0;border-radius:16px 0 0 16px;background-color:rgba(69, 142, 225, 0);padding:0;width:32px;height:100%;vertical-align:middle;text-align:center;font-size:inherit;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;right:inherit;left:0}
|
||||||
.searchbox__submit:before{display:inline-block;margin-right:-4px;height:100%;vertical-align:middle;content:""}
|
.searchbox__submit:before{display:inline-block;margin-right:-4px;height:100%;vertical-align:middle;content:""}
|
||||||
|
@ -4919,14 +4904,14 @@ pre {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
}
|
}
|
||||||
.column-count-2 {-webkit-column-count: 1;-moz-column-count: 1;column-count: 1}
|
.column-count-2 {-webkit-column-count: 1;column-count: 1}
|
||||||
.column-gap-1 {-webkit-column-gap: 0;-moz-column-gap: 0;column-gap: 0}
|
.column-gap-1 {-webkit-column-gap: 0;column-gap: 0}
|
||||||
.break-inside-avoid {-webkit-column-break-inside: auto;page-break-inside: auto;break-inside: auto}
|
.break-inside-avoid {-webkit-column-break-inside: auto;break-inside: auto}
|
||||||
@media screen and (min-width: 60em) {
|
@media screen and (min-width: 60em) {
|
||||||
.column-count-3-l {-webkit-column-count: 3;-moz-column-count: 3;column-count: 3}
|
.column-count-3-l {-webkit-column-count: 3;column-count: 3}
|
||||||
.column-count-2-l {-webkit-column-count: 2;-moz-column-count: 2;column-count: 2}
|
.column-count-2-l {-webkit-column-count: 2;column-count: 2}
|
||||||
.column-gap-1-l {-webkit-column-gap: 1;-moz-column-gap: 1;column-gap: 1}
|
.column-gap-1-l {-webkit-column-gap: 1;column-gap: 1}
|
||||||
.break-inside-avoid-l {-webkit-column-break-inside: avoid;page-break-inside: avoid;break-inside: avoid}
|
.break-inside-avoid-l {-webkit-column-break-inside: avoid;break-inside: avoid}
|
||||||
}
|
}
|
||||||
.prose ul, .prose ol {
|
.prose ul, .prose ol {
|
||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
|
@ -4937,10 +4922,6 @@ pre {
|
||||||
.prose li:hover {
|
.prose li:hover {
|
||||||
background-color: #eee
|
background-color: #eee
|
||||||
}
|
}
|
||||||
.prose ::-moz-selection {
|
|
||||||
background: #0594CB; /* WebKit/Blink Browsers */
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
.prose ::selection {
|
.prose ::selection {
|
||||||
background: #0594CB; /* WebKit/Blink Browsers */
|
background: #0594CB; /* WebKit/Blink Browsers */
|
||||||
color: white;
|
color: white;
|
||||||
|
@ -5132,8 +5113,11 @@ code, .code, pre code, .highlight pre {
|
||||||
-webkit-transition: opacity .15s ease-in;
|
-webkit-transition: opacity .15s ease-in;
|
||||||
transition: opacity .15s ease-in;
|
transition: opacity .15s ease-in;
|
||||||
}
|
}
|
||||||
.facebook, .twitter, .instagram, .youtube {
|
.facebook,
|
||||||
fill: #BABABA;
|
.twitter,
|
||||||
|
.instagram,
|
||||||
|
.youtube {
|
||||||
|
fill: #bababa;
|
||||||
}
|
}
|
||||||
.facebook:hover {
|
.facebook:hover {
|
||||||
fill: #3b5998;
|
fill: #3b5998;
|
||||||
|
@ -5142,7 +5126,7 @@ code, .code, pre code, .highlight pre {
|
||||||
fill: #55acee;
|
fill: #55acee;
|
||||||
}
|
}
|
||||||
.twitter:hover {
|
.twitter:hover {
|
||||||
fill: #BABABA;
|
fill: #bababa;
|
||||||
}
|
}
|
||||||
.instagram:hover {
|
.instagram:hover {
|
||||||
fill: #e95950;
|
fill: #e95950;
|
||||||
|
@ -5150,6 +5134,32 @@ code, .code, pre code, .highlight pre {
|
||||||
.youtube:hover {
|
.youtube:hover {
|
||||||
fill: #bb0000;
|
fill: #bb0000;
|
||||||
}
|
}
|
||||||
|
.mstdn {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #282c37;
|
||||||
|
color: #d9e1e8;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 4px 10px 4px 30px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 16px;
|
||||||
|
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2261.076954mm%22%20height%3D%2265.47831mm%22%20viewBox%3D%220%200%20216.4144%20232.00976%22%3E%3Cpath%20d%3D%22M211.80734%20139.0875c-3.18125%2016.36625-28.4925%2034.2775-57.5625%2037.74875-15.15875%201.80875-30.08375%203.47125-45.99875%202.74125-26.0275-1.1925-46.565-6.2125-46.565-6.2125%200%202.53375.15625%204.94625.46875%207.2025%203.38375%2025.68625%2025.47%2027.225%2046.39125%2027.9425%2021.11625.7225%2039.91875-5.20625%2039.91875-5.20625l.8675%2019.09s-14.77%207.93125-41.08125%209.39c-14.50875.7975-32.52375-.365-53.50625-5.91875C9.23234%20213.82%201.40609%20165.31125.20859%20116.09125c-.365-14.61375-.14-28.39375-.14-39.91875%200-50.33%2032.97625-65.0825%2032.97625-65.0825C49.67234%203.45375%2078.20359.2425%20107.86484%200h.72875c29.66125.2425%2058.21125%203.45375%2074.8375%2011.09%200%200%2032.975%2014.7525%2032.975%2065.0825%200%200%20.41375%2037.13375-4.59875%2062.915%22%20fill%3D%22%233088d4%22%2F%3E%3Cpath%20d%3D%22M177.50984%2080.077v60.94125h-24.14375v-59.15c0-12.46875-5.24625-18.7975-15.74-18.7975-11.6025%200-17.4175%207.5075-17.4175%2022.3525v32.37625H96.20734V85.42325c0-14.845-5.81625-22.3525-17.41875-22.3525-10.49375%200-15.74%206.32875-15.74%2018.7975v59.15H38.90484V80.077c0-12.455%203.17125-22.3525%209.54125-29.675%206.56875-7.3225%2015.17125-11.07625%2025.85-11.07625%2012.355%200%2021.71125%204.74875%2027.8975%2014.2475l6.01375%2010.08125%206.015-10.08125c6.185-9.49875%2015.54125-14.2475%2027.8975-14.2475%2010.6775%200%2019.28%203.75375%2025.85%2011.07625%206.36875%207.3225%209.54%2017.22%209.54%2029.675%22%20fill%3D%22%23fff%22%2F%3E%3C%2Fsvg%3E");
|
||||||
|
background-size: 16px;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: top 50% left 8px;
|
||||||
|
-webkit-transition: all 0.5s;
|
||||||
|
transition: all 0.5s;
|
||||||
|
}
|
||||||
|
.mstdn:hover {
|
||||||
|
background-color: #484c56;
|
||||||
|
}
|
||||||
|
.mstdn > span {
|
||||||
|
color: #9baec8;
|
||||||
|
font-size: 12px;
|
||||||
|
padding-left: 3px;
|
||||||
|
}
|
||||||
|
.mstdn > span:before {
|
||||||
|
content: "@";
|
||||||
|
}
|
||||||
@media (min-width: 75em) {
|
@media (min-width: 75em) {
|
||||||
|
|
||||||
[data-scrolldir="down"] .sticky {
|
[data-scrolldir="down"] .sticky {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -30,9 +30,9 @@
|
||||||
{{- partial "site-search.html" . -}}
|
{{- partial "site-search.html" . -}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="absolute mt1 mt2-l pr3 right-0 top-0">
|
<div class="absolute mt1 mt2-l pr3 right-0 top-0 flex items-start">
|
||||||
{{- partialCached "social-follow.html" . -}}
|
{{- partialCached "social-follow.html" . -}}
|
||||||
</span>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<!-- TODO: Add follow intents where available TODO: Revisit color and hover color -->
|
{{/*
|
||||||
{{ with .Site.Social.twitter }}
|
Disable Twitter for now as we lost access to the account.
|
||||||
|
with .Site.Social.twitter }}
|
||||||
<a href="https://twitter.com/intent/follow?screen_name={{ . }}" title="Follow on Twitter" class="link-transition twitter link dib z-999 pt3 pt0-l mr2">
|
<a href="https://twitter.com/intent/follow?screen_name={{ . }}" title="Follow on Twitter" class="link-transition twitter link dib z-999 pt3 pt0-l mr2">
|
||||||
{{ partial "svg/twitter.svg" (dict "size" "32px") }}
|
{{ partial "svg/twitter.svg" (dict "size" "32px") }}
|
||||||
</a>
|
</a>
|
||||||
{{ end }}
|
{{ end */}}
|
||||||
<a class="github-button needs-js link primary-color-dark" href="https://github.com/gohugoio/hugo" data-size="large" data-show-count="false" aria-label="Star gohugoio/hugo on GitHub">Star</a>
|
<a rel="me" class="mstdn mr3" href="https://fosstodon.org/@gohugoio" target="_blank">gohugoio</a>
|
||||||
|
<a class="github-button needs-js link primary-color-dark" href="https://github.com/gohugoio/hugo" data-size="large" data-show-count="false" aria-label="Star gohugoio/hugo on GitHub">Star</a>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
# github.com/gohugoio/gohugoioTheme v0.0.0-20230812102551-06f8256e7ee5
|
# github.com/gohugoio/gohugoioTheme v0.0.0-20230927165800-342e2c850f18
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
---
|
---
|
||||||
title: {{ replace .Name "-" " " | title }}
|
title: {{ replace .File.ContentBaseName "-" " " | title }}
|
||||||
description: ""
|
description:
|
||||||
signature: []
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
keywords: []
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
relatedfuncs: []
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType:
|
||||||
|
signatures: []
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
---
|
---
|
||||||
title: "{{ replace .Name "-" " " | title }}"
|
title: {{ replace .File.ContentBaseName "-" " " | title }}
|
||||||
description: ""
|
description:
|
||||||
date: {{ .Date }}
|
date: {{ .Date }}
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
title: {{ replace .Name "-" " " | title }}
|
title: {{ replace .File.ContentBaseName "-" " " | title }}
|
||||||
date: {{ now.Format "2006-01-02" }}
|
date: {{ now.Format "2006-01-02" }}
|
||||||
|
|
||||||
description: "A short description of this page."
|
description: A short description of this page.
|
||||||
|
|
||||||
# The URL to the site on the internet.
|
# The URL to the site on the internet.
|
||||||
siteURL: https://gohugo.io/
|
siteURL: https://gohugo.io/
|
||||||
|
@ -34,4 +34,3 @@ bio.md
|
||||||
|
|
||||||
featured.png
|
featured.png
|
||||||
: A reasonably sized screenshot of your website. It can be named anything, but the name must start with "featured". The sample image is `1500x750` (2:1 aspect ratio).
|
: A reasonably sized screenshot of your website. It can be named anything, but the name must start with "featured". The sample image is `1500x750` (2:1 aspect ratio).
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 83 KiB |
|
@ -36,13 +36,13 @@ Hugo is for people building a blog, a company site, a portfolio site, documentat
|
||||||
[@spf13]: https://twitter.com/spf13
|
[@spf13]: https://twitter.com/spf13
|
||||||
[Amazon S3]: https://aws.amazon.com/s3/
|
[Amazon S3]: https://aws.amazon.com/s3/
|
||||||
[Azure]: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website
|
[Azure]: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website
|
||||||
[CloudFront]: https://aws.amazon.com/cloudfront/ "Amazon CloudFront"
|
[CloudFront]: https://aws.amazon.com/cloudfront/
|
||||||
[DreamHost]: https://www.dreamhost.com/
|
[DreamHost]: https://www.dreamhost.com/
|
||||||
[Firebase]: https://firebase.google.com/docs/hosting/ "Firebase static hosting"
|
[Firebase]: https://firebase.google.com/docs/hosting/
|
||||||
[GitHub Pages]: https://pages.github.com/
|
[GitHub Pages]: https://pages.github.com/
|
||||||
[GitLab Pages]: https://about.gitlab.com/features/pages/
|
[GitLab Pages]: https://about.gitlab.com/features/pages/
|
||||||
[Go language]: https://go.dev/
|
[Go language]: https://go.dev/
|
||||||
[GoDaddy]: https://www.godaddy.com/ "GoDaddy.com Hosting"
|
[GoDaddy]: https://www.godaddy.com/
|
||||||
[Google Cloud Storage]: https://cloud.google.com/storage/
|
[Google Cloud Storage]: https://cloud.google.com/storage/
|
||||||
[Heroku]: https://www.heroku.com/
|
[Heroku]: https://www.heroku.com/
|
||||||
[Jekyll]: https://jekyllrb.com/
|
[Jekyll]: https://jekyllrb.com/
|
||||||
|
|
|
@ -68,7 +68,7 @@ If none of these exists, Hugo uses a built-in default archetype.
|
||||||
|
|
||||||
## Functions and context
|
## Functions and context
|
||||||
|
|
||||||
You can use any [template function] within an archetype. As shown above, the default archetype uses the [`replace`](/functions/replace/) function to replace hyphens with spaces when populating the title in front matter.
|
You can use any [template function] within an archetype. As shown above, the default archetype uses the [`replace`](/functions/strings/replace) function to replace hyphens with spaces when populating the title in front matter.
|
||||||
|
|
||||||
Archetypes receive the following objects and values in [context]:
|
Archetypes receive the following objects and values in [context]:
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ Hugo passes reasonable default arguments to these external helpers by default:
|
||||||
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.
|
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.
|
||||||
{{% /note %}}
|
{{% /note %}}
|
||||||
|
|
||||||
### External helper Asciidoctor
|
### Asciidoctor
|
||||||
|
|
||||||
The Asciidoctor community offers a wide set of tools for the AsciiDoc format that can be installed additionally to Hugo.
|
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
|
[See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/). Make sure that also all
|
||||||
|
@ -59,52 +59,9 @@ optional extensions like `asciidoctor-diagram` or `asciidoctor-html5s` are insta
|
||||||
External `asciidoctor` command requires Hugo rendering to _disk_ to a specific destination directory. It is required to run Hugo with the command option `--destination`.
|
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 %}}
|
{{% /note %}}
|
||||||
|
|
||||||
Some [Asciidoctor](https://asciidoctor.org/man/asciidoctor/) parameters can be customized in Hugo:
|
Some Asciidoctor parameters can be customized in Hugo. See [details].
|
||||||
|
|
||||||
Parameter | Comment
|
[details]: /getting-started/configuration-markup/#asciidoc
|
||||||
--- | ---
|
|
||||||
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`.
|
|
||||||
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
|
## Learn markdown
|
||||||
|
|
||||||
|
@ -115,7 +72,6 @@ Markdown syntax is simple enough to learn in a single sitting. The following are
|
||||||
* [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial]
|
* [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial]
|
||||||
* [The Markdown Guide, Matt Cone][mdguide]
|
* [The Markdown Guide, Matt Cone][mdguide]
|
||||||
|
|
||||||
[`emojify` function]: /functions/emojify/
|
|
||||||
[ascii]: https://asciidoctor.org/
|
[ascii]: https://asciidoctor.org/
|
||||||
[config]: /getting-started/configuration/
|
[config]: /getting-started/configuration/
|
||||||
[developer tools]: /tools/
|
[developer tools]: /tools/
|
||||||
|
|
|
@ -101,12 +101,45 @@ Example 4: Skips rendering if there's problem accessing a remote resource.
|
||||||
|
|
||||||
## Image processing methods
|
## Image processing methods
|
||||||
|
|
||||||
The `image` resource implements the [`Resize`], [`Fit`], [`Fill`], [`Crop`], [`Filter`], [`Colors`] and [`Exif`] methods.
|
The `image` resource implements the [`Process`], [`Resize`], [`Fit`], [`Fill`], [`Crop`], [`Filter`], [`Colors`] and [`Exif`] methods.
|
||||||
|
|
||||||
{{% note %}}
|
{{% 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.
|
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 %}}
|
{{% /note %}}
|
||||||
|
|
||||||
|
### Process
|
||||||
|
|
||||||
|
{{< new-in "0.119.0" >}}
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
The `Process` method is also available as a filter, which is more effective if need to apply multiple filters to an image. See [Process filter](/functions/images/#process).
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
|
Process processes the image with the given specification. The specification can contain an optional action, one of `resize`, `crop`, `fit` or `fill`. This means that you can use this method instead of [`Resize`], [`Fit`], [`Fill`], or [`Crop`].
|
||||||
|
|
||||||
|
See [Options](#image-processing-options) for available options.
|
||||||
|
|
||||||
|
You can also use this method apply image processing that does not need any scaling, e.g. format conversions:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{/* Convert the image from JPG to PNG. */}}
|
||||||
|
{{ $png := $jpg.Process "png" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Some more examples:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{/* Rotate the image 90 degrees counter-clockwise. */}}
|
||||||
|
{{ $image := $image.Process "r90" }}
|
||||||
|
|
||||||
|
{{/* Scaling actions. */}}
|
||||||
|
{{ $image := $image.Process "resize 600x" }}
|
||||||
|
{{ $image := $image.Process "crop 600x400" }}
|
||||||
|
{{ $image := $image.Process "fit 600x400" }}
|
||||||
|
{{ $image := $image.Process "fill 600x400" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Resize
|
### Resize
|
||||||
|
|
||||||
Resize an image to the specified width and/or height.
|
Resize an image to the specified width and/or height.
|
||||||
|
@ -468,15 +501,16 @@ If you change image processing methods or options, or if you rename or remove im
|
||||||
hugo --gc
|
hugo --gc
|
||||||
```
|
```
|
||||||
|
|
||||||
[time.Format]: /functions/dateformat
|
[time.Format]: /functions/time/format
|
||||||
[`anchor`]: /content-management/image-processing#anchor
|
[`anchor`]: /content-management/image-processing#anchor
|
||||||
[mounted]: /hugo-modules/configuration#module-configuration-mounts
|
[mounted]: /hugo-modules/configuration#module-configuration-mounts
|
||||||
[page bundle]: /content-management/page-bundles
|
[page bundle]: /content-management/page-bundles
|
||||||
[`lang.FormatNumber`]: /functions/lang
|
[`lang.FormatNumber`]: /functions/lang/formatnumber
|
||||||
[filters]: /functions/images
|
[filters]: /functions/images
|
||||||
[github.com/disintegration/imaging]: <https://github.com/disintegration/imaging#image-resizing>
|
[github.com/disintegration/imaging]: <https://github.com/disintegration/imaging#image-resizing>
|
||||||
[Smartcrop]: <https://github.com/muesli/smartcrop#smartcrop>
|
[Smartcrop]: <https://github.com/muesli/smartcrop#smartcrop>
|
||||||
[Exif]: <https://en.wikipedia.org/wiki/Exif>
|
[Exif]: <https://en.wikipedia.org/wiki/Exif>
|
||||||
|
[`Process`]: #process
|
||||||
[`Colors`]: #colors
|
[`Colors`]: #colors
|
||||||
[`Crop`]: #crop
|
[`Crop`]: #crop
|
||||||
[`Exif`]: #exif
|
[`Exif`]: #exif
|
||||||
|
@ -485,4 +519,4 @@ hugo --gc
|
||||||
[`Fit`]: #fit
|
[`Fit`]: #fit
|
||||||
[`Resize`]: #resize
|
[`Resize`]: #resize
|
||||||
[site configuration]: #processing-options
|
[site configuration]: #processing-options
|
||||||
[`with`]: /functions/with/
|
[`with`]: /functions/go-template/with/
|
||||||
|
|
|
@ -468,7 +468,7 @@ English|Wednesday, November 3, 2021
|
||||||
Français|mercredi 3 novembre 2021
|
Français|mercredi 3 novembre 2021
|
||||||
Deutsch|Mittwoch, 3. November 2021
|
Deutsch|Mittwoch, 3. November 2021
|
||||||
|
|
||||||
See [time.Format] for details.
|
See [`time.Format`] for details.
|
||||||
|
|
||||||
### Currency
|
### Currency
|
||||||
|
|
||||||
|
@ -526,11 +526,86 @@ See [lang.FormatPercent] for details.
|
||||||
|
|
||||||
## Menus
|
## Menus
|
||||||
|
|
||||||
Localization of menu entries depends on the how you define them:
|
Localization of menu entries depends on how you define them:
|
||||||
|
|
||||||
- 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 [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 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.
|
- When you define menu entries [in site configuration], you must create language-specific menu entries under each language key. If the names of the menu entries are insufficent, use translation tables to localize each entry.
|
||||||
|
|
||||||
|
### Create language-specific menu entries
|
||||||
|
|
||||||
|
#### Method 1 -- Use a single configuration file
|
||||||
|
|
||||||
|
For a simple menu with a small number of entries, use a single configuration file. For example:
|
||||||
|
|
||||||
|
{{< code-toggle file="hugo" copy=false >}}
|
||||||
|
[languages.de]
|
||||||
|
languageCode = 'de-DE'
|
||||||
|
languageName = 'Deutsch'
|
||||||
|
weight = 1
|
||||||
|
|
||||||
|
[[languages.de.menu.main]]
|
||||||
|
name = 'Produkte'
|
||||||
|
pageRef = '/products'
|
||||||
|
weight = 10
|
||||||
|
|
||||||
|
[[languages.de.menu.main]]
|
||||||
|
name = 'Leistungen'
|
||||||
|
pageRef = '/services'
|
||||||
|
weight = 20
|
||||||
|
|
||||||
|
[languages.en]
|
||||||
|
languageCode = 'en-US'
|
||||||
|
languageName = 'English'
|
||||||
|
weight = 2
|
||||||
|
|
||||||
|
[[languages.en.menu.main]]
|
||||||
|
name = 'Products'
|
||||||
|
pageRef = '/products'
|
||||||
|
weight = 10
|
||||||
|
|
||||||
|
[[languages.en.menu.main]]
|
||||||
|
name = 'Services'
|
||||||
|
pageRef = '/services'
|
||||||
|
weight = 20
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
#### Method 2 -- Use a configuration directory
|
||||||
|
|
||||||
|
With a more complex menu structure, create a [configuration directory] and split the menu entries into multiple files, one file per language. For example:
|
||||||
|
|
||||||
|
```text
|
||||||
|
config/
|
||||||
|
└── _default/
|
||||||
|
├── menus/
|
||||||
|
│ ├── menu.de.toml
|
||||||
|
│ └── menu.en.toml
|
||||||
|
└── hugo.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
{{< code-toggle file="config/_default/menus/menu.de" copy=false >}}
|
||||||
|
[[main]]
|
||||||
|
name = 'Produkte'
|
||||||
|
pageRef = '/products'
|
||||||
|
weight = 10
|
||||||
|
[[main]]
|
||||||
|
name = 'Leistungen'
|
||||||
|
pageRef = '/services'
|
||||||
|
weight = 20
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
{{< code-toggle file="config/_default/menus/menu.en" copy=false >}}
|
||||||
|
[[main]]
|
||||||
|
name = 'Products'
|
||||||
|
pageRef = '/products'
|
||||||
|
weight = 10
|
||||||
|
[[main]]
|
||||||
|
name = 'Services'
|
||||||
|
pageRef = '/services'
|
||||||
|
weight = 20
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
[configuration directory]: /getting-started/configuration/#configuration-directory
|
||||||
|
|
||||||
### Use translation tables
|
### Use translation tables
|
||||||
|
|
||||||
|
@ -574,44 +649,6 @@ services = 'Leistungen'
|
||||||
[in front matter]: /content-management/menus/#define-in-front-matter
|
[in front matter]: /content-management/menus/#define-in-front-matter
|
||||||
[in site configuration]: /content-management/menus/#define-in-site-configuration
|
[in site configuration]: /content-management/menus/#define-in-site-configuration
|
||||||
|
|
||||||
### Create language-specific menu entries
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
{{< code-toggle file="hugo" copy=false >}}
|
|
||||||
[languages.de]
|
|
||||||
languageCode = 'de-DE'
|
|
||||||
languageName = 'Deutsch'
|
|
||||||
weight = 1
|
|
||||||
|
|
||||||
[[languages.de.menu.main]]
|
|
||||||
name = 'Produkte'
|
|
||||||
pageRef = '/products'
|
|
||||||
weight = 10
|
|
||||||
|
|
||||||
[[languages.de.menu.main]]
|
|
||||||
name = 'Leistungen'
|
|
||||||
pageRef = '/services'
|
|
||||||
weight = 20
|
|
||||||
|
|
||||||
[languages.en]
|
|
||||||
languageCode = 'en-US'
|
|
||||||
languageName = 'English'
|
|
||||||
weight = 2
|
|
||||||
|
|
||||||
[[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
|
## 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.
|
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.
|
||||||
|
@ -636,7 +673,7 @@ i18n|MISSING_TRANSLATION|en|wordCount
|
||||||
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:
|
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`
|
* 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 }}`
|
* Be constructed with the [`relLangURL`] or [`absLangURL`] template function, 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).
|
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).
|
||||||
|
|
||||||
|
@ -657,23 +694,23 @@ hugo new content content/en/post/test.md
|
||||||
hugo new content content/de/post/test.md
|
hugo new content content/de/post/test.md
|
||||||
```
|
```
|
||||||
|
|
||||||
[abslangurl]: /functions/abslangurl
|
[`abslangurl`]: /functions/urls/abslangurl
|
||||||
[config]: /getting-started/configuration/
|
[config]: /getting-started/configuration/
|
||||||
[contenttemplate]: /templates/single-page-templates/
|
[contenttemplate]: /templates/single-page-templates/
|
||||||
[go-i18n-source]: https://github.com/nicksnyder/go-i18n
|
[go-i18n-source]: https://github.com/nicksnyder/go-i18n
|
||||||
[go-i18n]: https://github.com/nicksnyder/go-i18n
|
[go-i18n]: https://github.com/nicksnyder/go-i18n
|
||||||
[homepage]: /templates/homepage/
|
[homepage]: /templates/homepage/
|
||||||
[Hugo Multilingual Part 1: Content translation]: https://regisphilibert.com/blog/2018/08/hugo-multilingual-part-1-managing-content-translation/
|
[Hugo Multilingual Part 1: Content translation]: https://regisphilibert.com/blog/2018/08/hugo-multilingual-part-1-managing-content-translation/
|
||||||
[i18func]: /functions/i18n/
|
[i18func]: /functions/lang/translate
|
||||||
[lang.FormatAccounting]: /functions/lang
|
[lang.FormatAccounting]: /functions/lang/formataccounting
|
||||||
[lang.FormatCurrency]: /functions/lang
|
[lang.FormatCurrency]: /functions/lang/formatcurrency
|
||||||
[lang.FormatNumber]: /functions/lang
|
[lang.FormatNumber]: /functions/lang/formatnumber
|
||||||
[lang.FormatNumberCustom]: /functions/lang
|
[lang.FormatNumberCustom]: /functions/lang/formatnumbercustom
|
||||||
[lang.FormatPercent]: /functions/lang
|
[lang.FormatPercent]: /functions/lang/formatpercent
|
||||||
[lang.Merge]: /functions/lang.merge/
|
[lang.Merge]: /functions/lang/merge/
|
||||||
[menus]: /content-management/menus/
|
[menus]: /content-management/menus/
|
||||||
[OS environment]: /getting-started/configuration/#configure-with-environment-variables
|
[OS environment]: /getting-started/configuration/#configure-with-environment-variables
|
||||||
[rellangurl]: /functions/rellangurl
|
[`rellangurl`]: /functions/urls/rellangurl
|
||||||
[RFC 5646]: https://tools.ietf.org/html/rfc5646
|
[RFC 5646]: https://tools.ietf.org/html/rfc5646
|
||||||
[single page templates]: /templates/single-page-templates/
|
[single page templates]: /templates/single-page-templates/
|
||||||
[time.Format]: /functions/dateformat
|
[`time.Format`]: /functions/time/format
|
||||||
|
|
|
@ -187,7 +187,7 @@ Rendered:
|
||||||
|
|
||||||
To specify one or more [highlighting options], include a quotation-encapsulated, comma-separated list:
|
To specify one or more [highlighting options], include a quotation-encapsulated, comma-separated list:
|
||||||
|
|
||||||
[highlighting options]: /functions/highlight/
|
[highlighting options]: /functions/transform/highlight/
|
||||||
|
|
||||||
```text
|
```text
|
||||||
{{</* highlight go-html-template "lineNos=inline, lineNoStart=42" */>}}
|
{{</* highlight go-html-template "lineNos=inline, lineNoStart=42" */>}}
|
||||||
|
@ -391,7 +391,7 @@ To learn more about creating custom shortcodes, see the [shortcode template docu
|
||||||
[`figure` shortcode]: #figure
|
[`figure` shortcode]: #figure
|
||||||
[contentmanagementsection]: /content-management/formats/
|
[contentmanagementsection]: /content-management/formats/
|
||||||
[examplegist]: https://gist.github.com/spf13/7896402
|
[examplegist]: https://gist.github.com/spf13/7896402
|
||||||
[figureelement]: https://html5doctor.com/the-figure-figcaption-elements/ "An article from HTML5 doctor discussing the fig and figcaption elements."
|
[figureelement]: https://html5doctor.com/the-figure-figcaption-elements/
|
||||||
[Hugo and the GDPR]: /about/hugo-and-gdpr/
|
[Hugo and the GDPR]: /about/hugo-and-gdpr/
|
||||||
[Instagram]: https://www.instagram.com/
|
[Instagram]: https://www.instagram.com/
|
||||||
[pagevariables]: /variables/page/
|
[pagevariables]: /variables/page/
|
||||||
|
|
|
@ -92,7 +92,7 @@ Gives this:
|
||||||
|
|
||||||
## Highlight template function
|
## Highlight template function
|
||||||
|
|
||||||
See [Highlight](/functions/highlight/).
|
See [Highlight](/functions/transform/highlight/).
|
||||||
|
|
||||||
## Highlighting in code fences
|
## Highlighting in code fences
|
||||||
|
|
||||||
|
|
|
@ -191,12 +191,11 @@ title: "Bruce Willis"
|
||||||
wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
|
wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
|
||||||
{{< /code-toggle >}}
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
[`urlize` template function]: /functions/urlize/
|
|
||||||
[content section]: /content-management/sections/
|
[content section]: /content-management/sections/
|
||||||
[content type]: /content-management/types/
|
[content type]: /content-management/types/
|
||||||
[documentation on archetypes]: /content-management/archetypes/
|
[documentation on archetypes]: /content-management/archetypes/
|
||||||
[front matter]: /content-management/front-matter/
|
[front matter]: /content-management/front-matter/
|
||||||
[taxonomy list templates]: /templates/taxonomy-templates/#taxonomy-list-templates
|
[taxonomy list templates]: /templates/taxonomy-templates/#taxonomy-list-templates
|
||||||
[taxonomy templates]: /templates/taxonomy-templates/
|
[taxonomy templates]: /templates/taxonomy-templates/
|
||||||
[terms within the taxonomy]: /templates/taxonomy-templates/#taxonomy-terms-templates "See how to order terms associated with a taxonomy"
|
[terms within the taxonomy]: /templates/taxonomy-templates/#taxonomy-terms-templates
|
||||||
[configuration]: /getting-started/configuration/
|
[site configuration]: /getting-started/configuration/
|
||||||
|
|
|
@ -2,12 +2,15 @@
|
||||||
title: .AddDate
|
title: .AddDate
|
||||||
description: Returns the time corresponding to adding the given number of years, months, and days to the given time.Time value.
|
description: Returns the time corresponding to adding the given number of years, months, and days to the given time.Time value.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [dates,time]
|
function:
|
||||||
signature: [".AddDate YEARS MONTHS DAYS"]
|
aliases: []
|
||||||
relatedfuncs: [now]
|
returnType: time.Time
|
||||||
|
signatures: [.AddDate YEARS MONTHS DAYS]
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
90
content/en/functions/Format.md
Normal file
90
content/en/functions/Format.md
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
---
|
||||||
|
title: .Format
|
||||||
|
description: Returns a formatted time.Time value.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: string
|
||||||
|
signatures: [.Format LAYOUT]
|
||||||
|
relatedFunctions: []
|
||||||
|
toc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-template
|
||||||
|
{{ $t := "2023-01-27T23:44:58-08:00" }}
|
||||||
|
{{ $t = time.AsTime $t }}
|
||||||
|
{{ $format := "2 Jan 2006" }}
|
||||||
|
|
||||||
|
{{ $t.Format $format }} → 27 Jan 2023
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
To return a formatted and localized `time.Time` value, use the [`time.Format`] function instead.
|
||||||
|
|
||||||
|
[`time.Format`]: /functions/time/format
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
|
Use the `.Format` method with any `time.Time` value, including the four predefined front matter dates:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $format := "2 Jan 2006" }}
|
||||||
|
|
||||||
|
{{ .Date.Format $format }}
|
||||||
|
{{ .PublishDate.Format $format }}
|
||||||
|
{{ .ExpiryDate.Format $format }}
|
||||||
|
{{ .Lastmod.Format $format }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Layout string
|
||||||
|
|
||||||
|
{{% readfile file="/functions/_common/time-layout-string.md" %}}
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Given this front matter:
|
||||||
|
|
||||||
|
{{< code-toggle fm=true copy=false >}}
|
||||||
|
title = "About time"
|
||||||
|
date = 2023-01-27T23:44:58-08:00
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
The examples below were rendered in the `America/Los_Angeles` time zone:
|
||||||
|
|
||||||
|
Format string|Result
|
||||||
|
:--|:--
|
||||||
|
`Monday, January 2, 2006`|`Friday, January 27, 2023`
|
||||||
|
`Mon Jan 2 2006`|`Fri Jan 27 2023`
|
||||||
|
`January 2006`|`January 2023`
|
||||||
|
`2006-01-02`|`2023-01-27`
|
||||||
|
`Monday`|`Friday`
|
||||||
|
`02 Jan 06 15:04 MST`|`27 Jan 23 23:44 PST`
|
||||||
|
`Mon, 02 Jan 2006 15:04:05 MST`|`Fri, 27 Jan 2023 23:44:58 PST`
|
||||||
|
`Mon, 02 Jan 2006 15:04:05 -0700`|`Fri, 27 Jan 2023 23:44:58 -0800`
|
||||||
|
|
||||||
|
## UTC and local time
|
||||||
|
|
||||||
|
Convert and format any `time.Time` value to either Coordinated Universal Time (UTC) or local time.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $t := "2023-01-27T23:44:58-08:00" }}
|
||||||
|
{{ $t = time.AsTime $t }}
|
||||||
|
{{ $format := "2 Jan 2006 3:04:05 PM MST" }}
|
||||||
|
|
||||||
|
{{ $t.UTC.Format $format }} → 28 Jan 2023 7:44:58 AM UTC
|
||||||
|
{{ $t.Local.Format $format }} → 27 Jan 2023 11:44:58 PM PST
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ordinal representation
|
||||||
|
|
||||||
|
Use the [`humanize`](/functions/inflect/humanize) function to render the day of the month as an ordinal number:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $t := "2023-01-27T23:44:58-08:00" }}
|
||||||
|
{{ $t = time.AsTime $t }}
|
||||||
|
|
||||||
|
{{ humanize $t.Day }} of {{ $t.Format "January 2006" }} → 27th of January 2023
|
||||||
|
```
|
|
@ -2,12 +2,17 @@
|
||||||
title: .Get
|
title: .Get
|
||||||
description: Accesses positional and ordered parameters in shortcode declaration.
|
description: Accesses positional and ordered parameters in shortcode declaration.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [shortcodes]
|
function:
|
||||||
signature: [".Get INDEX", ".Get KEY"]
|
aliases: []
|
||||||
relatedfuncs: []
|
returnType: any
|
||||||
|
signatures:
|
||||||
|
- .Get INDEX
|
||||||
|
- .Get KEY
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
||||||
`.Get` is specifically used when creating your own [shortcode template][sc], to access the [positional and named](/templates/shortcode-templates/#positional-vs-named-parameters) parameters passed to it. When used with a numeric INDEX, it queries positional parameters (starting with 0). With a string KEY, it queries named parameters.
|
`.Get` is specifically used when creating your own [shortcode template][sc], to access the [positional and named](/templates/shortcode-templates/#positional-vs-named-parameters) parameters passed to it. When used with a numeric INDEX, it queries positional parameters (starting with 0). With a string KEY, it queries named parameters.
|
|
@ -1,13 +1,16 @@
|
||||||
---
|
---
|
||||||
title: .GetPage
|
title: .GetPage
|
||||||
description: "Gets a `Page` of a given `path`."
|
description: Gets a `Page` of a given `path`.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [sections,lists,indexes]
|
function:
|
||||||
signature: [".GetPage PATH"]
|
aliases: []
|
||||||
relatedfuncs: []
|
returnType:
|
||||||
|
signatures: [.GetPage PATH]
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
||||||
`.GetPage` returns a page of a given `path`. Both `Site` and `Page` implements this method. The `Page` variant will, if given a relative path -- i.e. a path without a leading `/` -- try look for the page relative to the current page.
|
`.GetPage` returns a page of a given `path`. Both `Site` and `Page` implements this method. The `Page` variant will, if given a relative path -- i.e. a path without a leading `/` -- try look for the page relative to the current page.
|
||||||
|
|
35
content/en/functions/HasMenuCurrent.md
Normal file
35
content/en/functions/HasMenuCurrent.md
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
---
|
||||||
|
title: .HasMenuCurrent
|
||||||
|
description: Reports whether the given page object matches the page object associated with one of the child menu entries under the given menu entry in the given menu.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: bool
|
||||||
|
signatures: [PAGE.HasMenuCurrent MENU MENUENTRY]
|
||||||
|
relatedFunctions:
|
||||||
|
- .HasMenuCurrent
|
||||||
|
- .IsMenuCurrent
|
||||||
|
---
|
||||||
|
|
||||||
|
If the page object associated with the menu entry is a section, this method also returns `true` for any descendant of that section.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $currentPage := . }}
|
||||||
|
{{ range site.Menus.main }}
|
||||||
|
{{ if $currentPage.IsMenuCurrent .Menu . }}
|
||||||
|
<a class="active" aria-current="page" href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ else if $currentPage.HasMenuCurrent .Menu . }}
|
||||||
|
<a class="ancestor" aria-current="true" href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ else }}
|
||||||
|
<a href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
See [menu templates] for a complete example.
|
||||||
|
|
||||||
|
[menu templates]: /templates/menu-templates/#example
|
33
content/en/functions/IsMenuCurrent.md
Normal file
33
content/en/functions/IsMenuCurrent.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
title: .IsMenuCurrent
|
||||||
|
description: Reports whether the given page object matches the page object associated with the given menu entry in the given menu.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: bool
|
||||||
|
signatures: [PAGE.IsMenuCurrent MENU MENUENTRY]
|
||||||
|
relatedFunctions:
|
||||||
|
- .HasMenuCurrent
|
||||||
|
- .IsMenuCurrent
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $currentPage := . }}
|
||||||
|
{{ range site.Menus.main }}
|
||||||
|
{{ if $currentPage.IsMenuCurrent .Menu . }}
|
||||||
|
<a class="active" aria-current="page" href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ else if $currentPage.HasMenuCurrent .Menu . }}
|
||||||
|
<a class="ancestor" aria-current="true" href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ else }}
|
||||||
|
<a href="{{ .URL }}">{{ .Name }}</a>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
See [menu templates] for a complete example.
|
||||||
|
|
||||||
|
[menu templates]: /templates/menu-templates/#example
|
|
@ -1,12 +1,16 @@
|
||||||
---
|
---
|
||||||
title: .Param
|
title: .Param
|
||||||
description: Returns a page parameter, falling back to a site parameter if present.
|
description: Returns a page parameter, falling back to a site parameter if present.
|
||||||
signature: ['.Param KEY']
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
keywords: ['front matter', 'params']
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: any
|
||||||
|
signatures: [.Param KEY]
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
||||||
The `.Param` method on `.Page` looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY` in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the `.Param` method returns `nil`.
|
The `.Param` method on `.Page` looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY` in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the `.Param` method returns `nil`.
|
|
@ -2,12 +2,15 @@
|
||||||
title: .Render
|
title: .Render
|
||||||
description: Takes a view to apply when rendering content.
|
description: Takes a view to apply when rendering content.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [views]
|
function:
|
||||||
signature: [".Render LAYOUT"]
|
aliases: []
|
||||||
relatedfuncs: []
|
returnType: template.HTML
|
||||||
|
signatures: [.Render LAYOUT]
|
||||||
|
relatedFunctions: []
|
||||||
---
|
---
|
||||||
|
|
||||||
The view is an alternative layout and should be a file name that points to a template in one of the locations specified in the documentation for [Content Views](/templates/views).
|
The view is an alternative layout and should be a file name that points to a template in one of the locations specified in the documentation for [Content Views](/templates/views).
|
|
@ -1,12 +1,15 @@
|
||||||
---
|
---
|
||||||
title: .RenderString
|
title: .RenderString
|
||||||
description: "Renders markup to HTML."
|
description: Renders markup to HTML.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [markdown,goldmark,render]
|
function:
|
||||||
signature: [".RenderString MARKUP"]
|
aliases: []
|
||||||
|
returnType: template.HTML
|
||||||
|
signatures: ['.RenderString MARKUP [OPTIONS]']
|
||||||
---
|
---
|
||||||
|
|
||||||
`.RenderString` is a method on `Page` that renders some markup to HTML using the content renderer defined for that page (if not set in the options).
|
`.RenderString` is a method on `Page` that renders some markup to HTML using the content renderer defined for that page (if not set in the options).
|
||||||
|
@ -29,4 +32,4 @@ Some examples:
|
||||||
{{ "/italic org mode/" | $p.RenderString $optOrg }}
|
{{ "/italic org mode/" | $p.RenderString $optOrg }}
|
||||||
```
|
```
|
||||||
|
|
||||||
{{< new-in "0.93.0" >}} **Note**: [markdownify](/functions/markdownify/) uses this function in order to support [Render Hooks](/getting-started/configuration-markup/#markdown-render-hooks).
|
{{< new-in "0.93.0" >}} **Note**: [markdownify](/functions/transform/markdownify) uses this function in order to support [Render Hooks](/getting-started/configuration-markup/#markdown-render-hooks).
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
---
|
---
|
||||||
title: .Scratch
|
title: .Scratch
|
||||||
description: Acts as a "scratchpad" to store and manipulate data.
|
description: Acts as a "scratchpad" to store and manipulate data.
|
||||||
keywords: [iteration]
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
toc:
|
function:
|
||||||
signature: []
|
aliases: []
|
||||||
relatedfuncs: []
|
returnType:
|
||||||
|
signatures: []
|
||||||
|
relatedFunctions:
|
||||||
|
- .Store
|
||||||
|
- .Scratch
|
||||||
aliases: [/extras/scratch/,/doc/scratch/]
|
aliases: [/extras/scratch/,/doc/scratch/]
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -72,7 +76,7 @@ Get the value of a given key.
|
||||||
|
|
||||||
Add a given value to existing value(s) of the given key.
|
Add a given value to existing value(s) of the given key.
|
||||||
|
|
||||||
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be [appended](/functions/append/) to that list.
|
For single values, `Add` accepts values that support Go's `+` operator. If the first `Add` for a key is an array or slice, the following adds will be [appended](/functions/collections/append/) to that list.
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $scratch.Add "greetings" "Hello" }}
|
{{ $scratch.Add "greetings" "Hello" }}
|
|
@ -2,11 +2,17 @@
|
||||||
title: .Store
|
title: .Store
|
||||||
description: Returns a Scratch that is not reset on server rebuilds.
|
description: Returns a Scratch that is not reset on server rebuilds.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [scratch]
|
function:
|
||||||
signature: []
|
aliases: []
|
||||||
|
returnType:
|
||||||
|
signatures: []
|
||||||
|
relatedFunctions:
|
||||||
|
- .Store
|
||||||
|
- .Scratch
|
||||||
---
|
---
|
||||||
|
|
||||||
The `.Store` method on `.Page` returns a [Scratch] to store and manipulate data. In contrast to the `.Scratch` method, this Scratch is not reset on server rebuilds.
|
The `.Store` method on `.Page` returns a [Scratch] to store and manipulate data. In contrast to the `.Scratch` method, this Scratch is not reset on server rebuilds.
|
36
content/en/functions/Unix.md
Normal file
36
content/en/functions/Unix.md
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
title: .Unix
|
||||||
|
description: Converts a time.Time value to the number of seconds elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970.
|
||||||
|
categories: [functions]
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: int64
|
||||||
|
signatures:
|
||||||
|
- .Unix
|
||||||
|
- .UnixMilli
|
||||||
|
- .UnixMicro
|
||||||
|
- .UnixNano
|
||||||
|
relatedFunctions: []
|
||||||
|
---
|
||||||
|
|
||||||
|
The `Milli`, `Micro`, and `Nano` variants return the number of milliseconds, microseconds, and nanoseconds (respectively) elapsed since the Unix epoch.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
.Date.Unix → 1637259694
|
||||||
|
.ExpiryDate.Unix → 1672559999
|
||||||
|
.Lastmod.Unix → 1637361786
|
||||||
|
.PublishDate.Unix → 1637421261
|
||||||
|
|
||||||
|
("1970-01-01T00:00:00-00:00" | time.AsTime).Unix → 0
|
||||||
|
("1970-01-01T00:00:42-00:00" | time.AsTime).Unix → 42
|
||||||
|
("1970-04-11T01:48:29-08:00" | time.AsTime).Unix → 8675309
|
||||||
|
("2026-05-02T20:09:31-07:00" | time.AsTime).Unix → 1777777771
|
||||||
|
|
||||||
|
now.Unix → 1637447841
|
||||||
|
now.UnixMilli → 1637447841347
|
||||||
|
now.UnixMicro → 1637447841347378
|
||||||
|
now.UnixNano → 1637447841347378799
|
||||||
|
```
|
3
content/en/functions/_common/go-template-functions.md
Normal file
3
content/en/functions/_common/go-template-functions.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
See Go's [text/template] documentation for more details.
|
||||||
|
|
||||||
|
[text/template]: https://pkg.go.dev/text/template
|
3
content/en/functions/_common/locales.md
Normal file
3
content/en/functions/_common/locales.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Localization of dates, currencies, numbers, and percentages is performed by the [gohugoio/locales] package. The language tag of the current site must match one of the listed locales.
|
||||||
|
|
||||||
|
[gohugoio/locales]: https://github.com/gohugoio/locales
|
42
content/en/functions/_common/time-layout-string.md
Normal file
42
content/en/functions/_common/time-layout-string.md
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
Format a `time.Time` value based on [Go's reference time]:
|
||||||
|
|
||||||
|
[Go's reference time]: https://pkg.go.dev/time#pkg-constants
|
||||||
|
|
||||||
|
```text {copy=false}
|
||||||
|
Mon Jan 2 15:04:05 MST 2006
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a format string using these components:
|
||||||
|
|
||||||
|
Description|Valid components
|
||||||
|
:--|:--
|
||||||
|
Year|`"2006" "06"`
|
||||||
|
Month|`"Jan" "January" "01" "1"`
|
||||||
|
Day of the week|`"Mon" "Monday"`
|
||||||
|
Day of the month|`"2" "_2" "02"`
|
||||||
|
Day of the year|`"__2" "002"`
|
||||||
|
Hour|`"15" "3" "03"`
|
||||||
|
Minute|`"4" "04"`
|
||||||
|
Second|`"5" "05"`
|
||||||
|
AM/PM mark|`"PM"`
|
||||||
|
Time zone offsets|`"-0700" "-07:00" "-07" "-070000" "-07:00:00"`
|
||||||
|
|
||||||
|
Replace the sign in the format string with a Z to print Z instead of an offset for the UTC zone.
|
||||||
|
|
||||||
|
Description|Valid components
|
||||||
|
:--|:--
|
||||||
|
Time zone offsets|`"Z0700" "Z07:00" "Z07" "Z070000" "Z07:00:00"`
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $t := "2023-01-27T23:44:58-08:00" }}
|
||||||
|
{{ $t = time.AsTime $t }}
|
||||||
|
{{ $t = $t.Format "Jan 02, 2006 3:04 PM Z07:00" }}
|
||||||
|
|
||||||
|
{{ $t }} → Jan 27, 2023 11:44 PM -08:00
|
||||||
|
```
|
||||||
|
|
||||||
|
Strings such as `PST` and `CET` are not time zones. They are time zone _abbreviations_.
|
||||||
|
|
||||||
|
Strings such as `-07:00` and `+01:00` are not time zones. They are time zone _offsets_.
|
||||||
|
|
||||||
|
A time zone is a geographic area with the same local time. For example, the time zone abbreviated by `PST` and `PDT` (depending on Daylight Savings Time) is `America/Los_Angeles`.
|
|
@ -1,28 +0,0 @@
|
||||||
---
|
|
||||||
title: base64
|
|
||||||
description: "`base64Encode` and `base64Decode` let you easily decode content with a base64 encoding and vice versa through pipes."
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: []
|
|
||||||
relatedfuncs: []
|
|
||||||
signature: ["base64Decode INPUT", "base64Encode INPUT"]
|
|
||||||
---
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ "Hugo" | base64Encode }} → "SHVnbw=="
|
|
||||||
{{ "SHVnbw==" | base64Decode }} → "Hugo"
|
|
||||||
```
|
|
||||||
|
|
||||||
## `base64` with APIs
|
|
||||||
|
|
||||||
Using base64 to decode and encode becomes really powerful if we have to handle
|
|
||||||
responses from APIs.
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme" }}
|
|
||||||
{{ $resp.content | base64Decode | markdownify }}
|
|
||||||
```
|
|
||||||
|
|
||||||
The response of the GitHub API contains the base64-encoded version of the [README.md](https://github.com/gohugoio/hugo/blob/master/README.md) in the Hugo repository. Now we can decode it and parse the Markdown. The final output will look similar to the rendered version on GitHub.
|
|
|
@ -1,13 +1,21 @@
|
||||||
---
|
---
|
||||||
title: float
|
title: cast.ToFloat
|
||||||
|
linkTitle: float
|
||||||
description: Casts a value to a decimal (base 10) floating point value.
|
description: Casts a value to a decimal (base 10) floating point value.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [cast,strings,floats]
|
function:
|
||||||
signature: ["float INPUT"]
|
aliases: [float]
|
||||||
relatedfuncs: []
|
returnType: float64
|
||||||
|
signatures: [cast.ToFloat INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- cast.ToFloat
|
||||||
|
- cast.ToInt
|
||||||
|
- cast.ToString
|
||||||
|
aliases: [/functions/float]
|
||||||
---
|
---
|
||||||
|
|
||||||
With a decimal (base 10) input:
|
With a decimal (base 10) input:
|
|
@ -1,13 +1,21 @@
|
||||||
---
|
---
|
||||||
title: int
|
title: cast.ToInt
|
||||||
|
linkTitle: int
|
||||||
description: Casts a value to a decimal (base 10) integer.
|
description: Casts a value to a decimal (base 10) integer.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [cast,strings,integers]
|
function:
|
||||||
signature: ["int INPUT"]
|
aliases: [int]
|
||||||
relatedfuncs: []
|
returnType: int
|
||||||
|
signatures: [cast.ToInt INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- cast.ToFloat
|
||||||
|
- cast.ToInt
|
||||||
|
- cast.ToString
|
||||||
|
aliases: [/functions/int]
|
||||||
---
|
---
|
||||||
|
|
||||||
With a decimal (base 10) input:
|
With a decimal (base 10) input:
|
|
@ -1,13 +1,21 @@
|
||||||
---
|
---
|
||||||
title: string
|
title: cast.ToString
|
||||||
|
linkTitle: string
|
||||||
description: Cast a value to a string.
|
description: Cast a value to a string.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [cast,strings]
|
function:
|
||||||
signature: ["string INPUT"]
|
aliases: [string]
|
||||||
relatedfuncs: []
|
returnType: string
|
||||||
|
signatures: [cast.ToString INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- cast.ToFloat
|
||||||
|
- cast.ToInt
|
||||||
|
- cast.ToString
|
||||||
|
aliases: [/functions/string]
|
||||||
---
|
---
|
||||||
|
|
||||||
With a decimal (base 10) input:
|
With a decimal (base 10) input:
|
|
@ -1,20 +0,0 @@
|
||||||
---
|
|
||||||
title: chomp
|
|
||||||
toc: true
|
|
||||||
description: Removes any trailing newline characters.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: [trim]
|
|
||||||
signature:
|
|
||||||
- "chomp INPUT"
|
|
||||||
- "strings.Chomp INPUT"
|
|
||||||
relatedfuncs: [truncate]
|
|
||||||
---
|
|
||||||
|
|
||||||
Useful in a pipeline to remove newlines added by other processing (e.g., [`markdownify`](/functions/markdownify/)).
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ chomp "<p>Blockhead</p>\n" }} → "<p>Blockhead</p>"
|
|
||||||
```
|
|
|
@ -1,16 +1,24 @@
|
||||||
---
|
---
|
||||||
title: after
|
title: collections.After
|
||||||
description: "`after` slices an array to only the items after the <em>N</em>th item."
|
linkTitle: after
|
||||||
|
description: Slices an array to the items after the Nth item.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [iteration]
|
function:
|
||||||
signature: ["after INDEX COLLECTION"]
|
aliases: [after]
|
||||||
relatedfuncs: [last,first,seq]
|
returnType: any
|
||||||
|
signatures: [collections.After INDEX COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.After
|
||||||
|
- collections.First
|
||||||
|
- collections.Last
|
||||||
|
aliases: [/functions/after]
|
||||||
---
|
---
|
||||||
|
|
||||||
The following shows `after` being used in conjunction with the [`slice` function][slice]:
|
The following shows `after` being used in conjunction with the [`slice`]function:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ $data := slice "one" "two" "three" "four" }}
|
{{ $data := slice "one" "two" "three" "four" }}
|
||||||
|
@ -22,7 +30,7 @@ The following shows `after` being used in conjunction with the [`slice` function
|
||||||
|
|
||||||
## Example of `after` with `first`: 2nd–4th most recent articles
|
## Example of `after` with `first`: 2nd–4th most recent articles
|
||||||
|
|
||||||
You can use `after` in combination with the [`first` function] and Hugo's [powerful sorting methods][lists]. Let's assume you have a list page at `example.com/articles`. You have 10 articles, but you want your templating for the [list/section page] to show only two rows:
|
You can use `after` in combination with the [`first`] function and Hugo's [powerful sorting methods][lists]. Let's assume you have a list page at `example.com/articles`. You have 10 articles, but you want your templating for the [list/section page] to show only two rows:
|
||||||
|
|
||||||
1. The top row is titled "Featured" and shows only the most recently published article (i.e. by `publishdate` in the content files' front matter).
|
1. The top row is titled "Featured" and shows only the most recently published article (i.e. by `publishdate` in the content files' front matter).
|
||||||
2. The second row is titled "Recent Articles" and shows only the 2nd- to 4th-most recently published articles.
|
2. The second row is titled "Recent Articles" and shows only the 2nd- to 4th-most recently published articles.
|
||||||
|
@ -52,7 +60,7 @@ You can use `after` in combination with the [`first` function] and Hugo's [power
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{< /code >}}
|
{{< /code >}}
|
||||||
|
|
||||||
[`first` function]: /functions/first/
|
[`first`]: /functions/collections/first
|
||||||
[list/section page]: /templates/section-templates/
|
[list/section page]: /templates/section-templates
|
||||||
[lists]: /templates/lists/#order-content
|
[lists]: /templates/lists/#order-content
|
||||||
[slice]: /functions/slice/
|
[`slice`]: /functions/collections/slice/
|
|
@ -1,13 +1,23 @@
|
||||||
---
|
---
|
||||||
title: append
|
title: collections.Append
|
||||||
|
linkTitle: append
|
||||||
description: Appends one or more elements to a slice and returns the resulting slice.
|
description: Appends one or more elements to a slice and returns the resulting slice.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections]
|
function:
|
||||||
signature: ["COLLECTION | append ELEMENT [ELEMENT]...", "COLLECTION | append COLLECTION"]
|
aliases: [append]
|
||||||
relatedfuncs: [last,first,where,slice]
|
returnType: any
|
||||||
|
signatures:
|
||||||
|
- COLLECTION | collections.Append ELEMENT [ELEMENT]...
|
||||||
|
- COLLECTION | collections.Append COLLECTION
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Append
|
||||||
|
- collections.Merge
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/append]
|
||||||
---
|
---
|
||||||
|
|
||||||
This function appends all elements, excluding the last, to the last element. This allows [pipe](/getting-started/glossary/#pipeline) constructs as shown below.
|
This function appends all elements, excluding the last, to the last element. This allows [pipe](/getting-started/glossary/#pipeline) constructs as shown below.
|
||||||
|
@ -81,8 +91,6 @@ To create a slice of slices, starting with an empty slice:
|
||||||
{{ $s }} → [[a b] [c d]]
|
{{ $s }} → [[a b] [c d]]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Although the elements in the examples above are strings, you can use the `append` function with any data type, including Pages. For example, on the home page of a corporate site, to display links to the two most recent press releases followed by links to the four most recent articles:
|
Although the elements in the examples above are strings, you can use the `append` function with any data type, including Pages. For example, on the home page of a corporate site, to display links to the two most recent press releases followed by links to the four most recent articles:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,19 +1,30 @@
|
||||||
---
|
---
|
||||||
title: apply
|
title: collections.Apply
|
||||||
|
linkTitle: apply
|
||||||
description: Given an array or slice, `apply` returns a new slice with a function applied over it.
|
description: Given an array or slice, `apply` returns a new slice with a function applied over it.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [advanced]
|
function:
|
||||||
signature: ["apply COLLECTION FUNCTION [PARAM...]"]
|
aliases: [apply]
|
||||||
relatedfuncs: []
|
returnType: any
|
||||||
|
signatures: ['collections.Apply COLLECTION FUNCTION [PARAM...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Apply
|
||||||
|
- collections.Delimit
|
||||||
|
- collections.In
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Seq
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/apply]
|
||||||
---
|
---
|
||||||
|
|
||||||
`apply` expects at least three arguments, depending on the function being applied.
|
`apply` expects at least three arguments, depending on the function being applied.
|
||||||
|
|
||||||
1. The first argument is the sequence to operate on.
|
1. The first argument is the sequence to operate on.
|
||||||
2. The second argument is the name of the function as a string, which must be the name of a valid [Hugo function][functions].
|
2. The second argument is the name of the function as a string, which must be the name of a valid [template function].
|
||||||
3. After that, the arguments to the applied function are provided, with the string `"."` standing in for each element of the sequence the function is to be applied against.
|
3. After that, the arguments to the applied function are provided, with the string `"."` standing in for each element of the sequence the function is to be applied against.
|
||||||
|
|
||||||
Here is an example of a content file with `names:` as a front matter field:
|
Here is an example of a content file with `names:` as a front matter field:
|
||||||
|
@ -35,13 +46,13 @@ Which will result in the following:
|
||||||
"derek-perkins", "joe-bergevin", "tanner-linsley"
|
"derek-perkins", "joe-bergevin", "tanner-linsley"
|
||||||
```
|
```
|
||||||
|
|
||||||
This is *roughly* equivalent to using the following with [range]:
|
This is *roughly* equivalent to using the following with [`range`]:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ range .Params.names }}{{ . | urlize }}{{ end }}
|
{{ range .Params.names }}{{ . | urlize }}{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
However, it is not possible to provide the output of a range to the [`delimit` function][delimit], so you need to `apply` it.
|
However, it is not possible to provide the output of a range to the [`delimit`]function, so you need to `apply` it.
|
||||||
|
|
||||||
If you have `post-tag-list.html` and `post-tag-link.html` as [partials], you *could* use the following snippets, respectively:
|
If you have `post-tag-list.html` and `post-tag-link.html` as [partials], you *could* use the following snippets, respectively:
|
||||||
|
|
||||||
|
@ -83,7 +94,7 @@ This first version of `layouts/partials/post-tag-list.html` separates all of the
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now in the completed version, you can sort the tags, convert the tags to links with `layouts/partials/post-tag-link.html`, [chomp] off stray newlines, and join the tags together in a delimited list for presentation. Here is an even DRYer version of the preceding example:
|
Now in the completed version, you can sort the tags, convert the tags to links with `layouts/partials/post-tag-link.html`, [`chomp`] stray newlines, and join the tags together in a delimited list for presentation. Here is an even DRYer version of the preceding example:
|
||||||
|
|
||||||
{{< code file="layouts/partials/post-tag-list.html" >}}
|
{{< code file="layouts/partials/post-tag-list.html" >}}
|
||||||
{{ with .Params.tags }}
|
{{ with .Params.tags }}
|
||||||
|
@ -98,8 +109,7 @@ Now in the completed version, you can sort the tags, convert the tags to links w
|
||||||
`apply` does not work when receiving the sequence as an argument through a pipeline.
|
`apply` does not work when receiving the sequence as an argument through a pipeline.
|
||||||
{{% /note %}}
|
{{% /note %}}
|
||||||
|
|
||||||
[chomp]: /functions/chomp/ "See documentation for the chomp function"
|
[`chomp`]: /functions/strings/chomp/
|
||||||
[delimit]: /functions/delimit/ "See documentation for the delimit function"
|
[`delimit`]: /functions/collections/delimit/
|
||||||
[functions]: /functions/ "See the full list of Hugo functions to see what can be passed as an argument to the apply function."
|
[template function]: /functions/
|
||||||
[partials]: /templates/partials/
|
[`range`]: /functions/go-template/range/
|
||||||
[range]: /functions/range/ "Learn the importance of the range function, a fundamental keyword in both Hugo templates and the Go programming language."
|
|
|
@ -1,15 +1,22 @@
|
||||||
---
|
---
|
||||||
title: complement
|
title: collections.Complement
|
||||||
|
linkTitle: complement
|
||||||
description: Returns the elements of the last collection that are not in any of the others.
|
description: Returns the elements of the last collection that are not in any of the others.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections]
|
function:
|
||||||
signature:
|
aliases: [complement]
|
||||||
- "complement COLLECTION [COLLECTION]..."
|
returnType: any
|
||||||
- "collections.Complement COLLECTION [COLLECTION]..."
|
signatures: ['collections.Complement COLLECTION [COLLECTION]...']
|
||||||
relatedfuncs: [intersect,symdiff,union]
|
relatedFunctions:
|
||||||
|
- collections.Complement
|
||||||
|
- collections.Intersect
|
||||||
|
- collections.SymDiff
|
||||||
|
- collections.Union
|
||||||
|
aliases: [/functions/complement]
|
||||||
---
|
---
|
||||||
|
|
||||||
To find the elements within `$c3` that do not exist in `$c1` or `$c2`:
|
To find the elements within `$c3` that do not exist in `$c1` or `$c2`:
|
||||||
|
@ -57,7 +64,7 @@ To list everything except blog articles (`blog`) and frequently asked questions
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
Although the example above demonstrates the `complement` function, you could use the [`where`] function as well:
|
Although the example above demonstrates the `complement` function, you could use the [`where`] function as well:
|
||||||
|
|
||||||
[`where`]: /functions/where/
|
[`where`]: /functions/collections/where
|
||||||
{{% /note %}}
|
{{% /note %}}
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,25 @@
|
||||||
---
|
---
|
||||||
title: delimit
|
title: collections.Delimit
|
||||||
|
linkTitle: delimit
|
||||||
description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
|
description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [iteration]
|
function:
|
||||||
signature: ["delimit COLLECTION DELIMITER [LAST]"]
|
aliases: [delimit]
|
||||||
relatedfuncs: []
|
returnType: template.HTML
|
||||||
|
signatures: ['collections.Delimit COLLECTION DELIMITER [LAST]']
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Apply
|
||||||
|
- collections.Delimit
|
||||||
|
- collections.In
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Seq
|
||||||
|
- collections.Slice
|
||||||
|
- strings.Split
|
||||||
|
aliases: [/functions/delimit]
|
||||||
---
|
---
|
||||||
|
|
||||||
Delimit a slice:
|
Delimit a slice:
|
|
@ -1,13 +1,23 @@
|
||||||
---
|
---
|
||||||
title: dict
|
title: collections.Dictionary
|
||||||
|
linkTitle: dict
|
||||||
description: Creates a map from a list of key and value pairs.
|
description: Creates a map from a list of key and value pairs.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections]
|
function:
|
||||||
signature: ["dict KEY VALUE [KEY VALUE]..."]
|
aliases: [dict]
|
||||||
relatedfuncs: []
|
returnType: mapany
|
||||||
|
signatures: ['collections.Dictionary KEY VALUE [KEY VALUE]...']
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Dictionary
|
||||||
|
- collections.Group
|
||||||
|
- collections.Index
|
||||||
|
- collections.IsSet
|
||||||
|
- collections.Where
|
||||||
|
aliases: [/functions/dict]
|
||||||
---
|
---
|
||||||
|
|
||||||
`dict` is especially useful for passing more than one value to a partial template.
|
`dict` is especially useful for passing more than one value to a partial template.
|
40
content/en/functions/collections/EchoParam.md
Normal file
40
content/en/functions/collections/EchoParam.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
---
|
||||||
|
title: collections.EchoParam
|
||||||
|
linkTitle: echoParam
|
||||||
|
description: Prints a parameter if it is set.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [echoParam]
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.EchoParam COLLECTION KEY]
|
||||||
|
relatedFunctions: []
|
||||||
|
aliases: [/functions/echoparam]
|
||||||
|
---
|
||||||
|
|
||||||
|
For example, consider this site configuration:
|
||||||
|
|
||||||
|
{{< code-toggle file=hugo copy=false >}}
|
||||||
|
[params.footer]
|
||||||
|
poweredBy = 'Hugo'
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
To print the value of `poweredBy`:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ echoParam site.Params.footer "poweredby" }} → Hugo
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
When using the `echoParam` function you must reference the key using lower case. See the previous example.
|
||||||
|
|
||||||
|
The `echoParam` function will be deprecated in a future release. Instead, use either of the constructs below.
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ site.Params.footer.poweredBy }} → Hugo
|
||||||
|
{{ index site.Params.footer "poweredBy" }} → Hugo
|
||||||
|
```
|
|
@ -1,13 +1,21 @@
|
||||||
---
|
---
|
||||||
title: first
|
title: collections.First
|
||||||
description: "Slices an array to only the first _N_ elements."
|
linkTitle: first
|
||||||
|
description: Slices an array to the first N elements.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [iteration]
|
function:
|
||||||
signature: ["first LIMIT COLLECTION"]
|
aliases: [first]
|
||||||
relatedfuncs: [after,last]
|
returnType: any
|
||||||
|
signatures: [collections.First LIMIT COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.After
|
||||||
|
- collections.First
|
||||||
|
- collections.Last
|
||||||
|
aliases: [/functions/first]
|
||||||
---
|
---
|
||||||
|
|
||||||
`first` works in a similar manner to the [`limit` keyword in
|
`first` works in a similar manner to the [`limit` keyword in
|
||||||
|
@ -28,9 +36,9 @@ elements. It takes the array and number of elements as input.
|
||||||
|
|
||||||
## `first` and `where` Together
|
## `first` and `where` Together
|
||||||
|
|
||||||
Using `first` and [`where`][wherefunction] together can be very
|
Using `first` and [`where`] together can be very
|
||||||
powerful. Below snippet gets a list of posts only from [**main
|
powerful. Below snippet gets a list of posts only from [main
|
||||||
sections**][mainsections], sorts it by the `title` parameter, and then
|
sections], sorts it by the `title` parameter, and then
|
||||||
ranges through only the first 5 posts in that list:
|
ranges through only the first 5 posts in that list:
|
||||||
|
|
||||||
{{< code file="first-and-where-together.html" >}}
|
{{< code file="first-and-where-together.html" >}}
|
||||||
|
@ -41,5 +49,5 @@ ranges through only the first 5 posts in that list:
|
||||||
|
|
||||||
|
|
||||||
[limitkeyword]: https://www.techonthenet.com/sql/select_limit.php
|
[limitkeyword]: https://www.techonthenet.com/sql/select_limit.php
|
||||||
[wherefunction]: /functions/where/
|
[`where`]: /functions/collections/where
|
||||||
[mainsections]: /functions/where/#mainsections
|
[main sections]: /functions/collections/where#mainsections
|
40
content/en/functions/collections/Group.md
Normal file
40
content/en/functions/collections/Group.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
---
|
||||||
|
title: collections.Group
|
||||||
|
linkTitle: group
|
||||||
|
description: Groups a list of pages.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [group]
|
||||||
|
returnType: any
|
||||||
|
signatures: [PAGES | collections.Group KEY]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Dictionary
|
||||||
|
- collections.Group
|
||||||
|
- collections.Index
|
||||||
|
- collections.IsSet
|
||||||
|
- collections.Where
|
||||||
|
aliases: [/functions/group]
|
||||||
|
---
|
||||||
|
|
||||||
|
{{< code file="layouts/partials/groups.html" >}}
|
||||||
|
{{ $new := .Site.RegularPages | first 10 | group "New" }}
|
||||||
|
{{ $old := .Site.RegularPages | last 10 | group "Old" }}
|
||||||
|
{{ $groups := slice $new $old }}
|
||||||
|
{{ range $groups }}
|
||||||
|
<h3>{{ .Key }}{{/* Prints "New", "Old" */}}</h3>
|
||||||
|
<ul>
|
||||||
|
{{ range .Pages }}
|
||||||
|
<li>
|
||||||
|
<a href="{{ .Permalink }}">{{ .Title }}</a>
|
||||||
|
<div class="meta">{{ .Date.Format "Mon, Jan 2, 2006" }}</div>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
{{ end }}
|
||||||
|
{{< /code >}}
|
||||||
|
|
||||||
|
The page group you get from `group` is of the same type you get from the built-in [group methods](/templates/lists#group-content) in Hugo. The above example can be [paginated](/templates/pagination/#list-paginator-pages).
|
38
content/en/functions/collections/In.md
Normal file
38
content/en/functions/collections/In.md
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
---
|
||||||
|
title: collections.In
|
||||||
|
linkTitle: in
|
||||||
|
description: Reports whether an element is in an array or slice, or if a substring is in a string.
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [in]
|
||||||
|
returnType: bool
|
||||||
|
signatures: [collections.In SET ITEM]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/in]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "a" "b" "c" }}
|
||||||
|
{{ in $s "b" }} → true
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice 1 2 3 }}
|
||||||
|
{{ in $s 2 }} → true
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice 1.11 2.22 3.33 }}
|
||||||
|
{{ in $s 2.22 }} → true
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := "abc" }}
|
||||||
|
{{ in $s "b" }} → true
|
||||||
|
```
|
|
@ -1,14 +1,26 @@
|
||||||
---
|
---
|
||||||
title: index
|
title: collections.Index
|
||||||
|
linkTitle: index
|
||||||
description: Looks up the index(es) or key(s) of the data structure passed into it.
|
description: Looks up the index(es) or key(s) of the data structure passed into it.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: []
|
function:
|
||||||
signature: ["index COLLECTION INDEXES", "index COLLECTION KEYS"]
|
aliases: [index]
|
||||||
relatedfuncs: []
|
returnType: any
|
||||||
aliases: [/functions/index/]
|
signatures:
|
||||||
|
- collections.Index COLLECTION INDEXES
|
||||||
|
- collections.Index COLLECTION KEYS
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Dictionary
|
||||||
|
- collections.EchoParam
|
||||||
|
- collections.Group
|
||||||
|
- collections.Index
|
||||||
|
- collections.IsSet
|
||||||
|
- collections.Where
|
||||||
|
aliases: [/functions/index,/functions/index-function]
|
||||||
---
|
---
|
||||||
|
|
||||||
The `index` functions returns the result of indexing its first argument by the following arguments. Each indexed item must be a map or a slice, e.g.:
|
The `index` functions returns the result of indexing its first argument by the following arguments. Each indexed item must be a map or a slice, e.g.:
|
|
@ -1,13 +1,22 @@
|
||||||
---
|
---
|
||||||
title: intersect
|
title: collections.Intersect
|
||||||
|
linkTitle: intersect
|
||||||
description: Returns the common elements of two arrays or slices, in the same order as the first array.
|
description: Returns the common elements of two arrays or slices, in the same order as the first array.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections,intersect,union,complement,symdiff]
|
function:
|
||||||
signature: ["intersect SET1 SET2"]
|
aliases: [intersect]
|
||||||
relatedfuncs: []
|
returnType: any
|
||||||
|
signatures: [collections.Intersect SET1 SET2]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Complement
|
||||||
|
- collections.Intersect
|
||||||
|
- collections.SymDiff
|
||||||
|
- collections.Union
|
||||||
|
aliases: [/functions/intersect]
|
||||||
---
|
---
|
||||||
A useful example is to use it as `AND` filters when combined with where:
|
A useful example is to use it as `AND` filters when combined with where:
|
||||||
|
|
||||||
|
@ -21,7 +30,7 @@ A useful example is to use it as `AND` filters when combined with where:
|
||||||
|
|
||||||
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
|
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
|
||||||
|
|
||||||
See [union](/functions/union) for `OR`.
|
See [union](/functions/collections/union) for `OR`.
|
||||||
|
|
||||||
|
|
||||||
[partials]: /templates/partials/
|
[partials]: /templates/partials/
|
52
content/en/functions/collections/IsSet.md
Normal file
52
content/en/functions/collections/IsSet.md
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
---
|
||||||
|
title: collections.IsSet
|
||||||
|
linkTitle: isset
|
||||||
|
description: Reports whether the key exists within the collection.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [isset]
|
||||||
|
returnType: bool
|
||||||
|
signatures: [collections.IsSet COLLECTION KEY]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Dictionary
|
||||||
|
- collections.Group
|
||||||
|
- collections.Index
|
||||||
|
- collections.IsSet
|
||||||
|
- collections.Where
|
||||||
|
aliases: [/functions/isset]
|
||||||
|
---
|
||||||
|
|
||||||
|
For example, consider this site configuration:
|
||||||
|
|
||||||
|
{{< code-toggle file=hugo copy=false >}}
|
||||||
|
[params]
|
||||||
|
showHeroImage = false
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
It the value of `showHeroImage` is `true`, we can detect that it exists using either `if` or `with`:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ if site.Params.showHeroImage }}
|
||||||
|
{{ site.Params.showHeroImage }} → true
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
{{ with site.Params.showHeroImage }}
|
||||||
|
{{ . }} → true
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
But if the value of `showHeroImage` is `false`, we can't use either `if` or `with` to detect its existence. In this case, you must use the `isset` function:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ if isset site.Params "showheroimage" }}
|
||||||
|
<p>The showHeroImage parameter is set to {{ site.Params.showHeroImage }}.<p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
When using the `isset` function you must reference the key using lower case. See the previous example.
|
||||||
|
{{% /note %}}
|
45
content/en/functions/collections/KeyVals.md
Normal file
45
content/en/functions/collections/KeyVals.md
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
---
|
||||||
|
title: collections.KeyVals
|
||||||
|
linkTitle: keyVals
|
||||||
|
description: Returns a KeyVals struct.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [keyVals]
|
||||||
|
returnType: KeyValues
|
||||||
|
signatures: [collections.KeyVals KEY VALUES...]
|
||||||
|
relatedFunctions: []
|
||||||
|
aliases: [/functions/keyvals]
|
||||||
|
---
|
||||||
|
|
||||||
|
The primary application for this function is the definition of the `namedSlices` parameter in the options map passed to the `.Related` method on the `Page` object.
|
||||||
|
|
||||||
|
See [related content](/content-management/related).
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $kv := keyVals "foo" "a" "b" "c" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting data structure is:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"Key": "foo",
|
||||||
|
"Values": [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To extract the key and values:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
|
||||||
|
{{ $kv.Key }} → foo
|
||||||
|
{{ $kv.Values }} → [a b c]
|
||||||
|
```
|
25
content/en/functions/collections/Last.md
Normal file
25
content/en/functions/collections/Last.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
title: collections.Last
|
||||||
|
linkTitle: last
|
||||||
|
description: Slices an array to the last N elements.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [last]
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.Last INDEX COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.After
|
||||||
|
- collections.First
|
||||||
|
- collections.Last
|
||||||
|
aliases: [/functions/last]
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ range last 10 .Pages }}
|
||||||
|
{{ .Render "summary" }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
|
@ -1,13 +1,20 @@
|
||||||
---
|
---
|
||||||
title: merge
|
title: collections.Merge
|
||||||
description: "Returns the result of merging two or more maps."
|
linkTitle: merge
|
||||||
|
description: Returns the result of merging two or more maps.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections]
|
function:
|
||||||
signature: ["collections.Merge MAP MAP...", "merge MAP MAP..."]
|
aliases: [merge]
|
||||||
relatedfuncs: [dict, append, reflect.IsMap, reflect.IsSlice]
|
returnType: any
|
||||||
|
signatures: [collections.Merge MAP MAP...]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Append
|
||||||
|
- collections.Merge
|
||||||
|
aliases: [/functions/merge]
|
||||||
---
|
---
|
||||||
|
|
||||||
Returns the result of merging two or more maps from left to right. If a key already exists, `merge` updates its value. If a key is absent, `merge` inserts the value under the new key.
|
Returns the result of merging two or more maps from left to right. If a key already exists, `merge` updates its value. If a key is absent, `merge` inserts the value under the new key.
|
||||||
|
@ -63,5 +70,5 @@ Example 4
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
Regardless of depth, merging only applies to maps. For slices, use [append](/functions/append).
|
Regardless of depth, merging only applies to maps. For slices, use [append](/functions/collections/append).
|
||||||
{{% /note %}}
|
{{% /note %}}
|
22
content/en/functions/collections/NewScratch.md
Normal file
22
content/en/functions/collections/NewScratch.md
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
title: collections.NewScratch
|
||||||
|
linkTitle: newScratch
|
||||||
|
description: Creates a new Scratch which can be used to store values in a thread safe way.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [newScratch]
|
||||||
|
returnType: Scratch
|
||||||
|
signatures: [collections.NewScratch ]
|
||||||
|
relatedFunctions: []
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $scratch := newScratch }}
|
||||||
|
{{ $scratch.Add "b" 2 }}
|
||||||
|
{{ $scratch.Add "b" 2 }}
|
||||||
|
{{ $scratch.Get "b" }} → 4
|
||||||
|
```
|
|
@ -1,13 +1,22 @@
|
||||||
---
|
---
|
||||||
title: querify
|
title: collections.Querify
|
||||||
|
linkTitle: querify
|
||||||
description: Takes a set or slice of key-value pairs and returns a query string to be appended to URLs.
|
description: Takes a set or slice of key-value pairs and returns a query string to be appended to URLs.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [urls]
|
function:
|
||||||
signature: ["querify KEY VALUE [KEY VALUE]...", "querify COLLECTION"]
|
aliases: [querify]
|
||||||
relatedfuncs: []
|
returnType: string
|
||||||
|
signatures:
|
||||||
|
- collections.Querify KEY VALUE [KEY VALUE]...
|
||||||
|
- collections.Querify COLLECTION
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Querify
|
||||||
|
- urlquery
|
||||||
|
aliases: [/functions/querify]
|
||||||
---
|
---
|
||||||
|
|
||||||
`querify` takes a set or slice of key-value pairs and returns a [query string](https://en.wikipedia.org/wiki/Query_string) that can be appended to a URL.
|
`querify` takes a set or slice of key-value pairs and returns a [query string](https://en.wikipedia.org/wiki/Query_string) that can be appended to a URL.
|
26
content/en/functions/collections/Reverse.md
Normal file
26
content/en/functions/collections/Reverse.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
---
|
||||||
|
title: collections.Reverse
|
||||||
|
description: Reverses the order of a collection.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.Reverse COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Apply
|
||||||
|
- collections.Delimit
|
||||||
|
- collections.In
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Seq
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/collections.reverse]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ slice 2 1 3 | collections.Reverse }} → [3 1 2]
|
||||||
|
```
|
|
@ -1,13 +1,27 @@
|
||||||
---
|
---
|
||||||
title: seq
|
title: collections.Seq
|
||||||
|
linkTitle: seq
|
||||||
description: Returns a slice of integers.
|
description: Returns a slice of integers.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: []
|
function:
|
||||||
signature: ["seq LAST", "seq FIRST LAST", "seq FIRST INCREMENT LAST"]
|
aliases: [seq]
|
||||||
relatedfuncs: []
|
returnType: '[]int'
|
||||||
|
signatures:
|
||||||
|
- collections.Seq LAST
|
||||||
|
- collections.Seq FIRST LAST
|
||||||
|
- collections.Seq FIRST INCREMENT LAST
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Apply
|
||||||
|
- collections.Delimit
|
||||||
|
- collections.In
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Seq
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/seq]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,16 +1,25 @@
|
||||||
---
|
---
|
||||||
title: shuffle
|
title: collections.Shuffle
|
||||||
|
linkTitle: shuffle
|
||||||
description: Returns a random permutation of a given array or slice.
|
description: Returns a random permutation of a given array or slice.
|
||||||
keywords: [ordering]
|
keywords: [ordering]
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
signature: ["shuffle COLLECTION"]
|
function:
|
||||||
relatedfuncs: [seq]
|
aliases: [shuffle]
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.Shuffle COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Shuffle
|
||||||
|
- collections.Sort
|
||||||
|
- collections.Uniq
|
||||||
|
aliases: [/functions/shuffle]
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ shuffle (seq 1 2 3) }} → [3 1 2]
|
{{ shuffle (seq 1 2 3) }} → [3 1 2]
|
||||||
{{ shuffle (slice "a" "b" "c") }} → [b a c]
|
{{ shuffle (slice "a" "b" "c") }} → [b a c]
|
30
content/en/functions/collections/Slice.md
Normal file
30
content/en/functions/collections/Slice.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
---
|
||||||
|
title: collections.Slice
|
||||||
|
linkTitle: slice
|
||||||
|
description: Creates a slice (array) of all passed arguments.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [slice]
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.Slice ITEM...]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Append
|
||||||
|
- collections.Apply
|
||||||
|
- collections.Delimit
|
||||||
|
- collections.In
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Seq
|
||||||
|
- collections.Slice
|
||||||
|
aliases: [/functions/slice]
|
||||||
|
---
|
||||||
|
|
||||||
|
One use case is the concatenation of elements in combination with the [`delimit` function]:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "a" "b" "c" }}
|
||||||
|
{{ $s }} → [a b c]
|
||||||
|
```
|
|
@ -1,13 +1,22 @@
|
||||||
---
|
---
|
||||||
title: sort
|
title: collections.Sort
|
||||||
|
linkTitle: sort
|
||||||
description: Sorts slices, maps, and page collections.
|
description: Sorts slices, maps, and page collections.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
signature: ["sort COLLECTION [KEY] [ORDER]"]
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [ordering,sorting,lists]
|
function:
|
||||||
toc: true
|
aliases: [sort]
|
||||||
|
returnType: any
|
||||||
|
signatures: ['collections.Sort COLLECTION [KEY] [ORDER]']
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Shuffle
|
||||||
|
- collections.Sort
|
||||||
|
- collections.Uniq
|
||||||
|
aliases: [/functions/sort]
|
||||||
---
|
---
|
||||||
|
|
||||||
The `KEY` is optional when sorting slices in ascending order, otherwise it is required. When sorting slices, use the literal `value` in place of the `KEY`. See examples below.
|
The `KEY` is optional when sorting slices in ascending order, otherwise it is required. When sorting slices, use the literal `value` in place of the `KEY`. See examples below.
|
28
content/en/functions/collections/SymDiff.md
Normal file
28
content/en/functions/collections/SymDiff.md
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
title: collections.SymDiff
|
||||||
|
linkTitle: symdiff
|
||||||
|
description: Returns the symmetric difference of two collections.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [symdiff]
|
||||||
|
returnType: any
|
||||||
|
signatures: [COLLECTION | collections.SymDiff COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Complement
|
||||||
|
- collections.Intersect
|
||||||
|
- collections.SymDiff
|
||||||
|
- collections.Union
|
||||||
|
aliases: [/functions/symdiff]
|
||||||
|
---
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ slice 1 2 3 | symdiff (slice 3 4) }} → [1 2 4]
|
||||||
|
```
|
||||||
|
|
||||||
|
Also see https://en.wikipedia.org/wiki/Symmetric_difference
|
|
@ -1,13 +1,22 @@
|
||||||
---
|
---
|
||||||
title: union
|
title: collections.Union
|
||||||
|
linkTitle: union
|
||||||
description: Given two arrays or slices, returns a new array that contains the elements or objects that belong to either or both arrays/slices.
|
description: Given two arrays or slices, returns a new array that contains the elements or objects that belong to either or both arrays/slices.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [collections,intersect,union,complement]
|
function:
|
||||||
signature: ["union SET1 SET2"]
|
aliases: [union]
|
||||||
relatedfuncs: [intersect,where]
|
returnType: any
|
||||||
|
signatures: [collections.Union SET1 SET2]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Complement
|
||||||
|
- collections.Intersect
|
||||||
|
- collections.SymDiff
|
||||||
|
- collections.Union
|
||||||
|
aliases: [/functions/union]
|
||||||
---
|
---
|
||||||
|
|
||||||
Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both. The elements supported are strings, integers, and floats (only float64).
|
Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both. The elements supported are strings, integers, and floats (only float64).
|
||||||
|
@ -38,4 +47,4 @@ This is also very useful to use as `OR` filters when combined with where:
|
||||||
|
|
||||||
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
|
The above fetches regular pages not of `page` or `about` type unless they are pinned. And finally, we exclude all pages with no `images` set in Page parameters.
|
||||||
|
|
||||||
See [intersect](/functions/intersect) for `AND`.
|
See [intersect](/functions/collections/intersect) for `AND`.
|
25
content/en/functions/collections/Uniq.md
Normal file
25
content/en/functions/collections/Uniq.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
title: collections.Uniq
|
||||||
|
linkTitle: uniq
|
||||||
|
description: Takes in a slice or array and returns a slice with duplicate elements removed.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [uniq]
|
||||||
|
returnType: any
|
||||||
|
signatures: [collections.Uniq COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Reverse
|
||||||
|
- collections.Shuffle
|
||||||
|
- collections.Sort
|
||||||
|
- collections.Uniq
|
||||||
|
aliases: [/functions/uniq]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ slice 1 3 2 1 | uniq }} → [1 3 2]
|
||||||
|
```
|
|
@ -1,13 +1,23 @@
|
||||||
---
|
---
|
||||||
title: where
|
title: collections.Where
|
||||||
|
linkTitle: where
|
||||||
description: Filters an array to only the elements containing a matching value for a given field.
|
description: Filters an array to only the elements containing a matching value for a given field.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [filtering]
|
function:
|
||||||
signature: ["where COLLECTION KEY [OPERATOR] MATCH"]
|
aliases: [where]
|
||||||
relatedfuncs: [intersect,first,after,last]
|
returnType: any
|
||||||
|
signatures: ['collections.Where COLLECTION KEY [OPERATOR] MATCH']
|
||||||
|
relatedFunctions:
|
||||||
|
- collections.Dictionary
|
||||||
|
- collections.Group
|
||||||
|
- collections.Index
|
||||||
|
- collections.IsSet
|
||||||
|
- collections.Where
|
||||||
|
aliases: [/functions/where]
|
||||||
toc: true
|
toc: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -114,7 +124,7 @@ This example matches pages where the "foo" parameter begins with "ab":
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% readfile file="/functions/common/regular-expressions.md" %}}
|
{{% readfile file="/functions/_common/regular-expressions.md" %}}
|
||||||
|
|
||||||
## Use `where` with `first`
|
## Use `where` with `first`
|
||||||
|
|
||||||
|
@ -176,5 +186,5 @@ The user can override the default:
|
||||||
mainSections = ["blog", "docs"]
|
mainSections = ["blog", "docs"]
|
||||||
{{< /code-toggle >}}
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
[intersect]: /functions/intersect/
|
[intersect]: /functions/collections/intersect
|
||||||
[wherekeyword]: https://www.techonthenet.com/sql/where.php
|
[wherekeyword]: https://www.techonthenet.com/sql/where.php
|
|
@ -1,13 +1,20 @@
|
||||||
---
|
---
|
||||||
title: cond
|
title: compare.Conditional
|
||||||
|
linkTitle: cond
|
||||||
description: Returns one of two arguments depending on the value of the control argument.
|
description: Returns one of two arguments depending on the value of the control argument.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
keywords: [conditional, ternary]
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
signature: [cond CONTROL ARG1 ARG2]
|
function:
|
||||||
relatedfuncs: [default]
|
aliases: [cond]
|
||||||
|
returnType: any
|
||||||
|
signatures: [compare.Conditional CONTROL ARG1 ARG2]
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Conditional
|
||||||
|
- compare.Default
|
||||||
|
aliases: [/functions/cond]
|
||||||
---
|
---
|
||||||
|
|
||||||
The CONTROL argument is a boolean value that indicates whether the function should return ARG1 or ARG2. If CONTROL is `true`, the function returns ARG1. Otherwise, the function returns ARG2.
|
The CONTROL argument is a boolean value that indicates whether the function should return ARG1 or ARG2. If CONTROL is `true`, the function returns ARG1. Otherwise, the function returns ARG2.
|
|
@ -1,15 +1,20 @@
|
||||||
---
|
---
|
||||||
title: default
|
title: compare.Default
|
||||||
|
linkTitle: default
|
||||||
description: Allows setting a default value that can be returned if a first value is not set.
|
description: Allows setting a default value that can be returned if a first value is not set.
|
||||||
qref: "Returns a default value if a value is not set when checked."
|
|
||||||
keywords: [defaults]
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
toc:
|
function:
|
||||||
signature: ["default DEFAULT INPUT"]
|
aliases: [default]
|
||||||
relatedfuncs: []
|
returnType: any
|
||||||
|
signatures: [compare.Default DEFAULT INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Conditional
|
||||||
|
- compare.Default
|
||||||
|
aliases: [/functions/default]
|
||||||
---
|
---
|
||||||
|
|
||||||
`default` checks whether a given value is set and returns a default value if it is not. *Set* in this context means different things depending on the data type:
|
`default` checks whether a given value is set and returns a default value if it is not. *Set* in this context means different things depending on the data type:
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: eq
|
title: compare.Eq
|
||||||
|
linkTitle: eq
|
||||||
description: Returns the boolean truth of arg1 == arg2 || arg1 == arg3.
|
description: Returns the boolean truth of arg1 == arg2 || arg1 == arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["eq ARG1 ARG2 [ARG...]"]
|
aliases: [eq]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Eq ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/eq]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: ge
|
title: compare.Ge
|
||||||
|
linkTitle: ge
|
||||||
description: Returns the boolean truth of arg1 >= arg2 && arg1 >= arg3.
|
description: Returns the boolean truth of arg1 >= arg2 && arg1 >= arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["ge ARG1 ARG2 [ARG...]"]
|
aliases: [ge]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Ge ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/ge]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: gt
|
title: compare.Gt
|
||||||
|
linkTitle: gt
|
||||||
description: Returns the boolean truth of arg1 > arg2 && arg1 > arg3.
|
description: Returns the boolean truth of arg1 > arg2 && arg1 > arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["gt ARG1 ARG2 [ARG...]"]
|
aliases: [gt]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Gt ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/gt]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: le
|
title: compare.Le
|
||||||
|
linkTitle: le
|
||||||
description: Returns the boolean truth of arg1 <= arg2 && arg1 <= arg3.
|
description: Returns the boolean truth of arg1 <= arg2 && arg1 <= arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["le ARG1 ARG2 [ARG...]"]
|
aliases: [le]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Le ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/le]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: lt
|
title: compare.Lt
|
||||||
|
linkTitle: lt
|
||||||
description: Returns the boolean truth of arg1 < arg2 && arg1 < arg3.
|
description: Returns the boolean truth of arg1 < arg2 && arg1 < arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["lt ARG1 ARG2 [ARG...]"]
|
aliases: [lt]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Lt ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/lt]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,13 +1,24 @@
|
||||||
---
|
---
|
||||||
title: ne
|
title: compare.Ne
|
||||||
|
linkTitle: ne
|
||||||
description: Returns the boolean truth of arg1 != arg2 && arg1 != arg3.
|
description: Returns the boolean truth of arg1 != arg2 && arg1 != arg3.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [comparison,operators,logic]
|
function:
|
||||||
signature: ["ne ARG1 ARG2 [ARG...]"]
|
aliases: [ne]
|
||||||
relatedfuncs: []
|
returnType: bool
|
||||||
|
signatures: ['compare.Ne ARG1 ARG2 [ARG...]']
|
||||||
|
relatedFunctions:
|
||||||
|
- compare.Eq
|
||||||
|
- compare.Ge
|
||||||
|
- compare.Gt
|
||||||
|
- compare.Le
|
||||||
|
- compare.Lt
|
||||||
|
- compare.Ne
|
||||||
|
aliases: [/functions/ne]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
|
@ -1,22 +0,0 @@
|
||||||
---
|
|
||||||
title: countrunes
|
|
||||||
description: Determines the number of runes in a string excluding any whitespace.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: [counting, word count]
|
|
||||||
signature:
|
|
||||||
- "countrunes INPUT"
|
|
||||||
- "strings.CountRunes INPUT"
|
|
||||||
relatedfuncs: []
|
|
||||||
---
|
|
||||||
|
|
||||||
In contrast with `countwords` function, which counts every word in a string, the `countrunes` function determines the number of runes in the content and excludes any whitespace. This has specific utility if you are dealing with CJK-like languages.
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ "Hello, 世界" | countrunes }}
|
|
||||||
<!-- outputs a content length of 8 runes. -->
|
|
||||||
```
|
|
||||||
|
|
||||||
[pagevars]: /variables/page/
|
|
|
@ -2,13 +2,25 @@
|
||||||
title: crypto.FNV32a
|
title: crypto.FNV32a
|
||||||
description: Returns the FNV (Fowler–Noll–Vo) 32 bit hash of a given string.
|
description: Returns the FNV (Fowler–Noll–Vo) 32 bit hash of a given string.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [crypto hash FNV32 Fowler-Noll-Vo]
|
function:
|
||||||
signature: ["crypto.FNV32a STRING"]
|
aliases: []
|
||||||
|
returnType: int
|
||||||
|
signatures: [crypto.FNV32a STRING]
|
||||||
|
relatedFunctions:
|
||||||
|
- crypto.FNV32a
|
||||||
|
- crypto.HMAC
|
||||||
|
- crypto.MD5
|
||||||
|
- crypto.SHA1
|
||||||
|
- crypto.SHA256
|
||||||
|
aliases: [/functions/crypto.fnv32a]
|
||||||
---
|
---
|
||||||
|
|
||||||
This function calculates the 32 bit [FNV1a hash](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) of a given string according to the [specification](https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-12):
|
This function calculates the 32 bit [FNV1a hash](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) of a given string according to the [specification](https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-12):
|
||||||
|
|
||||||
{{ crypto.FNV32a "Hello world" }} → 1498229191
|
```go-html-template
|
||||||
|
{{ crypto.FNV32a "Hello world" }} → 1498229191
|
||||||
|
```
|
|
@ -1,13 +1,23 @@
|
||||||
---
|
---
|
||||||
title: hmac
|
title: crypto.HMAC
|
||||||
|
linkTitle: hmac
|
||||||
description: Returns a cryptographic hash that uses a key to sign a message.
|
description: Returns a cryptographic hash that uses a key to sign a message.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [hmac,checksum]
|
function:
|
||||||
signature: ["crypto.HMAC HASH_TYPE KEY MESSAGE [ENCODING]","hmac HASH_TYPE KEY MESSAGE [ENCODING]" ]
|
aliases: [hmac]
|
||||||
relatedfuncs: [hmac]
|
returnType: string
|
||||||
|
signatures: ['crypto.HMAC HASH_TYPE KEY MESSAGE [ENCODING]']
|
||||||
|
relatedFunctions:
|
||||||
|
- crypto.FNV32a
|
||||||
|
- crypto.HMAC
|
||||||
|
- crypto.MD5
|
||||||
|
- crypto.SHA1
|
||||||
|
- crypto.SHA256
|
||||||
|
aliases: [/functions/hmac]
|
||||||
---
|
---
|
||||||
|
|
||||||
Set the `HASH_TYPE` argument to `md5`, `sha1`, `sha256`, or `sha512`.
|
Set the `HASH_TYPE` argument to `md5`, `sha1`, `sha256`, or `sha512`.
|
|
@ -1,18 +1,28 @@
|
||||||
---
|
---
|
||||||
title: md5
|
title: crypto.MD5
|
||||||
|
linkTitle: md5
|
||||||
description: hashes the given input and returns its MD5 checksum.
|
description: hashes the given input and returns its MD5 checksum.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: []
|
function:
|
||||||
signature: ["md5 INPUT"]
|
aliases: [md5]
|
||||||
relatedfuncs: [sha]
|
returnType: string
|
||||||
|
signatures: [crypto.MD5 INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- crypto.FNV32a
|
||||||
|
- crypto.HMAC
|
||||||
|
- crypto.MD5
|
||||||
|
- crypto.SHA1
|
||||||
|
- crypto.SHA256
|
||||||
|
aliases: [/functions/md5]
|
||||||
---
|
---
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ md5 "Hello world, gophers!" }}
|
{{ md5 "Hello world" }} → 3e25960a79dbc69b674cd4ec67a72c62
|
||||||
<!-- returns the string "b3029f756f98f79e7f1b7f1d1f0dd53b" -->
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This can be useful if you want to use [Gravatar](https://en.gravatar.com/) for generating a unique avatar:
|
This can be useful if you want to use [Gravatar](https://en.gravatar.com/) for generating a unique avatar:
|
25
content/en/functions/crypto/SHA1.md
Normal file
25
content/en/functions/crypto/SHA1.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
title: crypto.SHA1
|
||||||
|
linkTitle: sha1
|
||||||
|
description: Hashes the given input and returns its SHA1 checksum.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [sha1]
|
||||||
|
returnType: string
|
||||||
|
signatures: [crypto.SHA1 INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- crypto.FNV32a
|
||||||
|
- crypto.HMAC
|
||||||
|
- crypto.MD5
|
||||||
|
- crypto.SHA1
|
||||||
|
- crypto.SHA256
|
||||||
|
aliases: [/functions/sha,/functions/sha1]
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ sha1 "Hello world" }} → 7b502c3a1f48c8609ae212cdfb639dee39673f5e
|
||||||
|
```
|
25
content/en/functions/crypto/SHA256.md
Normal file
25
content/en/functions/crypto/SHA256.md
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
title: crypto.SHA256
|
||||||
|
linkTitle: sha256
|
||||||
|
description: Hashes the given input and returns its SHA256 checksum.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [sha256]
|
||||||
|
returnType: string
|
||||||
|
signatures: [crypto.SHA256 INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- crypto.FNV32a
|
||||||
|
- crypto.HMAC
|
||||||
|
- crypto.MD5
|
||||||
|
- crypto.SHA1
|
||||||
|
- crypto.SHA256
|
||||||
|
aliases: [/functions/sha256]
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ sha256 "Hello world" }} → 64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c
|
||||||
|
```
|
117
content/en/functions/data/GetCSV.md
Normal file
117
content/en/functions/data/GetCSV.md
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
---
|
||||||
|
title: data.GetCSV
|
||||||
|
linkTitle: getCSV
|
||||||
|
description: Returns an array of arrays from a local or remote CSV file, or an error if the file does not exist.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [getCSV]
|
||||||
|
returnType: '[]string'
|
||||||
|
signatures: [data.GetCSV SEPARATOR PATHPART...]
|
||||||
|
relatedFunctions:
|
||||||
|
- data.GetCSV
|
||||||
|
- data.GetJSON
|
||||||
|
toc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Given the following directory structure:
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── other-files/
|
||||||
|
└── pets.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
Access the data with either of the following:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := getCSV "," "other-files/pets.csv" }}
|
||||||
|
{{ $data := getCSV "," "other-files/" "pets.csv" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Access remote data with either of the following:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := getCSV "," "https://example.org/pets.csv" }}
|
||||||
|
{{ $data := getCSV "," "https://example.org/" "pets.csv" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting data structure is an array of arrays:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
["name","type","breed","age"],
|
||||||
|
["Spot","dog","Collie","3"],
|
||||||
|
["Felix","cat","Malicious","7"]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Global resource alternative
|
||||||
|
|
||||||
|
Consider using `resources.Get` with [`transform.Unmarshal`] when accessing a global resource.
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── assets/
|
||||||
|
└── data/
|
||||||
|
└── pets.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $p := "data/pets.csv" }}
|
||||||
|
{{ with resources.Get $p }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get resource %q" $p }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Page resource alternative
|
||||||
|
|
||||||
|
Consider using `.Resources.Get` with [`transform.Unmarshal`] when accessing a page resource.
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── content/
|
||||||
|
└── posts/
|
||||||
|
└── my-pets/
|
||||||
|
├── index.md
|
||||||
|
└── pets.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $p := "pets.csv" }}
|
||||||
|
{{ with .Resources.Get $p }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get resource %q" $p }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Remote resource alternative
|
||||||
|
|
||||||
|
Consider using `resources.GetRemote` with [`transform.Unmarshal`] for improved error handling when accessing a remote resource.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $u := "https://example.org/pets.csv" }}
|
||||||
|
{{ with resources.GetRemote $u }}
|
||||||
|
{{ with .Err }}
|
||||||
|
{{ errorf "%s" . }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get remote resource %q" $u }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
[`transform.Unmarshal`]: /functions/transform/unmarshal
|
124
content/en/functions/data/GetJSON.md
Normal file
124
content/en/functions/data/GetJSON.md
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
---
|
||||||
|
title: data.GetJSON
|
||||||
|
linkTitle: getJSON
|
||||||
|
description: Returns a JSON object from a local or remote JSON file, or an error if the file does not exist.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [getJSON]
|
||||||
|
returnType: any
|
||||||
|
signatures: [data.GetJSON PATHPART...]
|
||||||
|
relatedFunctions:
|
||||||
|
- data.GetCSV
|
||||||
|
- data.GetJSON
|
||||||
|
toc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Given the following directory structure:
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── other-files/
|
||||||
|
└── books.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Access the data with either of the following:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := getCSV "," "other-files/books.json" }}
|
||||||
|
{{ $data := getCSV "," "other-files/" "books.json" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Access remote data with either of the following:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := getCSV "," "https://example.org/books.json" }}
|
||||||
|
{{ $data := getCSV "," "https://example.org/" "books.json" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting data structure is a JSON object:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"author": "Victor Hugo",
|
||||||
|
"rating": 5,
|
||||||
|
"title": "Les Misérables"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"author": "Victor Hugo",
|
||||||
|
"rating": 4,
|
||||||
|
"title": "The Hunchback of Notre Dame"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Global resource alternative
|
||||||
|
|
||||||
|
Consider using `resources.Get` with [`transform.Unmarshal`] when accessing a global resource.
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── assets/
|
||||||
|
└── data/
|
||||||
|
└── books.json
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $p := "data/books.json" }}
|
||||||
|
{{ with resources.Get $p }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get resource %q" $p }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Page resource alternative
|
||||||
|
|
||||||
|
Consider using `.Resources.Get` with [`transform.Unmarshal`] when accessing a page resource.
|
||||||
|
|
||||||
|
```text
|
||||||
|
my-project/
|
||||||
|
└── content/
|
||||||
|
└── posts/
|
||||||
|
└── reading-list/
|
||||||
|
├── books.json
|
||||||
|
└── index.md
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $p := "books.json" }}
|
||||||
|
{{ with .Resources.Get $p }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get resource %q" $p }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Remote resource alternative
|
||||||
|
|
||||||
|
Consider using `resources.GetRemote` with [`transform.Unmarshal`] for improved error handling when accessing a remote resource.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $u := "https://example.org/books.json" }}
|
||||||
|
{{ with resources.GetRemote $u }}
|
||||||
|
{{ with .Err }}
|
||||||
|
{{ errorf "%s" . }}
|
||||||
|
{{ else }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get remote resource %q" $u }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
[`transform.Unmarshal`]: /functions/transform/unmarshal
|
|
@ -1,49 +0,0 @@
|
||||||
---
|
|
||||||
title: time.Format
|
|
||||||
description: Converts a date/time to a localized string.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: [dates,time,strings]
|
|
||||||
signature:
|
|
||||||
- "time.Format LAYOUT INPUT"
|
|
||||||
- "dateFormat LAYOUT INPUT"
|
|
||||||
relatedfuncs: [Format,now,Unix,time]
|
|
||||||
---
|
|
||||||
|
|
||||||
`time.Format` (alias `dateFormat`) converts either a `time.Time` object (e.g. `.Date`) or a timestamp string `INPUT` into the format specified by the `LAYOUT` string.
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"
|
|
||||||
```
|
|
||||||
|
|
||||||
`time.Format` returns a localized string for the current language.
|
|
||||||
|
|
||||||
The `LAYOUT` string can be either:
|
|
||||||
|
|
||||||
* [Go’s Layout String](/functions/format/#gos-layout-string) to learn about how the `LAYOUT` string has to be formatted. There are also some useful examples.
|
|
||||||
* A custom Hugo layout identifier (see full list below)
|
|
||||||
|
|
||||||
See the [`time` function](/functions/time/) to convert a timestamp string to a Go `time.Time` type value.
|
|
||||||
|
|
||||||
|
|
||||||
## Date/time formatting layouts
|
|
||||||
|
|
||||||
Go's date layout strings can be hard to reason about, especially with multiple languages. You can alternatively use some predefined layout identifiers that will output localized dates or times:
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ .Date | time.Format ":date_long" }}
|
|
||||||
```
|
|
||||||
|
|
||||||
The full list of custom layouts with examples for English:
|
|
||||||
|
|
||||||
* `:date_full` => `Wednesday, June 6, 2018`
|
|
||||||
* `:date_long` => `June 6, 2018`
|
|
||||||
* `:date_medium` => `Jun 6, 2018`
|
|
||||||
* `:date_short` => `6/6/18`
|
|
||||||
|
|
||||||
* `:time_full` => `2:09:37 am UTC`
|
|
||||||
* `:time_long` => `2:09:37 am UTC`
|
|
||||||
* `:time_medium` => `2:09:37 am`
|
|
||||||
* `:time_short` => `2:09 am`
|
|
50
content/en/functions/debug/Dump.md
Normal file
50
content/en/functions/debug/Dump.md
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
---
|
||||||
|
title: debug.Dump
|
||||||
|
description: Returns an object dump as a string.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType: string
|
||||||
|
signatures: [debug.Dump VALUE]
|
||||||
|
relatedFunctions: []
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $data := "" }}
|
||||||
|
{{ $p := "data/books.json" }}
|
||||||
|
{{ with resources.Get $p }}
|
||||||
|
{{ $opts := dict "delimiter" "," }}
|
||||||
|
{{ $data = . | transform.Unmarshal $opts }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get resource %q" $p }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
<pre>{{ debug.Dump $data }}</pre>
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
[]interface {}{
|
||||||
|
map[string]interface {}{
|
||||||
|
"author": "Victor Hugo",
|
||||||
|
"rating": 5.0,
|
||||||
|
"title": "Les Misérables",
|
||||||
|
},
|
||||||
|
map[string]interface {}{
|
||||||
|
"author": "Victor Hugo",
|
||||||
|
"rating": 4.0,
|
||||||
|
"title": "The Hunchback of Notre Dame",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
Output from this function may change from one release to the next. Use for debugging only.
|
||||||
|
{{% /note %}}
|
|
@ -1,16 +0,0 @@
|
||||||
---
|
|
||||||
title: echoParam
|
|
||||||
description: Prints a parameter if it is set.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: []
|
|
||||||
signature: ["echoParam MAP KEY"]
|
|
||||||
relatedfuncs: []
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ echoParam .Params "project_url" }}
|
|
||||||
```
|
|
45
content/en/functions/encoding/Base64Decode.md
Normal file
45
content/en/functions/encoding/Base64Decode.md
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
---
|
||||||
|
title: encoding.Base64Decode
|
||||||
|
linkTitle: base64Decode
|
||||||
|
description: Returns the base64 decoding of the given content.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [base64Decode]
|
||||||
|
returnType: string
|
||||||
|
signatures: [encoding.Base64Decode INPUT]
|
||||||
|
signatures:
|
||||||
|
-
|
||||||
|
- base64Decode INPUT
|
||||||
|
aliases: [/functions/base64Decode]
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ "SHVnbw==" | base64Decode }} → "Hugo"
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the `base64Decode` function to decode responses from APIs. For example, the result of this call to GitHub's API contains the base64-encoded representation of the repository's README file:
|
||||||
|
|
||||||
|
```text
|
||||||
|
https://api.github.com/repos/gohugoio/hugo/readme
|
||||||
|
```
|
||||||
|
|
||||||
|
To retrieve and render the content:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $u := "https://api.github.com/repos/gohugoio/hugo/readme" }}
|
||||||
|
{{ with resources.GetRemote $u }}
|
||||||
|
{{ with .Err }}
|
||||||
|
{{ errorf "%s" . }}
|
||||||
|
{{ else }}
|
||||||
|
{{ with . | transform.Unmarshal }}
|
||||||
|
{{ .content | base64Decode | markdownify }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
{{ else }}
|
||||||
|
{{ errorf "Unable to get remote resource %q" $u }}
|
||||||
|
{{ end }}
|
||||||
|
```
|
22
content/en/functions/encoding/Base64Encode.md
Normal file
22
content/en/functions/encoding/Base64Encode.md
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
title: encoding.Base64Encode
|
||||||
|
linkTitle: base64Encode
|
||||||
|
description: Returns the base64 decoding of the given content.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [base64Encode]
|
||||||
|
returnType: string
|
||||||
|
signatures: [encoding.Base64Encode INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- encoding.Base64Decode
|
||||||
|
- encoding.Base64Encode
|
||||||
|
aliases: [/functions/base64, /functions/base64Encode]
|
||||||
|
---
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ "Hugo" | base64Encode }} → "SHVnbw=="
|
||||||
|
```
|
|
@ -1,13 +1,23 @@
|
||||||
---
|
---
|
||||||
title: jsonify
|
title: encoding.Jsonify
|
||||||
|
linkTitle: jsonify
|
||||||
description: Encodes a given object to JSON.
|
description: Encodes a given object to JSON.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [strings,json]
|
function:
|
||||||
signature: ["jsonify INPUT", "jsonify OPTIONS INPUT"]
|
aliases: [jsonify]
|
||||||
relatedfuncs: [plainify]
|
returnType: template.HTML
|
||||||
|
signatures:
|
||||||
|
- encoding.Jsonify INPUT
|
||||||
|
- encoding.Jsonify OPTIONS INPUT
|
||||||
|
relatedFunctions:
|
||||||
|
- encoding.Jsonify
|
||||||
|
- transform.Remarshal
|
||||||
|
- transform.Unmarshal
|
||||||
|
aliases: [/functions/jsonify]
|
||||||
---
|
---
|
||||||
|
|
||||||
To customize the printing of the JSON, pass a map of options as the first
|
To customize the printing of the JSON, pass a map of options as the first
|
||||||
|
@ -22,7 +32,7 @@ more copies of *indent* according to the indentation nesting.
|
||||||
{{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }}
|
{{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Jsonify options
|
## Options
|
||||||
|
|
||||||
indent ("")
|
indent ("")
|
||||||
: Indentation to use.
|
: Indentation to use.
|
|
@ -1,45 +0,0 @@
|
||||||
---
|
|
||||||
title: errorf and warnf
|
|
||||||
description: Log ERROR or WARNING from the templates.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: [strings, log, error]
|
|
||||||
signature: ["errorf FORMAT INPUT"]
|
|
||||||
relatedfuncs: [printf]
|
|
||||||
---
|
|
||||||
|
|
||||||
`errorf` or `warnf` will evaluate a format string, then output the result to the ERROR or WARNING log (and only once per error message to avoid flooding the log).
|
|
||||||
|
|
||||||
Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`).
|
|
||||||
|
|
||||||
Both functions return an empty string, so the messages are only printed to the console.
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ errorf "Failed to handle page %q" .Path }}
|
|
||||||
```
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ warnf "You should update the shortcodes in %q" .Path }}
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that `errorf`, `erroridf`, and `warnf` support all the formatting verbs of the [fmt](https://pkg.go.dev/fmt) package.
|
|
||||||
|
|
||||||
## Suppress errors
|
|
||||||
|
|
||||||
Sometimes it may make sense to let the user suppress an ERROR and make the build succeed.
|
|
||||||
|
|
||||||
You can do this by using the `erroridf` function. This functions takes an error ID as the first argument.
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ erroridf "my-custom-error" "You should consider fixing this." }}
|
|
||||||
```
|
|
||||||
|
|
||||||
This will produce:
|
|
||||||
|
|
||||||
```
|
|
||||||
ERROR 2021/06/07 17:47:38 You should consider fixing this.
|
|
||||||
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site configuration:
|
|
||||||
ignoreErrors = ["my-custom-error"]
|
|
||||||
```
|
|
33
content/en/functions/fmt/Errorf.md
Normal file
33
content/en/functions/fmt/Errorf.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
title: fmt.Errorf
|
||||||
|
linkTitle: errorf
|
||||||
|
description: Log an ERROR from a template.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [errorf]
|
||||||
|
returnType: string
|
||||||
|
signatures: ['fmt.Errorf FORMAT [INPUT]']
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Errorf
|
||||||
|
- fmt.Erroridf
|
||||||
|
- fmt.Warnf
|
||||||
|
aliases: [/functions/errorf]
|
||||||
|
---
|
||||||
|
|
||||||
|
The documentation for [Go's fmt package] describes the structure and content of the format string.
|
||||||
|
|
||||||
|
Like the [`printf`] function, the `errorf` function evaluates the format string. It then prints the result to the ERROR log and fails the build. Hugo prints each unique message once to avoid flooding the log with duplicate errors.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ errorf "The %q shortcode requires a src parameter. See %s" .Name .Position }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the [`erroridf`] function to allow optional suppression of specific errors.
|
||||||
|
|
||||||
|
[`erroridf`]: /functions/fmt/erroridf
|
||||||
|
[`printf`]: /functions/fmt/printf
|
||||||
|
[Go's fmt package]: https://pkg.go.dev/fmt
|
48
content/en/functions/fmt/Erroridf.md
Normal file
48
content/en/functions/fmt/Erroridf.md
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
---
|
||||||
|
title: fmt.Erroridf
|
||||||
|
linkTitle: erroridf
|
||||||
|
description: Log a suppressable ERROR from a template.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [erroridf]
|
||||||
|
returnType: string
|
||||||
|
signatures: ['fmt.Erroridf ID FORMAT [INPUT]']
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Errorf
|
||||||
|
- fmt.Erroridf
|
||||||
|
- fmt.Warnf
|
||||||
|
aliases: [/functions/erroridf]
|
||||||
|
---
|
||||||
|
|
||||||
|
The documentation for [Go's fmt package] describes the structure and content of the format string.
|
||||||
|
|
||||||
|
Like the [`errorf`] function, the `erroridf` function evaluates the format string, prints the result to the ERROR log, then fails the build. Hugo prints each unique message once to avoid flooding the log with duplicate errors.
|
||||||
|
|
||||||
|
Unlike the `errorf` function, you may suppress errors logged by the `erroridf` function by adding the message ID to the `ignoreErrors` array in your site configuration.
|
||||||
|
|
||||||
|
This template code:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ erroridf "error-42" "You should consider fixing this." }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Produces this console log:
|
||||||
|
|
||||||
|
```text
|
||||||
|
ERROR You should consider fixing this.
|
||||||
|
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
|
||||||
|
ignoreErrors = ["error-42"]
|
||||||
|
```
|
||||||
|
|
||||||
|
To suppress this message:
|
||||||
|
|
||||||
|
{{< code-toggle file=hugo copy=false >}}
|
||||||
|
ignoreErrors = ["error-42"]
|
||||||
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
[`errorf`]: /functions/fmt/errorf
|
||||||
|
[Go's fmt package]: https://pkg.go.dev/fmt
|
|
@ -1,17 +1,23 @@
|
||||||
---
|
---
|
||||||
title: print
|
title: fmt.Print
|
||||||
|
linkTitle: print
|
||||||
description: Prints the default representation of the given arguments using the standard `fmt.Print` function.
|
description: Prints the default representation of the given arguments using the standard `fmt.Print` function.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [strings]
|
function:
|
||||||
signature: ["print INPUT"]
|
aliases: [print]
|
||||||
relatedfuncs: []
|
returnType: string
|
||||||
|
signatures: [fmt.Print INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Print
|
||||||
|
- fmt.Printf
|
||||||
|
- fmt.Println
|
||||||
|
aliases: [/functions/print]
|
||||||
---
|
---
|
||||||
|
|
||||||
See [the go doc](https://golang.org/pkg/fmt/) for additional information.
|
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ print "foo" }} → "foo"
|
{{ print "foo" }} → "foo"
|
||||||
{{ print "foo" "bar" }} → "foobar"
|
{{ print "foo" "bar" }} → "foobar"
|
46
content/en/functions/fmt/Printf.md
Normal file
46
content/en/functions/fmt/Printf.md
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
---
|
||||||
|
title: fmt.Printf
|
||||||
|
linkTitle: printf
|
||||||
|
description: Formats a string using the standard `fmt.Sprintf` function.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [printf]
|
||||||
|
returnType: string
|
||||||
|
signatures: ['fmt.Printf FORMAT [INPUT]']
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Print
|
||||||
|
- fmt.Printf
|
||||||
|
- fmt.Println
|
||||||
|
aliases: [/functions/printf]
|
||||||
|
---
|
||||||
|
|
||||||
|
The documentation for [Go's fmt package] describes the structure and content of the format string.
|
||||||
|
|
||||||
|
[Go's fmt package]: https://pkg.go.dev/fmt
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $var := "world" }}
|
||||||
|
{{ printf "Hello %s." $var }} → Hello world.
|
||||||
|
```
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $pi := 3.14159265 }}
|
||||||
|
{{ printf "Pi is approximately %.2f." $pi }} → 3.14
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the `printf` function with the `safeHTMLAttr` function:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $desc := "Eat at Joe's" }}
|
||||||
|
<meta name="description" {{ printf "content=%q" $desc | safeHTMLAttr }}>
|
||||||
|
```
|
||||||
|
|
||||||
|
Hugo renders this to:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<meta name="description" content="Eat at Joe's">
|
||||||
|
```
|
|
@ -1,17 +1,23 @@
|
||||||
---
|
---
|
||||||
title: println
|
title: fmt.Println
|
||||||
|
linkTitle: println
|
||||||
description: Prints the default representation of the given argument using the standard `fmt.Print` function and enforces a linebreak.
|
description: Prints the default representation of the given argument using the standard `fmt.Print` function and enforces a linebreak.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [strings]
|
function:
|
||||||
signature: ["println INPUT"]
|
aliases: [println]
|
||||||
relatedfuncs: []
|
returnType: string
|
||||||
|
signatures: [fmt.Println INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Print
|
||||||
|
- fmt.Printf
|
||||||
|
- fmt.Println
|
||||||
|
aliases: [/functions/println]
|
||||||
---
|
---
|
||||||
|
|
||||||
See [the go doc](https://golang.org/pkg/fmt/) for additional information. `\n` denotes the linebreak but isn't printed in the templates as seen below:
|
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ println "foo" }} → "foo\n"
|
{{ println "foo" }} → "foo\n"
|
||||||
```
|
```
|
30
content/en/functions/fmt/Warnf.md
Normal file
30
content/en/functions/fmt/Warnf.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
---
|
||||||
|
title: fmt.Warnf
|
||||||
|
linkTitle: warnf
|
||||||
|
description: Log a WARNING from a template.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: [warnf]
|
||||||
|
returnType: string
|
||||||
|
signatures: ['fmt.Warnf FORMAT [INPUT]']
|
||||||
|
relatedFunctions:
|
||||||
|
- fmt.Errorf
|
||||||
|
- fmt.Erroridf
|
||||||
|
- fmt.Warnf
|
||||||
|
aliases: [/functions/warnf]
|
||||||
|
---
|
||||||
|
|
||||||
|
The documentation for [Go's fmt package] describes the structure and content of the format string.
|
||||||
|
|
||||||
|
Like the [`printf`] function, the `warnf` function evaluates the format string. It then prints the result to the WARNING log. Hugo prints each unique message once to avoid flooding the log with duplicate warnings.
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ warnf "Copyright notice missing from site configuration" }}
|
||||||
|
```
|
||||||
|
|
||||||
|
[`printf`]: /functions/fmt/printf
|
||||||
|
[Go's fmt package]: https://pkg.go.dev/fmt
|
|
@ -1,119 +0,0 @@
|
||||||
---
|
|
||||||
title: .Format
|
|
||||||
description: Formats built-in Hugo dates---`.Date`, `.PublishDate`, and `.Lastmod`---according to Go's layout string.
|
|
||||||
categories: [functions]
|
|
||||||
menu:
|
|
||||||
docs:
|
|
||||||
parent: functions
|
|
||||||
keywords: [dates,time]
|
|
||||||
signature: [".Format FORMAT"]
|
|
||||||
relatedfuncs: [dateFormat,now,Unix,time]
|
|
||||||
toc: true
|
|
||||||
---
|
|
||||||
|
|
||||||
`.Format` will format date values defined in your front matter and can be used as a property on the following [page variables][pagevars]:
|
|
||||||
|
|
||||||
* `.PublishDate`
|
|
||||||
* `.Date`
|
|
||||||
* `.Lastmod`
|
|
||||||
|
|
||||||
Assuming a key-value of `date: 2017-03-03` in a content file's front matter, your can run the date through `.Format` followed by a layout string for your desired output at build time:
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ .PublishDate.Format "January 2, 2006" }} => March 3, 2017
|
|
||||||
```
|
|
||||||
|
|
||||||
For formatting *any* string representations of dates defined in your front matter, see the [`dateFormat` function][dateFormat], which will still leverage the Go layout string explained below but uses a slightly different syntax.
|
|
||||||
|
|
||||||
## Go's layout string
|
|
||||||
|
|
||||||
Hugo templates [format your dates][time] via layout strings that point to a specific reference time:
|
|
||||||
|
|
||||||
```
|
|
||||||
Mon Jan 2 15:04:05 MST 2006
|
|
||||||
```
|
|
||||||
|
|
||||||
While this may seem arbitrary, the numerical value of `MST` is `07`, thus making the layout string a sequence of numbers.
|
|
||||||
|
|
||||||
Here is a visual explanation [taken directly from the Go docs][gdex]:
|
|
||||||
|
|
||||||
```
|
|
||||||
Jan 2 15:04:05 2006 MST
|
|
||||||
=> 1 2 3 4 5 6 -7
|
|
||||||
```
|
|
||||||
|
|
||||||
### Hugo date and time templating reference
|
|
||||||
|
|
||||||
The following examples show the layout string followed by the rendered output.
|
|
||||||
|
|
||||||
The examples were rendered and tested in [CST] and all point to the same field in a content file's front matter:
|
|
||||||
|
|
||||||
```
|
|
||||||
date: 2017-03-03T14:15:59-06:00
|
|
||||||
```
|
|
||||||
|
|
||||||
`.Date` (i.e. called via [page variable][pagevars])
|
|
||||||
: **Returns**: `2017-03-03 14:15:59 -0600 CST`
|
|
||||||
|
|
||||||
`"Monday, January 2, 2006"`
|
|
||||||
: **Returns**: `Friday, March 3, 2017`
|
|
||||||
|
|
||||||
`"Mon Jan 2 2006"`
|
|
||||||
: **Returns**: `Fri Mar 3 2017`
|
|
||||||
|
|
||||||
`"January 2006"`
|
|
||||||
: **Returns**: `March 2017`
|
|
||||||
|
|
||||||
`"2006-01-02"`
|
|
||||||
: **Returns**: `2017-03-03`
|
|
||||||
|
|
||||||
`"Monday"`
|
|
||||||
: **Returns**: `Friday`
|
|
||||||
|
|
||||||
`"02 Jan 06 15:04 MST"` (RFC822)
|
|
||||||
: **Returns**: `03 Mar 17 14:15 CST`
|
|
||||||
|
|
||||||
`"02 Jan 06 15:04 -0700"` (RFC822Z)
|
|
||||||
: **Returns**: `03 Mar 17 14:15 -0600`
|
|
||||||
|
|
||||||
`"Mon, 02 Jan 2006 15:04:05 MST"` (RFC1123)
|
|
||||||
: **Returns**: `Fri, 03 Mar 2017 14:15:59 CST`
|
|
||||||
|
|
||||||
`"Mon, 02 Jan 2006 15:04:05 -0700"` (RFC1123Z)
|
|
||||||
: **Returns**: `Fri, 03 Mar 2017 14:15:59 -0600`
|
|
||||||
|
|
||||||
More examples can be found in Go's [documentation for the time package][timeconst].
|
|
||||||
|
|
||||||
### Cardinal s
|
|
||||||
|
|
||||||
Spelled-out cardinal numbers (e.g. "one", "two", and "three") are not currently supported.
|
|
||||||
|
|
||||||
Use the [`humanize`](/functions/humanize) function to render the day of the month as an ordinal number:
|
|
||||||
|
|
||||||
```go-html-template
|
|
||||||
{{ humanize .Date.Day }} of {{ .Date.Format "January 2006" }}
|
|
||||||
```
|
|
||||||
|
|
||||||
This will output:
|
|
||||||
|
|
||||||
```
|
|
||||||
5th of March 2017
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Use `.Local` and `.UTC`
|
|
||||||
|
|
||||||
In conjunction with the [`dateFormat` function][dateFormat], you can also convert your dates to `UTC` or to local timezones:
|
|
||||||
|
|
||||||
`{{ dateFormat "02 Jan 06 15:04 MST" .Date.UTC }}`
|
|
||||||
: **Returns**: `03 Mar 17 20:15 UTC`
|
|
||||||
|
|
||||||
`{{ dateFormat "02 Jan 06 15:04 MST" .Date.Local }}`
|
|
||||||
: **Returns**: `03 Mar 17 14:15 CST`
|
|
||||||
|
|
||||||
[CST]: https://en.wikipedia.org/wiki/Central_Time_Zone
|
|
||||||
[dateFormat]: /functions/dateformat/
|
|
||||||
[gdex]: https://golang.org/pkg/time/#example_Time_Format
|
|
||||||
[pagevars]: /variables/page/
|
|
||||||
[time]: https://golang.org/pkg/time/
|
|
||||||
[timeconst]: https://golang.org/pkg/time/#ANSIC
|
|
|
@ -2,14 +2,25 @@
|
||||||
title: len
|
title: len
|
||||||
description: Returns the length of a string, slice, map, or collection.
|
description: Returns the length of a string, slice, map, or collection.
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
menu:
|
menu:
|
||||||
docs:
|
docs:
|
||||||
parent: functions
|
parent: functions
|
||||||
keywords: [length]
|
function:
|
||||||
signature: ["len INPUT"]
|
aliases: []
|
||||||
relatedfuncs: []
|
returnType: int
|
||||||
|
signatures: [len INPUT]
|
||||||
|
relatedFunctions:
|
||||||
|
- len
|
||||||
|
- strings.Count
|
||||||
|
- strings.CountRunes
|
||||||
|
- strings.CountWords
|
||||||
|
- strings.RuneCount
|
||||||
|
aliases: [/functions/len]
|
||||||
---
|
---
|
||||||
|
|
||||||
|
{{% readfile file="/functions/_common/go-template-functions.md" %}}
|
||||||
|
|
||||||
With a string:
|
With a string:
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
159
content/en/functions/go-template/range.md
Normal file
159
content/en/functions/go-template/range.md
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
---
|
||||||
|
title: range
|
||||||
|
description: Iterates over slices, maps, and page collections.
|
||||||
|
categories: [functions]
|
||||||
|
keywords: []
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
function:
|
||||||
|
aliases: []
|
||||||
|
returnType:
|
||||||
|
signatures: [range COLLECTION]
|
||||||
|
relatedFunctions:
|
||||||
|
- with
|
||||||
|
- range
|
||||||
|
aliases: [/functions/range]
|
||||||
|
toc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
{{% readfile file="/functions/_common/go-template-functions.md" %}}
|
||||||
|
|
||||||
|
## Slices
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "foo" "bar" "baz" }}
|
||||||
|
{{ range $s }}
|
||||||
|
<p>{{ . }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>foo</p>
|
||||||
|
<p>bar</p>
|
||||||
|
<p>baz</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "foo" "bar" "baz" }}
|
||||||
|
{{ range $v := $s }}
|
||||||
|
<p>{{ $v }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>foo</p>
|
||||||
|
<p>bar</p>
|
||||||
|
<p>baz</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "foo" "bar" "baz" }}
|
||||||
|
{{ range $k, $v := $s }}
|
||||||
|
<p>{{ $k }}: {{ $v }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>0: foo</p>
|
||||||
|
<p>1: bar</p>
|
||||||
|
<p>2: baz</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Maps
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $m := slice
|
||||||
|
(dict "name" "John" "age" 30)
|
||||||
|
(dict "name" "Will" "age" 28)
|
||||||
|
(dict "name" "Joey" "age" 24)
|
||||||
|
}}
|
||||||
|
{{ range $m }}
|
||||||
|
<p>{{ .name }} is {{ .age }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>John is 30</p>
|
||||||
|
<p>Will is 28</p>
|
||||||
|
<p>Joey is 24</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Page collections
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ range where site.RegularPages "Type" "articles" }}
|
||||||
|
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<h2><a href="/articles/article-3/">Article 3</a></h2>
|
||||||
|
<h2><a href="/articles/article-2/">Article 2</a></h2>
|
||||||
|
<h2><a href="/articles/article-1/">Article 1</a></h2>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Break
|
||||||
|
|
||||||
|
Use the `break` statement to stop the innermost iteration and bypass all remaining iterations.
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "foo" "bar" "baz" }}
|
||||||
|
{{ range $s }}
|
||||||
|
{{ if eq . "bar" }}
|
||||||
|
{{ break }}
|
||||||
|
{{ end }}
|
||||||
|
<p>{{ . }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>foo</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Continue
|
||||||
|
|
||||||
|
Use the `continue` statement to stop the innermost iteration and continue to the next iteration.
|
||||||
|
|
||||||
|
Template:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $s := slice "foo" "bar" "baz" }}
|
||||||
|
{{ range $s }}
|
||||||
|
{{ if eq . "bar" }}
|
||||||
|
{{ continue }}
|
||||||
|
{{ end }}
|
||||||
|
<p>{{ . }}</p>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>foo</p>
|
||||||
|
<p>baz</p>
|
||||||
|
```
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue