Commit graph

488 commits

Author SHA1 Message Date
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
digitalcraftsman
5d0748ce51 tpl: Add union template func 2017-03-12 23:04:12 +01:00
Albert Nigmatzianov
48120ccfd2 all: Fix some govet complaints 2017-03-09 14:18:12 +01:00
Cameron Moore
45b9d7223a tplimpl: Add built-in print funcs to FuncMap
Add print, printf, and println to the Hugo FuncMap so that they are
accessible to the apply template func.

Updates #3139
2017-03-09 00:21:55 +01:00
Cameron Moore
74ea81b885 tplimpl: return an error on unsupported type in isSet
Fixes #3092
2017-03-02 00:11:10 +01:00
digitalcraftsman
e37e3dcc04 tpl: Add title meta tag to twitter card template
Fixes #3095
2017-02-25 09:53:25 +01:00
Alan Orth
eb27c47fc5 tpl: Use og:updated_time OpenGraph tag on nodes
A previous commit greatly improved the OpenGraph tags generated by
Hugo's internal opengraph template, but there was a minor error in
the fix. Nodes are of type "website" and according to the Facebook
docs they should use og:updated_time.

See: https://github.com/spf13/hugo/pull/2979
See: https://developers.facebook.com/docs/reference/opengraph/object-type/website/
2017-02-21 14:41:09 +01:00
Bjørn Erik Pedersen
2cbdd65330 tpl, hugolib: Fix live-reload of non-renderable content pages
Fixes #3062
2017-02-21 13:56:20 +01:00
Alan Orth
4e77c8717b tpl: Remove twitter:domain tag from internal shortcode
It seems this metadata tag is no longer used by Twitter, as it has
been removed from their Cards Markup Tag Reference since at least
2013 according to a post on the W3 mailing list.

See: https://dev.twitter.com/cards/markup
See: https://lists.w3.org/Archives/Public/www-validator/2013Oct/0025.html
2017-02-21 13:24:44 +01:00
Bjørn Erik Pedersen
bdc02edfa8 tplimpl: Fix issue with recursive templates
Fixes #2927
2017-02-18 09:08:40 +01:00
Cameron Moore
10c13f5d79 hugolib: Make RSS item limit configurable
Add a new rssLimit site configuration option with default of 15.  Prior
to this fix, you could create your own RSS feed to override the default
limit of 15, but we still had a hardcoded limit of 50 items set in
`hugolib.renderRSS()`.

With this option in place, the `range first 15 .Data.Pages` logic is no
longer hardcoded into the embedded RSS template.

Because the size of the slice passed to the template is now limited to
rssLimit instead of 50, this commit is a breaking change for sites
with a custom RSS template that expects more than 15 items.

Fixes #3035
2017-02-17 19:53:08 +01:00
Cameron Moore
d3abb93cc7 tplimpl: Fix instagram shortcode panic on invalid ID
Instagram doesn't return a valid JSON response when the requested ID is
invalid or not found.

Fixes #3048
2017-02-17 17:50:37 +01:00
Bjørn Erik Pedersen
4b3ca38b2e tplimpl: Fix data race in resGetResource
Fixes #3045
2017-02-17 17:15:26 +01:00
Bjørn Erik Pedersen
77cbe4d60b tplimpl: Refactor imageConfig into a struct
Updates #2701
2017-02-17 17:15:26 +01:00
Bjørn Erik Pedersen
c507e2717d tpl: Refactor package
Now:

* The template API lives in /tpl
* The rest lives in /tpl/tplimpl

This is bound te be more improved in the future.

Updates #2701
2017-02-17 17:15:26 +01:00
Bjørn Erik Pedersen
93ca7c9e95 all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.

Updates #2701
Fixes #3016
2017-02-17 17:15:26 +01:00
Bjørn Erik Pedersen
691156c5ba Use OS fs by default
Fixes #3032
2017-02-15 10:00:34 +01:00
Cameron Moore
5cc8b58907 tpl: Accept limit as interface in findRE func
Fixes #3018
2017-02-10 20:02:28 +07:00
Bjørn Erik Pedersen
2618cfbeaa hugolib: Fix error for non-renderable HTML content with shortcodes
This commit re-introduces template lookup order that was accidently removed as
part of the template nonglobal refactoring.

Fixes #3021
2017-02-10 18:57:38 +07:00
Bjørn Erik Pedersen
a89fb86cdf tpl: Must do a extra lookup of cloned base templates
See #2549
Fixes #3013
2017-02-07 10:43:30 +07:00
Bjørn Erik Pedersen
c71e1b106e all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
2017-02-04 11:37:25 +07:00
Alan Orth
95ad3ad2fa tpl: Improve generation of OpenGraph date tags
Allow all nodes/pages to use date-related OpenGraph meta tags, not
only sites which are using the as-of-yet unfinished .Site.Authors
functionality.

Improve compliance of tags with Facebook's OpenGraph docs for the
"website" and "article" types[0][1]. Also, use the proper tag for
modification date (og:update_time vs article:modified_time).

Generate date published using either .PublishDate or .Date, and use
.Lastmod for modification date, which can use the new enableGitInfo
functionality from Hugo 0.18, but seamlessly falls back to .Date if
the site does not have this enabled/supported.

[0] https://developers.facebook.com/docs/reference/opengraph/object-type/website/
[1] https://developers.facebook.com/docs/reference/opengraph/object-type/article/
2017-01-23 21:31:30 +07:00
Cameron Moore
3ac1b9fe33 tpl: Fix deadlock in cached partials
Cached partials that contained cached partials would create a deadlock.

Fixes #2935
2017-01-18 10:30:22 +01:00
Bjørn Erik Pedersen
85c7578313 tpl: Fix broken benchmarks
But that did not explain issue #2935:

```
BenchmarkPartial-4                       200000          6452 ns/op        1040 B/op          30 allocs/op
BenchmarkPartialCached-4                 500000          4104 ns/op         544 B/op          14 allocs/op
BenchmarkPartialCachedVariants-4         500000          3398 ns/op         624 B/op          17 allocs/op
```
2017-01-14 12:39:52 +01:00
Brad Peabody
db33a33e61 Show full template error 2017-01-11 09:56:03 +01:00
Bjørn Erik Pedersen
d6000a208c all: Refactor to nonglobal template handling
Updates #2701
2017-01-10 01:36:59 +01:00
Bjørn Erik Pedersen
45e3ed517a all: Refactor to non-global logger
Note that this looks like overkill for just the logger, and that is correct,
but this will make sense once we start with the template handling etc.

Updates #2701
2017-01-07 17:06:35 +01:00
Mathias Biilmann
2989c38245 tpl: Add truncate template function
This commit adds a truncate template function for safely truncating text without
breaking words. The truncate function is HTML aware, so if the input text is a
template.HTML it will be truncated without leaving broken or unclosed HTML tags.

    {{ "this is a very long text" | truncate 10 " ..." }}
    {{ "With [Markdown](/markdown) inside." | markdownify | truncate 10 }}
2017-01-06 10:42:32 +01:00
Anthony Fok
19b6fdf2b1 tpl: Fix Unix time test case in TestDateFormat()
Fixes #2855
2017-01-03 23:43:17 +01:00
Nishanth Shanmugham
cabc6b3186 tpl: Add now function
Add a now template function that returns the current time as time.Time.
Also, update related docs.
2017-01-01 02:50:46 +01:00
digitalcraftsman
02d6f5320f tpl: Use HTTPS in Google Analytics template
Fixes #2858
2016-12-31 12:43:33 +01:00
Bjørn Erik Pedersen
bc060ee1c9 tpl: Update dateFormat test expectations for epoch values
As `Cast` now supports `int` inputs.
2016-12-25 14:53:34 +01:00
Tristan Rice
d055862a41 tpl: Fix crash when using imageConfig
defaultImageConfigCache is now initialized statically instead of relying on it
being initialized in the reset function.

Fixes #2806
2016-12-25 13:43:50 +01:00
Cameron Moore
34c87421b8 tpl: Update getenv to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore
29caaddce6 tpl: Update title to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore
661d64c46a tpl: Update upper to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore
4e5b4ac504 tpl: Update lower to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Cameron Moore
6b8422bb35 tpl: Update hasPrefix to accept interface{} params
Updates #2822
2016-12-23 09:51:03 +01:00
Bjørn Erik Pedersen
a3a67163f9 hugolib: Enable override of theme base template only
This commit fixes the base template lookup order to match the behaviour of regular templates.

