diff --git a/content/functions/adddate.md b/content/functions/adddate.md index 8ac00c111..ebc4389c8 100644 --- a/content/functions/adddate.md +++ b/content/functions/adddate.md @@ -14,7 +14,42 @@ hugoversion: relatedfuncs: [now] deprecated: false aliases: [] +needsexamples: true --- - +The `AddDate` function takes three arguments in logical order of `years`, `months`, and `days`. + +## Example `AddDate`: Randomized Tweets from the Last 2 Years + +Let's assume you have a filed at `data/tweets.toml` that contains a long list of Tweets you've been collecting to display on your site's homepage. This file is filled with hundreds of `[[tweet]]` blocks; e.g.--- + +```toml +[[tweet]] +name = "Steve Francia" +twitter_handle = "@spf13" +quote = "I am the creator of Hugo. #metadocreference" +link = "https://twitter.com/spf13" +date = "2017-01-07T00:00:00Z" +``` + +Let's assume you want to grab Tweets from the last two years and present them in a random order. In conjunction with the [`where`](functions/where/) and [`now`](/functions/now/) functions, we can limit our range to the last two years via `now.AddDate -2 0 0`, which represents a point in time 2 years, 0 days, and 0 hours before the time of your last site build. + +{{% code file="partials/templates/random-tweets.html" download="tweets.html" %}} +```html + {{ range where $.Site.Data.tweets.tweet "date" "ge" (now.AddDate -2 0 0) | shuffle }} +
+
+

+ {{ .quote | safeHTML }} +

+ — {{ .name }} ({{ .twitter_handle }}) + {{ dateFormat "January 2, 2006" .date }} + +
+
+ {{ end }} +``` +{{% /code %}} + + \ No newline at end of file diff --git a/content/functions/delimit.md b/content/functions/delimit.md index 0572cc005..9493e4d66 100644 --- a/content/functions/delimit.md +++ b/content/functions/delimit.md @@ -30,7 +30,7 @@ aliases: [] To maintain a consistent output order, maps will be sorted by keys and only a slice of the values will be returned. -Examples of `delimit` use the following front matter: +The examples of `delimit` that follow all use the same front matter: {{% code file="delimit-example-front-matter.toml" nocopy="true" %}} ```toml @@ -41,8 +41,6 @@ tags: [ "tag1", "tag2", "tag3" ] ``` {{% /code %}} - - {{% code file="delimit-page-tags-input.html" %}} ```html

Tags: {{ delimit .Params.tags ", " }}

diff --git a/content/templates/base.md b/content/templates/base.md index 9520b4d8e..79e2755f1 100644 --- a/content/templates/base.md +++ b/content/templates/base.md @@ -99,7 +99,7 @@ Code that you put outside the block definitions *can* break your layout. This ev ...your code here {{ end }} ``` -[See this thread from the discussion forums](https://discuss.gohugo.io/t/baseof-html-block-templates-and-list-types-results-in-empty-pages/5612/6) +[See this thread from the Hugo discussion forums.](https://discuss.gohugo.io/t/baseof-html-block-templates-and-list-types-results-in-empty-pages/5612/6) {{% /warning %}} The following shows how you can override both the `"main"` and `"title"` block areas from the base template with code unique to your [default single page template][singletemplate]: