Commit graph

285 commits

Author SHA1 Message Date
Bjørn Erik Pedersen
7e81971b46 node to page: Don't repeat the RSS title if it is the same
Updates #2297
2016-11-22 09:57:03 +01:00
Bjørn Erik Pedersen
e7d0bc8a74 Revert "Fix case issues with Params"
This reverts commit 239c75c7f8.

There is a ininite loop in there somewhere on my site that needs to be resolved.
2016-11-22 09:42:11 +01:00
Bjørn Erik Pedersen
239c75c7f8 Fix case issues with Params
There are currently several Params and case related issues floating around in Hugo.

This is very confusing for users and one of the most common support questions on the forum.

And while there have been done some great leg work in Viper etc., this is of limited value since this and similar doesn't work:

`Params.myCamelCasedParam`

Hugo has control over all the template method invocations, and can take care of all the lower-casing of the map lookup keys.

But that doesn't help with direct template lookups of type `Site.Params.TWITTER_CONFIG.USER_ID`.

This commit solves that by doing some carefully crafted modifications of the templates' AST -- lowercasing the params keys.

This is low-level work, but it's not like the template API wil change -- and this is important enough to defend such "bit fiddling".

Tests are added for all the template engines: Go templates, Ace and Amber.

Fixes #2615
Fixes #1129
Fixes #2590
2016-11-22 09:04:38 +01:00
Tristan Rice
a49f838cd0 tpl: Add imageConfig function
Add imageConfig function which calls image.DecodeConfig and returns the height, width and color mode of the image. (#2677)

This allows for more advanced image shortcodes and templates such as those required by AMP.

layouts/shortcodes/amp-img.html
```
{{ $src := .Get "src" }}
{{ $config := imageConfig (printf "/static/%s" $src) }}

<amp-img src="{{$src}}"
           height="{{$config.Height}}"
           width="{{$config.Width}}"
           layout="responsive">
</amp-img>
```
2016-11-16 13:00:45 +01:00
Albert Nigmatzianov
950034db5c source, tpl: Fix staticcheck complaints
tpl/template_funcs.go:1019:3: the surrounding loop is unconditionally terminated
source/lazy_file_reader.go:66:5: err != nil is always true for all possible
values ([nil:error] != [nil:error])
2016-11-15 21:22:43 +01:00
Albert Nigmatzianov
85a2d81e3c commands, tpl: Get rid of repeating viper accesses
* all: Delete some blank lines
* commands, tpl: Get rid of repeating viper accesses
2016-11-07 00:10:32 +01:00
Bjørn Erik Pedersen
07eb3a50c7 tpl: Golint fixes 2016-11-05 17:28:14 +01:00
Bjørn Erik Pedersen
301e4c7e78 Make Amber read from the Afero source file system 2016-10-26 20:50:12 +02:00
Bjørn Erik Pedersen
0406be3d54 Add missing template error logging 2016-10-25 22:56:44 +02:00
Albert Nigmatzianov
f21e2f25c9 all: Unify case of config variable names
All config variables starts with low-case and uses camelCase.

If there is abbreviation at the beginning of the name, the whole
abbreviation will be written in low-case.
If there is abbreviation at the end of the name, the
whole abbreviation will be written in upper-case.
For example, rssURI.
2016-10-24 20:56:00 +02:00
Bjørn Erik Pedersen
165edc7f0a tpl: Fix comment 2016-10-24 14:32:31 +02:00
Bjørn Erik Pedersen
a10b2cd372 Avoid reading from Viper for path and URL funcs
The gain, given the "real sites benchmark" below, is obvious:

```
benchmark           old ns/op       new ns/op       delta
BenchmarkHugo-4     14497594101     13084156335     -9.75%

benchmark           old allocs     new allocs     delta
BenchmarkHugo-4     57404335       48282002       -15.89%

benchmark           old bytes       new bytes      delta
BenchmarkHugo-4     9933505624      9721984424     -2.13%
```

Fixes #2495
2016-10-24 13:45:30 +02:00
Bjørn Erik Pedersen
588256776e Add workaround for block template crash
Fixes #2549
2016-10-14 11:01:49 +02:00
Bjørn Erik Pedersen
eb00c621e0 tpl: Remove the spamming template errors
Fixes #2343
2016-10-12 10:12:15 +02:00
Cameron Moore
8ddd95e361 tpl: Factor out double Lookup in executeTemplate 2016-10-12 08:26:39 +02:00
Cameron Moore
474eb454df tpl: Add partialCached template function
Supports an optional variant string parameter so that a given partial
will be cached based upon the name+variant.

Fixes #1368
Closes #2552
2016-10-11 23:56:06 +02:00
Bjørn Erik Pedersen
2071d470e6 tpl: Polish i18n tests
* Make the type/var names more specific. They live in the test namespace, but there are other tests there.
* Camel case variable
* Small change suggested by Golint
2016-09-20 13:22:56 +02:00
Mitchell Cohen
e7e2a1ca02 tpl: Improve tests and docs for i18n 2016-09-20 11:11:57 +02:00
Bjørn Erik Pedersen
2105e42aca tpl: Set i18n bundle once per test run
No real practical difference, but more clear.
2016-09-19 02:44:21 +02:00
Mitchell Cohen
b3a721559a Fix i18n with missing translations and add tests 2016-09-18 22:18:13 +02:00
Bjørn Erik Pedersen
4a79fa0c33 Revert the "standardize author data"
There were some breaking changes etc. that is too late to fix for 0.17.

Let us think this through and add proper author support for Hugo 0.18.

Fixes #2464

Revert "docs: Add documentation for author profiles"

This reverts commit b6673e5309.

Revert "Add First Class Author Support"

This reverts commit cf978c0649.
2016-09-18 19:16:39 +02:00
Derek Perkins
cf978c0649 Add First Class Author Support
Closes #1850
2016-09-17 00:49:24 +02:00
digitalcraftsman
e80453a991 tpl: Add EnableMissingTranslationPlaceholders option
Fixes #2451
2016-09-16 17:20:29 +02:00
Bjørn Erik Pedersen
a04abf0dda tpl: Make the *langURL funcs tace interface{}
Fixes #2447
2016-09-13 17:07:52 +02:00
Cameron Moore
3908489ccd tpl: Extend where to iterate over maps
Fixes #2028
2016-09-12 11:03:53 +02:00
Cameron Moore
640121423c tpl: Fix typos in tests
Closes #2370
2016-09-12 10:56:24 +02:00
Ben Campbell
3392133128 Remove redundant field in sort helper struct
The pair struct used by sortSeq() had two key fields, where only one
is really needed.
2016-09-11 10:42:50 +02:00
Bjørn Erik Pedersen
9c5f2befc0 tpl: Make it more clear on missing language string 2016-09-09 21:21:16 +02:00
Bjørn Erik Pedersen
fe0c270577 Reset the i18n func map on reload
Also improve the error message on missing resource bundles.
2016-09-08 17:18:11 +03:00
Bjørn Erik Pedersen
34fe5cd34f tpl: Fix echoParam
Fixes #2406
2016-09-07 22:03:09 +03:00
Bjørn Erik Pedersen
f1e1cdab3f Improve i18n string handling
* Fall back to default language on missing translation file
* Add a i18n-warnings build flag
* If that flag is set, print a parseable and greppable string on missing translation strings

See #2303
2016-09-06 18:32:19 +03:00
Bjørn Erik Pedersen
8da040342e Render main content language in root by default
Fixes #2312
2016-09-06 18:32:18 +03:00
Bjørn Erik Pedersen
54141f71dd Improve language handling in URLs
The current "rendering language" is needed outside of Site. This commit moves the Language type to the helpers package, and then used to get correct correct language configuration in the markdownify template func.
This commit also adds two new template funcs: relLangURL and absLangURL.

See #2309
2016-09-06 18:32:18 +03:00
Bjørn Erik Pedersen
2079a23dd8 Make it possible to configure Blackfroday per language
See #2309
2016-09-06 18:32:17 +03:00
Bjørn Erik Pedersen
b6fcb3d0bb Add sitemap index for multilingual sites
See #2309
2016-09-06 18:32:17 +03:00
Bjørn Erik Pedersen
708bc78770 Optimize the multilanguage build process
Work In Progress!

This commit makes a rework of the build and rebuild process to better suit a multi-site setup.

This also includes a complete overhaul of the site tests. Previous these were a messy mix that
were testing just small parts of the build chain, some of it testing code-paths not even used in
"real life". Now all tests that depends on a built site follows the same and real production code path.

See #2309
Closes #2211
Closes #477
Closes #1744
2016-09-06 18:32:16 +03:00
Bjørn Erik Pedersen
3a02807970 Add Translations and AllTranslations to Node
This commit also consolidates URLs on Node vs Page, so now .Permalink should be interoperable.

Note that this implementations should be fairly short-livded, waiting for #2297, but the API should be stable.
2016-09-06 18:32:16 +03:00
Bjørn Erik Pedersen
52bf8f9095 Rework the i18n template func handling
Setting the language to use when loading the language bundles just doesn't work.
The template system is unfortanetely a global, and the last languate processed won ...
2016-09-06 18:32:16 +03:00
Alexandre Bourget
ec33732fbe Add multilingual support in Hugo
Implements:
* support to render:
  * content/post/whatever.en.md to /en/2015/12/22/whatever/index.html
  * content/post/whatever.fr.md to /fr/2015/12/22/whatever/index.html
* gets enabled when `Multilingual:` is specified in config.
* support having language switchers in templates, that know
  where the translated page is (with .Page.Translations)
  (when you're on /en/about/, you can have a "Francais" link pointing to
   /fr/a-propos/)
  * all translations are in the `.Page.Translations` map, including the current one.
* easily tweak themes to support Multilingual mode
* renders in a single swift, no need for two config files.

Adds a couple of variables useful for multilingual sites

Adds documentation (content/multilingual.md)

Added language prefixing for all URL generation/permalinking see in the
code base.

Implements i18n. Leverages the great github.com/nicksnyder/go-i18n lib.. thanks Nick.
* Adds "i18n" and "T" template functions..
2016-09-06 18:32:15 +03:00
Bjørn Erik Pedersen
fee9ee72a6 tpl: Add missing arg to Fatalf 2016-08-20 20:52:14 +01:00
Cameron Moore
5498a1bd56 tpl: Return all errors from casting
Most non-boolean template functions should return errors.

Fixes #2354
2016-08-16 21:42:38 -05:00
Bjørn Erik Pedersen
09612f7af8 tpl: Fix faulty ordering of relURL test cases 2016-08-13 00:36:15 +02:00
Stephan Kulla
88dcbc6efa tpl: Make absURL and relURL accept anything 2016-08-13 00:31:50 +02:00
digitalcraftsman
914e4d8535 tpl: Fix typo in FindRE test 2016-08-04 14:37:15 +02:00
Bjørn Erik Pedersen
93f3a85bf8 Fix the time template func test
By making it not depend on the locale setup.
2016-08-04 10:36:44 +02:00
Wade Fitzpatrick
70544f9e62 tpl: Add time template func
Fixes #2328
2016-08-04 01:55:24 +02:00
Bjørn Erik Pedersen
285807ba7a Take 2: Load templates from the Afero source fs
See #2321
2016-07-30 17:28:40 +02:00
Bjørn Erik Pedersen
ec23aa998a Load templates from the Afero source fs
Fixes #2321
2016-07-30 17:16:04 +02:00
Bjørn Erik Pedersen
4ddd5361c1 Use the Afero source fs where relevant
Fixes #2319
2016-07-30 15:37:03 +02:00
Cathal Garvey
20555b1630 Add htmlEscape and htmlUnescape template functions
These functions allow trivial escaping and unescaping of HTML entities,
and make it far easier to compose other functions for the creation of
parameterised URLs.
2016-07-19 00:14:05 +02:00