```
1. <current-path>/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
2. <current-path>/baseof.<suffix>
3. _default/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
4. _default/baseof.<suffix>

For each of the steps above, it will first look in the project, then, if theme is set,
in the theme's layouts folder.
```

Fixes #2783
2016-12-15 21:35:38 +01:00
Bjørn Erik Pedersen
7862de91de tpl: Add a querify test case that is actually and URL
See #2780
2016-12-13 00:16:09 +01:00
Bjørn Erik Pedersen
5b1eee44c6 tpl: Avoid repeating the same test case in TestMD5 and TesSHA* 2016-12-05 00:27:49 +01:00
digitalcraftsman
0f6c73cf2e tpl: Add sha256 template function
Fixes #2742
2016-12-04 15:03:52 +01:00
Bjørn Erik Pedersen
046320d3f4 tpl: Fix params case issue with nested template funcs
Fixes #2740
2016-11-27 19:02:43 +01:00
Victor Kropp
dbb0c1cfc9 hugolib: Add shortcode for Instagram 2016-11-23 20:28:42 +01:00
Bjørn Erik Pedersen
139585f84a tpl: Simplify 2016-11-23 18:53:50 +01:00
Bjørn Erik Pedersen
c33eb93548 tpl: Add some missing test cases 2016-11-23 10:37:09 +01:00
Bjørn Erik Pedersen
174f97a9dd tpl: Fix spelling in test 2016-11-23 09:17:47 +01:00
bogem
7665dd239e tpl: Drop an else block in checkCondition
Fix golint warning: tpl/template_funcs.go:853:10: if block ends with a
return statement, so drop this else and outdent its block

See #2014
2016-11-23 09:13:00 +01:00
bogem
75e55cd06f hugolib, source, tpl: Fix docs
See #2014
2016-11-23 09:13:00 +01:00
bogem
dec1706ae0 commands, hugolib, parser, tpl: Use errors.New instead of fmt.Errorf 2016-11-22 23:43:55 +01:00
bogem
1f130fd692 commands, hugolib, source, target, tpl: Get rid of some fmt statements 2016-11-22 23:43:55 +01:00
Bjørn Erik Pedersen
e1da7cb320 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 17:33:52 +01:00
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
Bjørn Erik Pedersen
3564f09e3d tpl: Add humanize examples to smoke tests 2016-07-14 20:32:32 +02:00
Cathal Garvey
55a4f6e48e Do not double-escape in querify
Test case modified and expanded for querify to reflect original bug and changes.

Fixes #2279
2016-07-14 15:53:33 +02:00
Michael Orr
0a812beb12 tpl: Modify tpl.humanize to ordinalize integer input
Add logic to tpl.humanize such that it understands input of int literals
or strings which represent an integer. When tpl.humanize sees this type
of input, it will use inflect.Ordinalize as opposed to the standard
inflect.Humanize.

Fixes #1886
2016-07-13 22:09:59 +02:00
Bjørn Erik Pedersen
adf405496e Fix humanize when string is empty
Fixes #2272
2016-07-10 15:10:22 +02:00
Bjørn Erik Pedersen
39fe42cf6b Simplify querify 2016-07-06 20:57:37 +02:00
Jimmy Sawczuk
fbf48824ae tpl: Add a querify function to generate query strings inside templates
The query function will take a set of parameters specified like a dict and return a url.Values object which can be .Encode'd into a query string.

Example:

<a href="http://www.google.com?{{ (querify "q" "test" "page" 3).Encode | safeHTML }}">Search</a>

Returns:

<a href="http://www.google.com?page=3&q=test">Search</a>

Closes #2257
2016-07-05 19:52:45 +02:00
marco
c21e2b3b4d tpl: Enable safeHTMLAttr
See #2234 and #347
2016-06-27 09:18:14 -06:00
Bjørn Erik Pedersen
64817cc0d1 Fix broken template test 2016-05-09 23:18:18 +02:00
Bjørn Erik Pedersen
273a68400f Add non-string support in markdownify 2016-05-06 10:11:17 +02:00
Christopher Mancini
09038865c2 tpl: Add intersect operator to where function
Returns true if a given field value that is a slice / array of strings, integers or floats contains elements in common with the matching value. It follows the same rules as the intersect function.

