Commit graph

490 commits

Author SHA1 Message Date
Cameron Moore b4a14c25fe metrics: Add simple template metrics feature 2017-09-26 20:03:04 +02:00
Cameron Moore 8a69d23567 tpl: Add math.Ceil, Floor, and Round to method mappings 2017-09-26 08:16:24 +02:00
Bjørn Erik Pedersen fb33d8286d Use Chroma as new default syntax highlighter
If you want to use Pygments, set `pygmentsUseClassic=true` in your site config.

Fixes #3888
2017-09-25 08:59:02 +02:00
Cameron Moore 81ed564793 tpl: Add urls.Parse function
Add a urls.Parse template function that front-ends url.Parse from the Go
stdlib.

Fixes #3849
2017-09-24 10:07:35 +02:00
Cameron Moore 19c5910485 tpl: Add math.Ceil, Floor, and Round
Ceil and Floor are frontends for the stdlib math functions. The Round
implementation is essentially the same thing except that the Go stdlib
doesn't include a Round implementation in a stable release yet.  I've
included the Round function slated for Go 1.10.

Fixes #3883
2017-09-24 10:06:14 +02:00
Bjørn Erik Pedersen 0d29a0f781 Trim newlines in the hightlight shortcode
Fixes #3898
2017-09-23 18:14:07 +02:00
Bjørn Erik Pedersen c31e083ead Fix the docs helper tool 2017-09-23 10:20:11 +02:00
Bjørn Erik Pedersen 2d613dd905 tpl/tplimpl: Fix escaped HTML Go 1.9 multioutput issue (#3880)
Fixes #3876
2017-09-13 12:32:06 +02:00
Bjørn Erik Pedersen f4bf214137 tpl/time: Add time.Duration and time.ParseDuration template funcs
And with time.Duration with the convenient alias `duration`:

```
{{ mul 60 60 | duration "second" }}
```

Fixes #3828
2017-09-09 09:43:00 +02:00
Bjørn Erik Pedersen 0462c96a5a tpl/compare: Add cond (ternary) template func
Fixes #3860
2017-09-08 16:59:43 +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
oneleaftea 88e1bca92c Update template_embedded.go
Changed disqus urls from http to https. This fixes mixed content warnings on browsers when viewing Hugo websites over SSL (https).
2017-08-22 20:26:04 +02:00
Bjørn Erik Pedersen d000cf6050 tpl: Prepare for template metrics 2017-08-19 09:57:37 +02:00
Cameron Moore 29a2da0593 tpl: Cleanup strings.TrimPrefix and TrimSuffix
These funcs were added during the move to namespaces but were
undocumented.  This commit fixes the order of the arguments and adds the
funcs to the method mapping.
2017-08-18 14:21:58 +02:00
Cameron Moore 7674ad7382 tpl: Add strings.TrimLeft and TrimRight 2017-08-18 09:12:04 +02:00
Bjørn Erik Pedersen 08f48b91d6 compare, hugolib, tpl: Add Eqer interface
And use it in `eq` and `ne` so `Page` values can be compared directly in the templates without thinking about it being a `Page` or a `PageOutput` wrapper.

Fixes #3807
2017-08-18 07:36:32 +02:00
Nic Raboy 919bc9210a Add an iFrame title to the YouTube shortcode
To accommodate modern web accessibility as outlined here https://dequeuniversity.com/tips/provide-iframe-titles
2017-08-12 00:36:40 +02:00
Bjørn Erik Pedersen 33ae10b6ad tpl/transform: Only strip p tag in markdownify if only one paragraph
Fixes #3040
2017-08-10 19:52:41 +02:00
Bjørn Erik Pedersen 46ac745374 all: Fix spelling
And some other minor issues.
2017-08-07 20:19:24 +02:00
Bjørn Erik Pedersen 4b54fb0701 all: gofmt -s 2017-08-07 20:03:15 +02:00
Jorin Vogel 81c13171a9 Add some missing doc comments
As pointed out by the linter, some exported functions and types are
missing doc comments.
The linter warnings have been reduced from 194 to 116.
Not all missing comments have been added in this commit though.
2017-08-03 15:57:51 +02:00
Jorin Vogel 09907d36af Switch from fork bep/inflect to markbates/inflect
Original package has received updates the fork hasn't.
Without fork updates are easier to maintain.
2017-08-01 13:05:09 +02:00
Bjørn Erik Pedersen 8fb594bfb0 Make the title case style guide configurable
This works for the `title` func and the other places where Hugo makes title case.

* AP style (new default)
* Chicago style
* Go style (what we have today)

Fixes #989
2017-07-31 22:16:46 +02:00
Anthony Fok 555a9bc806 tpl: Accommodate gccgo in TestMethodToName
Fixes #3744
2017-07-28 08:03:15 +02:00
Cameron Moore 55d0b89417 tpl/collections: Fix intersect on []interface{} handling
Fixes #3718
2017-07-28 07:21:21 +02:00
Jake Howard 6cd33f6953 tpl: Use hash for cache key
Use a hash for the cache key, to fix 'file name too long' errors when retreiving from long urls

Fixes #3690
2017-07-21 13:10:11 +02:00
Bjørn Erik Pedersen 00b590d7ab Improve the twitter card template
Now fall back to `images` set in site config for twitter card.

Fixes #3711
2017-07-17 23:09:52 +02:00
Bjørn Erik Pedersen e0cf2e05bb tpl/collections: Add some empty slice tests to intersect
See #3686
2017-07-08 10:34:42 +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
Artem Sidorenko 34c566773a tpl/math: Add log function
It might be very useful for building tag clouds.
2017-07-03 00:20:48 +02:00
Bjørn Erik Pedersen 8431c8d39d tpl: Add WebP images support
Fixes #3529
2017-06-28 21:45:48 +02:00
Bruno Amaral da72805a43 tpl: Only show post's own keywords in schema.org
Fixes #2635
Closes #2646
2017-06-28 21:26:18 +02:00
Yihui Xie eccb064782 tpl: Simplify the Disqus template a little bit (#3655)
In accordance to the official guide: https://disqus.com/admin/universal/
2017-06-27 09:45:48 -06:00
Yihui Xie 2e1e4934b6 tpl: Improve the built-in Disqus template (#3639)
* Improve the built-in Disqus template

  Set `disqus_identifier`, `disqus_title`, and `disqus_url`
  only if the user has explicitly provided them.

  Do not load Disqus when the website is previewed locally,
  otherwise it is very confusing.

* Use disqus_config instead of three global variables

  https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
2017-06-27 05:40:01 -06: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 c17ad675e8 all: Update textual references in Go source to point to gohugoio/hugo 2017-06-13 18:47:17 +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
Cameron Moore 4113693ac1 tpl/cast: Handle template.HTML and friends in ToInt
Also add tests for ToInt and ToString.

Resolves #3308
2017-05-22 23:20:53 +03:00
Bjørn Erik Pedersen a119ef693f tpl/time: Re-add the time example 2017-05-20 11:41:43 +03:00
Bjørn Erik Pedersen 1f9e8dcc60 tpl: Make the Namespace func signature explicit
This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.
2017-05-20 11:34:38 +03:00
Cameron Moore a59525b05b tpl/time: Remove asTime template func mapping 2017-05-20 00:00:20 +03:00
Cameron Moore 3954160a21 tpl/time: Support overlapping namespace and template func
Fixes #3421
2017-05-20 00:00:20 +03:00
Bjørn Erik Pedersen 93c5774dd7 tpl/collections: Make IsSet WARNING less chatty
Updates #3092
2017-05-19 21:14:37 +03:00
Bjørn Erik Pedersen 405c2f6899 tpl/images: Fix error handling in Config 2017-05-18 23:24:55 +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
Cameron Moore 93b3b13867 tpl/lang: Add NumFmt function
NumFmt formats a number with a given precision using the requested
decimal, grouping, and negative characters.

Fixes #1444
2017-05-18 09:49:20 +03:00
Bjørn Erik Pedersen b6ea492b7a tmplimpl: Add support for ellipsed paginator
Fixes #3466
2017-05-17 21:47:05 +03:00
Bjørn Erik Pedersen af72db806f hugolib: Handle shortcode per output format
This commit allows shortcode per output format, a typical use case would be the special AMP media tags.

Note that this will only re-render the "overridden" shortcodes and only  in pages where these are used, so performance in the normal case should not suffer.

Closes #3220
2017-05-13 22:44:15 +03:00
Bjørn Erik Pedersen cff2f31334 tpl: Add some GoDoc info to template func docs
Closes #3418
2017-05-04 10:46:19 +02:00
Bjørn Erik Pedersen 3dd949d956 tpl/urls: Make urlize return a string
Like it did in 0.20.
2017-05-02 23:46:36 +02:00
Cameron Moore 08c0de5cc3 tpl/data: Clean up data namespace
- Move the main GetCSV and GetJSON into data.go.
- Add error returns to GetCSV and GetJSON.
- Add http client to Namespace for test mocking.
- Send accept headers on remote requests. Fixes #3395
- Return an error on non-2XX HTTP response codes and don't retry.
- Move cache tests to cache_test.go.
2017-05-02 09:18:41 +02:00
Cameron Moore 1cf2f3dc4f tpl/data: Move cache logic to separate file 2017-05-02 09:18:41 +02:00
Cameron Moore 5f095c27ea tpl/data: Shorten some internal func names 2017-05-02 09:18:41 +02:00
Cameron Moore f604076de1 tpl/images: Fix embedded sync.Mutex 2017-05-02 09:17:14 +02:00
Cameron Moore f69df916df tpl: Add basic tests for all namespace init funcs 2017-05-02 00:07:33 +02:00
Bjørn Erik Pedersen 690b0f8ff5 tpl: Add docshelper for template funcs
And fix some other minor related issues.

Updates #3418
2017-05-01 21:44:15 +02:00
Bjørn Erik Pedersen e2b067f050 tpl/partials: Remouve unused method 2017-05-01 15:57:52 +02: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 4714085a10 tpl/urls: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 55f90a3a0d tpl/transform: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen ee5aa84f2a tpl/time: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 4a3463463f tpl/safe: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen b958c0c109 tpl/os: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen fc77b6303c tpl/inflect: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen a432c90aee tpl/images: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 9aee8ace4e tpl/encoding: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 744dccbea4 tpl/crypto: Make it a package that stands on its own
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
Bjørn Erik Pedersen a3bf118eaa tpl/compare: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 6561557367 tpl/data: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen 0ab23eb5a8 tpl/strings: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen eefa0703cb tpl/math: Make it a package that stands on its own
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen c5373efcf0 tpl: Add TemplateFuncsNamespaceRegistry
As a first step to remove the hard ties between `tplimpl` and the different namespace packages.

The `lang` package is used as the first example use case.

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
Jack Taylor 90d3fbf1da tplimpl: Add translation links to the default sitemap template
For pages with translations, add links with hreflang attributes to the
default sitemap template. This helps Google to show the correct
language page in its search results. The syntax used is based on
Google's example at [1].

Also update the sitemap template docs to reflect the changes in the
default template.

[1]
https://support.google.com/webmasters/answer/2620865?hl=en&topic=2370587&ctx=topic

Fixes #2569
2017-04-22 22:37:14 +02:00
Bjørn Erik Pedersen 1cf29200b4 tplimpl: Allow text partials in HTML templates
Most obvius benefit of this is to include CSS partials with css file suffix into HTML templates.

A valid workaround would be to rename the file `mystyles.html`, but that doesn't work too good for external editors etc.

The css partial is  a method used in some themes before Hugo 0.20, but then it stopped working.

This commit reintroduces that behaviour.

Note that the regular layout lookups for text templates, i.e. "single.json" will be
prefixed with "_text/" on lookup and will only match in the text collection.

Fixes #3273
2017-04-16 09:17:47 +02:00
Bjørn Erik Pedersen 077005e514 output: Fix base theme vs project base template logic
Fixes #3323
2017-04-13 11:19:54 +02:00
Albert Nigmatzianov 260b55ea56 tpl: Set RenderingContext.Config in markdownify 2017-04-06 21:02:37 +02:00
Bjørn Erik Pedersen 6650fae7ad tpl: Fix nil pointer in Tree()
Fixes #3285
2017-04-05 22:12:03 +02:00
Bjørn Erik Pedersen 1425587193 hugolib: Add optional outputFormat to Ref/RelRef
Fixes #3224
2017-04-04 23:09:01 +02:00
Bjørn Erik Pedersen bc36d468ab tplimpl: Reintroduce the double template lookup in Partial
So it works as before without the html suffix.

Fixes #3272
2017-04-04 17:21:04 +02:00
Bjørn Erik Pedersen 7da1b65968 all: Use the configured output types to resolve template type
Closes #320
2017-04-04 15:12:30 +02:00
Bjørn Erik Pedersen 8b5b558bb5 tpl: Rework to handle both text and HTML templates
Before this commit, Hugo used `html/template` for all Go templates.

While this is a fine choice for HTML and maybe also RSS feeds, it is painful for plain text formats such as CSV, JSON etc.

This commit fixes that by using the `IsPlainText` attribute on the output format to decide what to use.

A couple of notes:

* The above requires a nonambiguous template name to type mapping. I.e. `/layouts/_default/list.json` will only work if there is only one JSON output format, `/layouts/_default/list.mytype.json` will always work.
* Ambiguous types will fall back to HTML.
* Partials inherits the text vs HTML identificator of the container template. This also means that plain text templates can only include plain text partials.
* Shortcode templates are, by definition, currently HTML templates only.

Fixes #3221
2017-04-02 23:13:10 +02:00
Bjørn Erik Pedersen 7eb71ee064 Revert "tpl: Rework to handle both text and HTML templates"
Will have to take another stab at this ...

This reverts commit 5c5efa03d2.

Closes #3260
2017-04-02 14:20:34 +02:00
Bjørn Erik Pedersen 0aeadfd02d tplimpl: Add test with failing partial
Main motivation to see that the containing template name is included in the error message name.

It is.
2017-04-02 12:06:21 +02:00
Bjørn Erik Pedersen 5c5efa03d2 tpl: Rework to handle both text and HTML templates
Before this commit, Hugo used `html/template` for all Go templates.

While this is a fine choice for HTML and maybe also RSS feeds, it is painful for plain text formats such as CSV, JSON etc.

This commit fixes that by using the `IsPlainText` attribute on the output format to decide what to use.

A couple of notes:

* The above requires a nonambiguous template name to type mapping. I.e. `/layouts/_default/list.json` will only work if there is only one JSON output format, `/layouts/_default/list.mytype.json` will always work.
* Ambiguous types will fall back to HTML.
* Partials inherits the text vs HTML identificator of the container template. This also means that plain text templates can only include plain text partials.
* Shortcode templates are, by definition, currently HTML templates only.

Fixes #3221
2017-04-02 11:37:30 +02:00
Bjørn Erik Pedersen 42a4f6f9cb tplimpl: Fix map data race in URLLock 2017-03-31 10:40:33 +02:00
Bjørn Erik Pedersen 79b34c2f1e tplimpl: Fix deadlock in getJSON
Fixes #3211
2017-03-31 09:17:03 +02:00
Bjørn Erik Pedersen 4923273688 tplimpl: Fix lookup with non-standard layout folder 2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen 9a0aa5fdbe hugolib: Wrap pageOutput create in sync.Once 2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen ee75e2999b Remove the now superflous defaultExtension
And some other unsed fields and methods.
2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen 15b64d51da all: Propagate baseURL error to the callers 2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen 148fedd227 hugolib, tplimpl: Use OutputFormats to create atom links 2017-03-27 15:43:56 +02:00