1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

3178 Commits

Author SHA1 Message Date
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
27610ddd01 hugolib: Don't ignore errors from applyDepsIfNeeded 2017-04-02 18:43:32 +02:00
6b29bccfee hugolib, i18n: Update tests with flat format and TOML files 2017-04-02 18:43:32 +02:00
28fdd71c29 vendor: Update go-i18n
Fix #2577
2017-04-02 18:43:32 +02:00
fe8462b205 docs, examples: Use TOML for i18n config files
Fix #3200
2017-04-02 18:43:32 +02:00
d122260de7 vendor: update goorgeous 2017-04-02 18:34:17 +02:00
a037b855dd docs: Add blog of Enrique Saez Gil to the site showcase 2017-04-02 18:29:24 +02:00
7eb71ee064 Revert "tpl: Rework to handle both text and HTML templates"
Will have to take another stab at this ...

This reverts commit 5c5efa03d2512749950b0d05a7d4bde35ecbdc37.

Closes #3260
2017-04-02 14:20:34 +02:00
c97dae40d9 hugolib: Use Page Kind in template errors to prevent log spam
Having the content page name in the log key for the distinct error logger isnt't very usable when you have an error in a commonly used partial.

Using the Page Kind reduces the amount of log entries. Here is an example from an error in the partial menu.html, used in all the page templates:

```
Started building sites ...
ERROR 2017/04/02 12:19:43 Error while rendering "page": template: /Users/bep/sites/bepsays.com/layouts/_default/single.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/single.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "section": template: /Users/bep/sites/bepsays.com/layouts/_default/section.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/section.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "taxonomy": template: /Users/bep/sites/bepsays.com/layouts/_default/list.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/list.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "home": template: /Users/bep/sites/bepsays.com/layouts/index.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/index.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "404": template: 404.html:2:3: executing "404.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
Built site for language nn:
```
Which is pretty good.
2017-04-02 12:22:54 +02:00
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
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
73c1c7b69d vendor: Update cobra
Really fix #2349
b7a672f didn't actually the issue.
2017-04-01 20:28:18 +02:00
f911b107ef media, output: Add CSV type and format
And make CSS correclty behave as plain text.
2017-04-01 15:12:31 +02:00
05949c9038 docs: Fix typo/source link in firstname.club showcase addition 2017-03-31 22:49:09 +02:00
d5036c3ab5 docs: Update link to Disqus alternative Livefyre.com
Livefyre.com is down.

Livefyre was integrated into Adobe's offering.

The product is now called Adobe Experience Manager Livefyre.

Wikipedia points to web.livefyre.com which redirects to the link I provided in the commit.
2017-03-31 22:41:22 +02:00
af1f9ecf91 docs: Add firstname.club to the showcase 2017-03-31 22:38:22 +02:00
42a4f6f9cb tplimpl: Fix map data race in URLLock 2017-03-31 10:40:33 +02:00
79b34c2f1e tplimpl: Fix deadlock in getJSON
Fixes #3211
2017-03-31 09:17:03 +02:00
3c6b16d5a2 vendor: Update fsnotify with several Linux-fixes 2017-03-29 13:30:31 +02:00
87b3cd4655 hugolib, helpers: Reduce log level to WARN on .Render for non-regular pages
We will eventually support all types in the Render method.
2017-03-29 08:08:45 +02:00
5989c4d464 helpers, output: Fix spelling 2017-03-28 01:19:46 +02:00
af55ec7661 hugolib, output: Gofmt 2017-03-28 01:18:15 +02:00
f2fbf0b2ea media: Add some more relevant MIME types 2017-03-28 00:09:25 +02:00
4923273688 tplimpl: Fix lookup with non-standard layout folder 2017-03-27 15:43:56 +02:00
930a3df1b7 hugolib, output: Restrict Render to regular Pages
Using it for list pages doesn't work and has potential weird side-effects.

The user probably meant to range over .Site.ReqularPages, and that is now marked clearly in the log.
2017-03-27 15:43:56 +02:00
e49a2b83ad hugolib: Fix Render layouts for list pages 2017-03-27 15:43:56 +02:00
9a0aa5fdbe hugolib: Wrap pageOutput create in sync.Once 2017-03-27 15:43:56 +02:00
0aaf3c56a5 hugolib: Fix panic for Permalink in 404 etc. templates 2017-03-27 15:43:56 +02:00
ee4a33b14f commands: Fix broken commandeer 2017-03-27 15:43:56 +02:00
09c88e84d1 output: Rename HTMLType etc. to HTMLFormat 2017-03-27 15:43:56 +02:00
24c1770288 hugolib: Revise paginator alias path handling 2017-03-27 15:43:56 +02:00
b7ed67d425 hugolib: More TODO fixes 2017-03-27 15:43:56 +02:00
3cd97951f1 hugolib, layout: Consolidate RSS template handling 2017-03-27 15:43:56 +02:00
ee75e2999b Remove the now superflous defaultExtension
And some other unsed fields and methods.
2017-03-27 15:43:56 +02:00
15b64d51da all: Propagate baseURL error to the callers 2017-03-27 15:43:56 +02:00
148fedd227 hugolib, tplimpl: Use OutputFormats to create atom links 2017-03-27 15:43:56 +02:00
ec01c3a7f0 hugolib: Add 404 test 2017-03-27 15:43:56 +02:00
5761b93c96 hugolib, output: Fix RSSLink vs output formats
And remove the now superflous setPageURLs method.
2017-03-27 15:43:56 +02:00
87188496fb hugolib, output: Handle aliases for all HTML formats 2017-03-27 15:43:56 +02:00
0c4701f0ef hugolib: Update site stats to take output formats into account 2017-03-27 15:43:56 +02:00
d851d6b98f Add custom protocol support in Permalink 2017-03-27 15:43:56 +02:00
8bcc08e3b0 media, output: Add Calendar type 2017-03-27 15:43:56 +02:00
dbb83f925a hugolib: Read default output formats from site config 2017-03-27 15:43:56 +02:00
4aaed87dd9 hugolib, media: Make the MediaType available to the templates 2017-03-27 15:43:56 +02:00
c7dbee2321 hugolib, output: Add Rel to the output format
To make it super-easy to create rel-links.
2017-03-27 15:43:56 +02:00
29d3778ba1 docs: Move the rough custom output formats spec to docs
This isn't meant to be the final useer docs on this feature!
2017-03-27 15:43:56 +02:00
1b2be5e878 hugolib: Add OutputFormats with permalinks to Page 2017-03-27 15:43:56 +02:00
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
c7c6b47ba8 hubolib: Pick layout per output format 2017-03-27 15:43:56 +02:00
08fa2b1124 hugolib: Fix layout lookup order for Render func
Will have to fix this in a better way later in relation to the non-renderable pages.

But this commit brings the Hugo Benchmark down to "only slightly slower" than master.

```
benchmark           old ns/op       new ns/op       delta
BenchmarkHugo-4     10074504521     10071236251     -0.03%

benchmark           old allocs     new allocs     delta
BenchmarkHugo-4     43623091       49271859       +12.95%

benchmark           old bytes      new bytes      delta
BenchmarkHugo-4     9468322704     9725848376     +2.72%
```

Which is something we can work with.
2017-03-27 15:43:56 +02:00