Closes #1945
2016-04-28 00:58:47 +02:00
Robert Basic
24cb0d1f58 tpl: Do not write to cache when ignoring cache
Fixes #2067
Closes #2069
2016-04-14 10:48:26 +02:00
Bjørn Erik Pedersen
d48b986c45 Revert "tpl: Extend where to iterate over maps"
Committed by accident.

This reverts commit 0141a02160.
2016-04-13 19:13:33 +02:00
Cameron Moore
0141a02160 tpl: Extend where to iterate over maps
Refactor and extend where to iterate over maps.
2016-04-13 11:43:06 +02:00
digitalcraftsman
6c900380dc tpl: Add replaceRE to the "smoke tests"
Fixes #2063
2016-04-08 21:36:35 +02:00
Bjørn Erik Pedersen
f2ff77f3ac Make Hugo build without Mercurial
By creating a fork of the Bitbucket inflect repo. It hasn't changed since 2013,
so it must be considered pretty stable.

Fixes #2062
2016-04-08 21:11:44 +02:00
digitalcraftsman
5bfe16ef8d tpl: Add findRE template func 2016-04-05 22:26:03 +02:00
Bjørn Erik Pedersen
f0dbf2c88f tpl: Add the other test case for hasPrefix 2016-04-03 01:59:47 +02:00
Bjørn Erik Pedersen
aaee038581 tpl: Sort the smoke tests 2016-04-03 01:57:22 +02:00
digitalcraftsman
80d02a14ab tpl: Add hasPrefix to the template funcs' "smoke test" 2016-04-03 01:30:14 +02:00
Cameron Moore
fe929114d3 tpl: Fix panic in sort of nil sequence
Properly handle a nil sequence in the sortSeq function.  Test included.
Discovered while using `range sort .Site.Data.source.Undefined "foo"`.
2016-04-02 23:06:48 +02:00
Cameron Moore
d15fda5000 tpl: Fix panic in pairList.Less
While sorting on data sources with missing fields, a panic can occur in
pairList.Less if `Interface()` is called on a invalid `reflect.Value`.
This commit detects an invalid Value and replacing it with a zero value
for the comparison.
2016-04-02 23:01:36 +02:00
Bjørn Erik Pedersen
c2277fcbc1 docs: Add doc and a test for readDir
Fixes #2009
2016-03-31 23:16:42 +02:00
Bjørn Erik Pedersen
cb89ae63e9 tpl: Make readDir use the WorkingDir fs
Fixes #2010
2016-03-31 23:06:51 +02:00
Bjørn Erik Pedersen
4f66f790b1 Add readFile template func
This also includes a refactor of the hugofs package and its usage.

The motivation for that is:

The Afero filesystems are brilliant. Hugo's way of adding a dozen of global variables for the different filesystems was a mistake. In readFile (and also in some other places in Hugo today) we need a way to restrict the access inside the working dir. We could use ioutil.ReadFile and implement the path checking, checking the base path and the dots ("..") etc. But it is obviously better to use an Afero BasePathFs combined witha ReadOnlyFs. We could create a use-once-filesystem and handle the initialization ourselves, but since this is also useful to others and the initialization depends on some other global state (which would mean to create a new file system on every invocation), we might as well do it properly and encapsulate the predefined set of filesystems. This change also leads the way, if needed, to encapsulate the file systems in a struct, making it possible to have several file system sets in action at once (parallel multilanguage site building? With Moore's law and all...)

Fixes #1551
2016-03-31 21:24:18 +02:00
digitalcraftsman
7fa2cec906 tpl: Small Golint fixes 2016-03-24 22:56:50 +01:00
Bjørn Erik Pedersen
e5e1bcc271 Add plainify template function
To strip away any HTML. May be useful for the .Title in head etc.

People may shoot themself in the foot with this, maybe ...

