Commit graph

386 commits

Author SHA1 Message Date
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
Bjørn Erik Pedersen dbb83f925a hugolib: Read default output formats from site config 2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen baa29f6534 output: Rework the base template logic
Extract the logic to a testable function and add support for custom output types.

Fixes #2995
2017-03-27 15:43:56 +02:00
Bjørn Erik Pedersen 2bea9d0ca1 Revert "tplimpl: return an error on unsupported type in isSet"
This breaks the theme site and lots of themes, so we will have to thinkg a little harder about this one.

This reverts commit 74ea81b885.
2017-03-26 20:09:08 +02:00
Darwin 1b92c8b713 Change RSS description from full .Content to .Summary 2017-03-25 22:58:41 +01:00