Commit graph

20 commits

Author SHA1 Message Date
Bjørn Erik Pedersen 2b8d907ab7 Add a newScratch template func
Fixes #4685
2018-07-06 17:51:38 +02:00
Bjørn Erik Pedersen f8212d2000
tpl/collections: Return en empty slice in after instead of error
When the given index is out of bounds. So it can safely be used with `with` etc. without extra length checking.

Fixes #4894
2018-07-01 20:34:02 +02:00
liguoqinjim 83c761b71a tpl/collections: Seed random on init only 2018-01-27 18:51:12 +01:00
Cameron Moore 47fdfd5196 Clean up lint in various packages
Changes fall into one of the following:

- gofmt -s
- receiver name is inconsistent
- omit unused 2nd value from range
- godoc comment formed incorrectly
- err assigned and not used
- if block ends with a return statement followed by else
2017-09-29 16:23:16 +02:00
Bjørn Erik Pedersen 3b4f17bbc9 hugolib: Implement "related content"
This closes #98, even if this commit does not do full content text search.

We may revisit that problem in the future, but that deserves its own issue.

Fixes #98
2017-09-06 00:20:02 +02:00
Bjørn Erik Pedersen dbbc5c4810 tpl/collections: Fix union when the first slice is empty
Fixes #3686
2017-07-08 10:31:09 +02:00
Bjørn Erik Pedersen ccdd08d57a tpl/collections: Add Pages support to Intersect and Union
This enables `AND` (`intersect`)  and `OR` (`union`)  filters when combined with `where`.

Example:

```go
{{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }}
{{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }}
{{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}
```

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 params.

Fixes #3174
2017-07-03 21:48:03 +02:00
Bjørn Erik Pedersen d12cf5a25d tpl/collections: Fix In function for JSON arrays
Fixes #1468
2017-07-03 10:23:03 +02:00
Bjørn Erik Pedersen 873a6f1885 Run gofmt to get imports in line vs gohugoio/hugo 2017-06-13 19:12:10 +02:00
Bjørn Erik Pedersen d8717cd4c7 all: Update import paths to gohugoio/hugo 2017-06-13 18:42:45 +02:00
Cameron Moore b82cd82f11 tpl/collections: Add uint support to In 2017-06-08 21:01:15 +02:00
Cameron Moore 204c3a9e32 tpl/collections: Support interfaces in union
Fixes #3411
2017-06-08 21:01:15 +02:00
Nathan Sharfi e28d9aa42c tpl: Add uniq function 2017-06-03 19:13:58 +02:00
Bjørn Erik Pedersen 93c5774dd7 tpl/collections: Make IsSet WARNING less chatty
Updates #3092
2017-05-19 21:14:37 +03:00
Cameron Moore 58d4c25e50 tpl/collections: Use Feedback log instead of Error in IsSet
Using the Error log will cause Hugo to exit with an error, which could
break site build workflows.
2017-05-18 21:54:42 +03:00
Cameron Moore 38661c17bb tpl/collections: Log an error on unsupported types in IsSet
Unsupported types are currently silently ignored by IsSet.  An earlier
attempt was made to solve the issue by returning an error.  That attempt
was reverted since it broke some existing themes.

So instead, we'll log an error.  Hopefully, people will stop using IsSet
in this way, and we can eventually return an error outright.

Updates #3092
2017-05-18 21:54:42 +03:00
Cameron Moore f1c29b017b tpl/collections: Add support for interfaces to intersect
Fixes #1952
2017-05-18 10:13:44 +03:00
Bjørn Erik Pedersen 0e2260421e tpl: Fix the remaining template funcs namespace issues
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 8a49c0b3b8 tpl/collections: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Cameron Moore de7c32a1a8 tpl: Add template function namespaces
This commit moves almost all of the template functions into separate
packages under tpl/ and adds a namespace framework.  All changes should
be backward compatible for end users, as all existing function names in
the template funcMap are left intact.

Seq and DoArithmatic have been moved out of the helpers package and into
template namespaces.

Most of the tests involved have been refactored, and many new tests have
been written.  There's still work to do, but this is a big improvement.

I got a little overzealous and added some new functions along the way:

- strings.Contains
- strings.ContainsAny
- strings.HasSuffix
- strings.TrimPrefix
- strings.TrimSuffix

Documentation is forthcoming.

Fixes #3042
2017-04-30 10:56:38 +02:00