The replacement function is pretty fast.
2016-03-21 20:27:25 -04:00
Bjørn Erik Pedersen
02e50c0126 Remove duplicate doArithmetic 2016-03-18 23:18:40 +01:00
Cameron Moore
df44b1930a tpl: Send actual values to in from intersect
The `intersect` function uses `in` to avoid adding duplicates to the
resulting set.  We were passing `reflect.Value` items when we should
have been using `Value.Interface()` to send the actual data structure.
This fixes that.

See #1952
2016-03-17 20:09:43 +01:00
Cameron Moore
600558273e tpl: Add missing printf param in t.Errorf call 2016-03-17 20:07:41 +01:00
Cameron Moore
b0326a1c0f tpl: Treat booleans as set in default function
Booleans and `default` don't really make sense together, so we'll always treat
booleans as "set" and return the given value.
2016-03-16 20:05:48 +01:00
Bjørn Erik Pedersen
58802de313 No block support in shortcodes
So no need to check them.
2016-03-15 10:22:08 +01:00
Bjørn Erik Pedersen
3a2a4c3b07 tpl: Make the safeHTML and cousins accept more than strings 2016-03-14 22:27:40 +01:00
Cameron Moore
aedb13b219 tpl: Fix race condition in regexp cache
Protect regular expression cache with a mutex.

Fixes #1973
2016-03-14 16:58:08 +01:00
Bjørn Erik Pedersen
989c7487eb Add emojify to the template func smoke tests 2016-03-12 16:53:39 +01:00
Bjørn Erik Pedersen
cafb784799 Add emoji support
This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use `strings.Replacer` is also plenty fast.

```
BenchmarkEmojiKyokomiFprint-4  	   20000	     86038 ns/op	   33960 B/op	     117 allocs/op
BenchmarkEmojiKyokomiSprint-4  	   20000	     83252 ns/op	   38232 B/op	     122 allocs/op
BenchmarkEmojiStringsReplacer-4	  100000	     21092 ns/op	   17248 B/op	      25 allocs/op
BenchmarkHugoEmoji-4           	  500000	      5728 ns/op	     624 B/op	      13 allocs/op
```

Fixes #1891
2016-03-11 15:51:37 -06:00
Cameron Moore
b8d3651242 tpl: Add replaceRE function
This commit addes a `replaceRE` template function.  Regexp patterns are compiled
once and cached.
2016-03-11 19:59:18 +01:00
Konstantin Kliakhandler
e9008b91fa Allow picking a specific file out of a gist 2016-03-11 18:29:07 +01:00
Bjørn Erik Pedersen
941b4caf57 tpl: Add Copyright reference to the Go authors
Also a reference to the `index`issue in Go's issue tracker.
2016-03-10 21:00:53 +01:00
Cameron Moore
2d0650dbd9 tpl: Add custom index function
This commit adds a custom index template function that deviates from the stdlib
simply by not returning an "index out of range" error if an array, slice or
string index is out of range.  Instead, we just return nil values.  This should
help make the new default function more useful for Hugo users.

Fixes #1949
2016-03-10 17:47:59 +01:00
Cameron Moore
f3f9763afd tpl: Add time note to default func description 2016-03-10 17:47:59 +01:00
Cameron Moore
09c8c17bf0 tpl: fix default function
This commit fixes a few things:

1. `given` is now a variadic parameter so that piping works properly
2. add separate template tests to make sure piping works
3. support time values
4. add more tests of the dfault function
2016-03-10 17:47:59 +01:00
Cameron Moore
ce9ee3cf49 tpl: Add default function 2016-03-10 17:47:59 +01:00
digitalcraftsman
94c3825e5b Add md5 and sha1 template funcs 2016-03-10 11:03:06 +01:00
Bjørn Erik Pedersen
a2abad9677 Add support for Go 1.6 block keyword in templates
NOTE: Needs Go 1.6 to use the new feature.

Fixes #1832
2016-03-10 10:53:54 +01:00
Bjørn Erik Pedersen
973393c99e Create template clone for late template execution
Fixing some breaking blogs on Go 1.6

Fixes #1879
2016-03-09 14:37:58 +01:00
Bjørn Erik Pedersen
435e996c4f Add jsonify template func 2016-03-06 15:01:14 +01:00
Bjørn Erik Pedersen
d774b142e8 Make where accept slice
Fixes #1926
2016-03-06 13:15:07 +01:00
Bjørn Erik Pedersen
3c100cc32c tpl: Unexport the rest of the internal template funcs 2016-03-04 01:00:41 +01:00
Bjørn Erik Pedersen
f6591eca35 tpl: Add some dateFormat testcases with both time and date
See #235
2016-03-03 23:17:35 +01:00
Bjørn Erik Pedersen
e85b821d3e tpl: Fix broken chomp test 2016-03-03 21:24:21 +01:00
Bjørn Erik Pedersen
f223f17c76 tpl: Make chomp return template.HTML 2016-03-03 19:45:23 +01:00
Bjørn Erik Pedersen
daaf4eb330 tpl: Add integration tests for most of the template funcs examples in doc 2016-03-03 19:35:04 +01:00
Bjørn Erik Pedersen
6b922750f3 Revert "Create template clone for late template execution"
This reverts commit 93b04e67f6.
2016-02-28 12:15:33 +01:00
Bjørn Erik Pedersen
93b04e67f6 Create template clone for late template execution
Fixing some breaking blogs on Go 1.6

Fixes #1879
2016-02-28 11:51:51 +01:00
digitalcraftsman
c1f8b188f7 Add template function slice 2016-02-27 17:04:45 +01:00
David Roda
284e959fc4 Close file handle when finished reading file 2016-02-17 21:42:56 +01:00
Bjørn Erik Pedersen
c1e4309516 Clean up the trim template func test 2016-02-16 00:47:14 +01:00
Derek Perkins
bac1ba4655 Fix spelling and go vet errors 2016-02-13 19:08:48 +08:00
Bjørn Erik Pedersen
8fe1070872 Prevent confusing template errors when seq is nil
The common is the `where` func and this:

```
panic: reflect: call of reflect.Value.Type on zero Value [recovered]
	panic: reflect: call of reflect.Value.Type on zero Value
```
2016-02-09 19:02:05 +01:00
Bjørn Erik Pedersen
2b0fad79b7 tpl: Add two more doArithmetic test cases 2016-02-07 23:02:46 +01:00
Bjørn Erik Pedersen
f90b45f7f3 tpl: Test with nil value in first, last, after and shuffle 2016-02-07 21:16:43 +01:00
Bjørn Erik Pedersen
3cc468a82f tpl: Add missing test variants for slicestr 2016-02-07 20:14:24 +01:00
Bjørn Erik Pedersen
b3c2d90ba2 tpl: Add missing substr test variants 2016-02-07 15:22:57 +01:00
Bjørn Erik Pedersen
4dcb63c2f6 tpl: Add highlight test 2016-02-07 15:15:27 +01:00
Bjørn Erik Pedersen
0a8583a451 tpl: Add missing base64 tests 2016-02-07 14:58:23 +01:00
Bjørn Erik Pedersen
0888ddd01f tpl: Add tests for word and rune counting 2016-02-07 14:51:06 +01:00
Bjørn Erik Pedersen
ec49dbb8f5 tpl: Consolidate and complete the Inflect tests 2016-02-07 14:37:04 +01:00
Bjørn Erik Pedersen
1e8b4d9cde Add some missing doArithmetic test cases 2016-02-07 14:20:25 +01:00
Bjørn Erik Pedersen
5995eaaa08 tpl: Unexport all template funcs
There is no good reason to export all the template funcs:

* They're not used outside the templates.
* If usable in other packages, they should be moved (to helpers?)
* They create too broad an interface;
  users of the tpl package don't see the forest for all the trees.
2016-02-07 11:45:45 +01:00
Bjørn Erik Pedersen
0586bf0dc3 Use filepath.Join in locale resource getting 2016-02-07 02:12:33 +01:00
Bjørn Erik Pedersen
8d8e9dde51 Minor cleanup of some of the resource getting code 2016-02-07 02:07:58 +01:00
Bjørn Erik Pedersen
b3a70abe40 tpl: Complete coverage for Humanize 2016-02-07 01:45:37 +01:00
Cameron Moore
45df4596bb tpl: Add humanize func and cleanup lint
Add humanize (inflect.Humanize) to the template funcMap.  Documentation and
tests are included.

Various code cleanups of the template funcs:

- Break pluralize and singularize out into stand-alone funcs.
- Sort the list of funcMap entries.
- Add some minimal godoc comments to all public funcs.
- Fix some issues found by golint and grind.
2016-02-06 15:31:25 +01:00
Bjørn Erik Pedersen
318a984526 Apply gofmt -s 2016-02-06 13:09:52 +01:00
digitalcraftsman
cd36d752a3 Add autostart option to YouTube shortcode 2016-01-29 16:23:41 -05:00
Tatsushi Demachi
3b3e771d61 Check for exported fields in embedded structs
This fixes a exported field check condition in a way described at Go
issue https://golang.org/issue/12367

According to the issue comments, this fix should be safe under Go 1.6.
2016-01-28 19:27:35 +09:00
Bjørn Erik Pedersen
75ba84acbf Add int and string cast template funcs 2016-01-15 23:56:45 +01:00
Bjørn Erik Pedersen
e8ca52e93a Add one more temporary template test for linux/arm
See #1771
2016-01-13 14:26:25 +01:00
Bjørn Erik Pedersen
bca2d38e52 Add temporary template test for linux/arm
See #1771
2016-01-13 14:10:14 +01:00
Ivan Fraixedes
9a6dc6c791 Add embeded template for robots.txt 2016-01-05 23:36:16 +01:00
Daniel Martí
7c5a1fd16b Replace *bytes.Buffer with io.Writer in rendering
Found via github.com/mvdan/interfacer.
2016-01-05 23:32:03 +01:00
Antti Järvinen
9008ac0b55 Rename random to shuffle. Remove count parameteter to simplify its role. Add tests for randomising. 2016-01-04 11:47:37 -05:00
Antti Järvinen
302a6ac701 Add Random function to template functions
Adds Random function to pick N random items from sequence.
2016-01-04 11:38:57 -05:00
Wade Fitzpatrick
ff28120e53 Added async version of Google Analytics internal template 2016-01-04 10:33:18 -05:00
digitalcraftsman
dfa34afd86 Add template funcs countwords and countrunes 2016-01-02 11:00:03 -05:00
Colin Bate
2e92f36890 Add hasPrefix template function. 2016-01-02 10:47:17 -05:00
Bjørn Erik Pedersen
fe7ca7d78c Fix build 2015-12-18 23:23:37 +01:00
Bjørn Erik Pedersen
13d14ab94d Remove "Host:" prefix from Host header
That thould work with Go 1.4.3 according to sources inside Google.
2015-12-18 23:09:50 +01:00
Bjørn Erik Pedersen
dd2ab2820e Correct the strings.Contains syntax in failing test 2015-12-18 16:19:00 +01:00
Bjørn Erik Pedersen
31035f8ad1 Fix remote test on Go 1.4 2015-12-18 16:05:24 +01:00
Bjørn Erik Pedersen
89f8fa586c Set the request Host on http test server
Needed for the remote tests to pass on Go 1.6.

See #1470
2015-12-18 15:52:17 +01:00
Anthony Fok
8509727fe8 Add copyright header to that source files that don’t have one.
See #1646
2015-12-10 15:19:38 -07:00
Tatsushi Demachi
f3c74c9db4 Add boolean value comparison to where tpl function
`where` template function's internal condition check function doesn't
check boolean values and always returns `false` silently.

This adds missing boolean value comparison to the function.
`where Values ".Param.key" true` like clause can be used.

Only "=", "==", "eq", "!=", "<>", "ne" operators are allowed to be used
with a boolean value. If an other operator is passed with it, the
condition check function returns `false` like before.
2015-12-08 05:39:11 +09:00
Bjørn Erik Pedersen
e445c35d6a Fix copyright headers in source files
Still need to add some missing headers and an AUTHORS file.

See #1646
2015-12-07 19:57:01 +01:00
digitalcraftsman
311307c9e4 Add IsNamedParams property in shortcodes 2015-11-24 08:59:32 +01:00
digitalcraftsman
7d31d5f59d Add shortcode for tweets 2015-11-24 08:59:32 +01:00
digitalcraftsman
e03f27ccf8 Add shortcode for github gists 2015-11-24 08:59:32 +01:00