Commit graph

328 commits

Author SHA1 Message Date
Daniel Atwood ffd9dac421
tpl: Update date logic of opengraph and schema internal templates
* Fix: updated date logic in opengraph template

* Updated date logic in schema template

* Reformatted opengraph and schema

* Wrapped PublishDate and Lastmod in with
2021-02-18 17:51:32 +01:00
Jeremy Epstein 4867cd1dea
tpl/embedded: Exclude pages without Permalink from sitemap 2021-02-06 18:30:09 +01:00
Cameron Moore 241b7483ea tpl: Fix race condition in text template baseof
Copy most of the htmltemplate cloning to the textemplate implementation
in the same function.
2021-01-22 19:25:45 +01:00
Bjørn Erik Pedersen cea1574023
Add Dart Sass support
But note that the Dart Sass Embedded Protocol is still in beta (beta 5), a main release scheduled for Q1 2021.

Fixes #7380
Fixes #8102
2020-12-30 17:32:25 +01:00
Bjørn Erik Pedersen a2d146ec32
tpl: Regenerate templates 2020-12-16 12:20:02 +01:00
Maciej Sawicki d2d493ab5d
tpl: Fix series detection in opengraph
When inside front matter you specified series with spaces,
then the opengraph template wouldn't detect other articles,
because in `.Site.Taxonomies.series` they are stored by 
urlized key.

Example:

```yaml
# in front matter
series:
    - My Series
```

```gohtml
{{/* in a template */}}
{{- $series := index .Site.Taxonomies.series$name }}

{{/* was resolved to */}}
{{- $series := index {'my-series': ...} "MySeries" }}
```
2020-12-16 12:13:30 +01:00
Phil Davis 04b89857e1
all: Fix minor typos 2020-12-16 12:11:32 +01:00
Bjørn Erik Pedersen d90e37e0c6 all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
2020-12-03 13:12:58 +01:00
Andrew Zenk 4fc918e02c
tpl: Add title parameter to YouTube shortcode 2020-12-02 12:53:53 +01:00
Cameron Moore 08e4f9ff9c embedded: Always show page number when 5 pages or less
Fixes #7523
2020-10-16 16:16:49 +02:00
Josh Gerdes edc5c4741c tpl: Add Do Not Track (dnt) option to Vimeo shortcode
Added a Vimeo EnableDNT privacy option to the Hugo config. This will enable the Vimeo 'Do Not Track' flag when either Vimeo shortcode tempalte options are used. When enabled, it will force the Vimeo player to be blocked from tracking any session data, including all cookies and stats.

Fixes #7700
2020-10-02 23:02:38 +02:00
Bjørn Erik Pedersen 4055c12184 Fix some change detection issues on server reloads
* Fix change detection when .GetPage/site.GetPage is used from shortcode
* Fix stale content for GetPage results with short name lookups on server reloads

Fixes #7623
Fixes #7624
Fixes #7625
2020-09-07 21:06:44 +02:00
Kyle Anderson 5f42590144 Remove trailing whitespace and tabs from RSS templates
The rss templates had some tab characters mixed in with the spaces.
Additionally there would end up being trailing whitespace in output
rss feeds, which looks red in git diff.
2020-08-12 09:25:16 +02:00
Joe Mooring bffc4e12fe Revert "Fix ellipsis display logic in pagination template"
This reverts commit 2fa851e650.
2020-08-06 13:42:08 +02:00
Joe Mooring 2fa851e650 Fix ellipsis display logic in pagination template
Closes #7523
2020-07-31 16:08:23 +02:00
Joe Mooring a06c06a5c2 Fix date format in internal schema template
Prior to this change, the offset indicator for dates with positive
offsets was rendered as + instead of +.

Fixes #7495
2020-07-23 15:57:20 +02:00
Bjørn Erik Pedersen c91dbe4ce9 Fix baseof block regression
From Hugo 0.74.0.

Fixes #7478
2020-07-13 20:45:09 +02:00
Remko Tronçon 2fc3380707 Add js.Build asset bundling
Fixes #7321
2020-07-13 10:56:23 +02:00
Bjørn Erik Pedersen 12a65e76df Add openapi3.Unmarshal
Fixes #7442
Fixes #7443
2020-07-06 20:03:36 +02:00
Bjørn Erik Pedersen 42e150fbfa Fix server reload when non-HTML shortcode changes
Fixes #7448
2020-07-03 23:31:51 +02:00
Bjørn Erik Pedersen defd7106bf
tpl: Add debug.Dump
Fixes #3957
2020-07-02 09:04:46 +02:00
Bjørn Erik Pedersen 4a3efea7ef Add support for inline partials
Fixes #7444
2020-07-01 23:10:21 +02:00
Bjørn Erik Pedersen 01e249e97c
Regenerate templates 2020-06-12 11:29:04 +02:00
Joe Mooring 4b560cc119 Beautify HTML generated by pagination template
Fixes #7199.
2020-06-12 11:27:20 +02:00
Daniel Tipping 6205d56b85 Use .Lastmod for og:updated_time
.Lastmod is the time at which the website was most recently updated,
rather than .Date which is the time at which the website content file
was created.
2020-05-07 18:42:20 +02:00
BurtonQin 5146dc614f tpl/tmplimpl/template: Change defer RLock to RUnlock 2020-04-21 13:23:31 +02:00
Bjørn Erik Pedersen ffcb4aeb8e Fix handling of HTML files without front matter
This means that any HTML file inside /content will be treated as a regular file.

If you want it processes with shortcodes and a layout, add front matter.

The defintion of an HTML file here is:

* File with extension .htm or .html
* With first non-whitespace character "<" that isn't a HTML comment.

This is in line with the documentation.

Fixes #7030
Fixes #7028
See #6789
2020-03-09 15:01:55 +01:00
Bjørn Erik Pedersen b0d850321e Fix rebuild logic when editing template using a base template
We have been doing too much work in that case.

Fixes #6968
2020-02-28 14:14:55 +01:00
Bjørn Erik Pedersen d73e37387c
tpl: Adjust the RSS taxonomy logic
See #6909
2020-02-18 17:29:46 +01:00
Bjørn Erik Pedersen aa3e183056
tpl: Fix RSS template for the terms listing
Fixes #6909
2020-02-18 16:55:30 +01:00
Bjørn Erik Pedersen f45cb31728 Fix base template handling with preceding comments
Fixes #6816
2020-01-30 23:44:42 +01:00
Bjørn Erik Pedersen f441f67512 Fix baseof with regular define regression
Fixes #6790
2020-01-23 19:54:06 +01:00
Bjørn Erik Pedersen c6d650c8c8
tpl/tplimpl: Rework template management to get rid of concurrency issues
This more or less completes the simplification of the template handling code in Hugo started in v0.62.

The main motivation was to fix a long lasting issue about a crash in HTML content files  without front matter.

But this commit also comes with a big functional improvement.

As we now have moved the base template evaluation to the build stage we now use the same lookup rules for `baseof` as for `list` etc. type of templates.

This means that in this simple example you can have a `baseof` template for the `blog` section without having to duplicate the others:

```
layouts
├── _default
│   ├── baseof.html
│   ├── list.html
│   └── single.html
└── blog
    └── baseof.html
```

Also, when simplifying code, you often get rid of some double work, as shown in the "site building" benchmarks below.

These benchmarks looks suspiciously good, but I have repeated the below with ca. the same result. Compared to master:

```
name                              old time/op    new time/op    delta
SiteNew/Bundle_with_image-16        13.1ms ± 1%    10.5ms ± 1%  -19.34%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16    13.0ms ± 0%    10.7ms ± 1%  -18.05%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16      46.4ms ± 2%    43.1ms ± 1%   -7.15%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16            52.2ms ± 2%    47.8ms ± 1%   -8.30%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16        77.9ms ± 1%    70.9ms ± 1%   -9.01%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16      43.0ms ± 0%    37.2ms ± 1%  -13.54%  (p=0.029 n=4+4)
SiteNew/Page_collections-16         58.2ms ± 1%    52.4ms ± 1%   -9.95%  (p=0.029 n=4+4)

name                              old alloc/op   new alloc/op   delta
SiteNew/Bundle_with_image-16        3.81MB ± 0%    2.22MB ± 0%  -41.70%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16    3.60MB ± 0%    2.01MB ± 0%  -44.20%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16      19.3MB ± 1%    14.1MB ± 0%  -26.91%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16            70.7MB ± 0%    69.0MB ± 0%   -2.40%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16        37.1MB ± 0%    31.2MB ± 0%  -15.94%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16      17.6MB ± 0%    10.6MB ± 0%  -39.92%  (p=0.029 n=4+4)
SiteNew/Page_collections-16         25.9MB ± 0%    21.2MB ± 0%  -17.99%  (p=0.029 n=4+4)

name                              old allocs/op  new allocs/op  delta
SiteNew/Bundle_with_image-16         52.3k ± 0%     26.1k ± 0%  -50.18%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16     52.3k ± 0%     26.1k ± 0%  -50.16%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16        336k ± 1%      269k ± 0%  -19.90%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16              422k ± 0%      395k ± 0%   -6.43%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16          401k ± 0%      313k ± 0%  -21.79%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16        247k ± 0%      143k ± 0%  -42.17%  (p=0.029 n=4+4)
SiteNew/Page_collections-16           282k ± 0%      207k ± 0%  -26.55%  (p=0.029 n=4+4)
```

Fixes #6716
Fixes #6760
Fixes #6768
Fixes #6778
2020-01-22 09:39:49 +01:00
Bjørn Erik Pedersen 1cf235412f
tpl: Put Go's internal template funcs in Hugo's map
```
name                            old time/op    new time/op    delta
SiteNew/Many_HTML_templates-16    43.4ms ± 0%    42.7ms ± 0%  -1.71%  (p=0.016 n=4+5)

name                            old alloc/op   new alloc/op   delta
SiteNew/Many_HTML_templates-16    17.5MB ± 0%    17.5MB ± 0%    ~     (p=0.690 n=5+5)

name                            old allocs/op  new allocs/op  delta
SiteNew/Many_HTML_templates-16      247k ± 0%      247k ± 0%    ~     (p=0.310 n=5+5)
```

Fixes #6717
2020-01-07 13:18:19 +01:00
Bjørn Erik Pedersen d20ca37005 tpl: Get rid of the custom template truth logic
Fixes #6615
2019-12-18 20:05:22 +01:00
Bjørn Erik Pedersen e625088ef5
Add render template hooks for links and images
This commit also

* revises the change detection for templates used by content files in server mode.
* Adds a Page.RenderString method

Fixes #6545
Fixes #4663
Closes #6043
2019-12-18 11:44:40 +01:00
Bjørn Erik Pedersen a03c631c42
Rework template handling for function and map lookups
This is a big commit, but it deletes lots of code and simplifies a lot.

* Resolving the template funcs at execution time means we don't have to create template clones per site
* Having a custom map resolver means that we can remove the AST lower case transformation for the special lower case Params map

Not only is the above easier to reason about, it's also faster, especially if you have more than one language, as in the benchmark below:

```
name                          old time/op    new time/op    delta
SiteNew/Deep_content_tree-16    53.7ms ± 0%    48.1ms ± 2%  -10.38%  (p=0.029 n=4+4)

name                          old alloc/op   new alloc/op   delta
SiteNew/Deep_content_tree-16    41.0MB ± 0%    36.8MB ± 0%  -10.26%  (p=0.029 n=4+4)

name                          old allocs/op  new allocs/op  delta
SiteNew/Deep_content_tree-16      481k ± 0%      410k ± 0%  -14.66%  (p=0.029 n=4+4)
```

This should be even better if you also have lots of templates.

Closes #6594
2019-12-12 10:04:35 +01:00
Bjørn Erik Pedersen 167c01530b
Create lightweight forks of text/template and html/template
This commit also removes support for Ace and Amber templates.

Updates #6594
2019-12-12 09:59:34 +01:00
Bjørn Erik Pedersen 5f8c2818f1
Deprecate Ace and Amber
Fixes #6609
2019-12-11 08:08:42 +01:00
Max Arnold c91970c08d tpl/tplimpl: Featured and Site.Params image support for Schema 2019-11-26 23:53:43 +01:00
Max Arnold 25a6b33693 tpl/tplimpl: Add support for featured and global image to OpenGraph template 2019-11-26 20:11:53 +01:00
Bjørn Erik Pedersen 96f09659ce
Fix language handling in ExecuteAsTemplate
Fixes #6331
2019-11-26 12:55:00 +01:00
Bjørn Erik Pedersen a3fe5e5e35
Fix Params case handling in the index, sort and where func
This means that you can now do:

```
{{ range where .Site.Pages "Params.MYPARAM" "foo" }}
```
2019-11-22 18:41:50 +01:00
Bjørn Erik Pedersen cd07e6d57b
Fix GetPage Params case issue
Fixes #5946
2019-11-22 18:41:40 +01:00
Zach Bayoff 7b3edc2931 tpl: Add optional "title" attribute to iframe in Vimeo shortcode
Add an optional "title" attribute to the iframe in the vimeo shortcode. If one is not given, the title attribute will default to "vimeo video". It is imperative for iframes to have a non-empty "title" attribute in order to meet WCAG2.0 accessibility guidelines https://www.w3.org/TR/WCAG20-TECHS/H64.
2019-10-12 18:10:14 +02:00
Bjørn Erik Pedersen 329e88db1f Support typed bool, int and float in shortcode params
This means that you now can do:

    {{< vidur 9KvBeKu false true 32 3.14 >}}

And the boolean and numeric values will be converted to `bool`, `int` and `float64`.

If you want these to be  strings, they must be quoted:

    {{< vidur 9KvBeKu "false" "true" "32" "3.14" >}}

Fixes #6371
2019-09-29 23:22:41 +02:00
XhmikosR 34dc06b032 tpl: Add rel="noopener" for external links
This could be a security and performance issue.

See https://developers.google.com/web/tools/lighthouse/audits/noopener
2019-09-21 10:08:47 +02:00
XhmikosR 2b1814ee58 tpl: Remove unneeded space 2019-09-21 10:06:15 +02:00
Jake Jarvis 00297085db tpl: Migrate last shortcodes (YouTube and Vimeo) to HTTPS embeds 2019-08-30 11:55:55 +02:00
Bjørn Erik Pedersen 88d6993612
tpl: Use RegularPages for RSS template
This is in line with how it was in Hugo 0.56.

See #6238
2019-08-17 19:37:14 +02:00
Bjørn Erik Pedersen 564cf1bb11 tpl: Avoid "home page warning" in RSS template
See #6238
2019-08-17 18:50:16 +02:00
Bjørn Erik Pedersen 9e57182705
tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
Christian Muehlhaeuser a93cbb0d6c Simplify code
- Use bytes.Equal instead of bytes.Compare
- Omit range's value where it's unused
2019-08-10 20:10:32 +02:00
Bjørn Erik Pedersen 7ff0a8ee9f Simplify page tree logic
This is preparation for #6041.

For historic reasons, the code for bulding the section tree and the taxonomies were very much separate.

This works, but makes it hard to extend, maintain, and possibly not so fast as it could be.

This simplification also introduces 3 slightly breaking changes, which I suspect most people will be pleased about. See referenced issues:

This commit also switches the radix tree dependency to a mutable implementation: github.com/armon/go-radix.

Fixes #6154
Fixes #6153
Fixes #6152
2019-08-08 20:13:39 +02:00
Bjørn Erik Pedersen 2d1d33673d
tpl: Regenerate templates 2019-08-01 14:05:20 +02:00
Christian Oliff be0d4efc3d tpl: Always load GitHub Gists over HTTPS 2019-08-01 13:57:41 +02:00
XhmikosR f7f549e3a7 Fix assorted typos 2019-08-01 13:55:48 +02:00
Bjørn Erik Pedersen 9f5a92078a
Add Hugo Modules
This commit implements Hugo Modules.

This is a broad subject, but some keywords include:

* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`,  `hugo mod get`,  `hugo mod graph`,  `hugo mod tidy`, and  `hugo mod vendor`.

All of the above is backed by Go Modules.

Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-07-24 09:35:53 +02:00
Bjørn Erik Pedersen b2a3d4644b
tpl/tplimpl: Regenerate templates 2019-06-26 22:39:32 +02:00
Mark Mandel 88c8a15be1 Pagination - do not render href if no next item
When using a html link checker with Hugo, this template consistently causes errors, as it renders `href=""` attributes when next/previous is disabled.

This change makes it so that the `href` attribute is not rendered at all if `HasNext` is false - which is better semantically, and makes link checking far easier.
2019-06-26 22:38:30 +02:00
Bruno Amaral d1cf53f5f4 Remove references to Google+
According to google, this is no longer supported and structured data should be used instead: https://support.google.com/webmasters/answer/6083347?hl=en
2019-05-26 19:24:45 +02:00
Rodolfo Carvalho e22b3f54c3 tpl: Fix internal templates usage of safeHTMLAttr
The `safeHTMLAttr` function operates on a full attribute definition, not
just within the attribute value.

Docs: https://gohugo.io/functions/safehtmlattr/

For `opengraph.html`, run the whole `content` HTML attribute through
`safeHTMLAttr`. That will preserve `+` signs in formatted dates.

For `vimeo_simple.html`, `safeHTMLAttr` was in the context of an
attribute value, thus having no effect. In this case we could replace it
with `safeURL`, but since the code is coming from an API it is safer to
just let Go's template engine sanitize the value as it already does with
`provider_url`.

Fixes #5236 (no need to change Go upstream)
Related to #5246
2019-05-17 16:00:54 +02:00
Bjørn Erik Pedersen 2838d58b1d
i18n: Move the package below /langs
To get fewer top level packages.
2019-05-04 18:25:56 +02:00
Bjørn Erik Pedersen 69a56420ae hugolib: Avoid recloning of shortcode templates
```bash
benchmark                                    old ns/op     new ns/op     delta
BenchmarkSiteNew/Bundle_with_image-4         14572242      14382188      -1.30%
BenchmarkSiteNew/Bundle_with_JSON_file-4     13683922      13738196      +0.40%
BenchmarkSiteNew/Multiple_languages-4        41912231      25192494      -39.89%

benchmark                                    old allocs     new allocs     delta
BenchmarkSiteNew/Bundle_with_image-4         57496          57493          -0.01%
BenchmarkSiteNew/Bundle_with_JSON_file-4     57492          57501          +0.02%
BenchmarkSiteNew/Multiple_languages-4        242422         118809         -50.99%

benchmark                                    old bytes     new bytes     delta
BenchmarkSiteNew/Bundle_with_image-4         3845077       3844065       -0.03%
BenchmarkSiteNew/Bundle_with_JSON_file-4     3627442       3627798       +0.01%
BenchmarkSiteNew/Multiple_languages-4        13963502      7543885       -45.97%
```

Fixes #5890
2019-04-24 12:37:57 +02:00
Bjørn Erik Pedersen 2957795f52 tpl/tplimpl: Handle late transformation of templates
Fixes #5865
2019-04-16 21:24:09 +02:00
Bjørn Erik Pedersen 56550d1e44
hugolib: Fix shortcode namespace issue
Fixes #5863
2019-04-15 18:31:56 +02:00
Bjørn Erik Pedersen 27a8049da7
tpl/tplimpl: Replace deprecated .GetParam usage
Fixes #5834
2019-04-09 16:39:12 +02:00
Bjørn Erik Pedersen 612a06f067 Misc paginator adjustments
* Rewind paginator for server mode
* Add some more related tests.
* Replace the clumsy scratch constructs in internal paginator template with variables

See #5825
2019-04-08 11:02:12 +02:00
Bjørn Erik Pedersen a55640de8e
tpl: Allow the partial template func to return any type
This commit adds support for return values in partials.

This means that you can now do this and similar:

    {{ $v := add . 42 }}
    {{ return $v }}

Partials without a `return` statement will be rendered as before.

This works for both `partial` and `partialCached`.

Fixes #5783
2019-04-02 10:30:24 +02:00
Bjørn Erik Pedersen b5f39d23b8 all: Apply staticcheck recommendations 2019-03-24 16:14:51 +01:00
Bjørn Erik Pedersen d30e845485
Run gofmt -s 2019-03-23 20:15:06 +01:00
Bjørn Erik Pedersen 597e418cb0
Make Page an interface
The main motivation of this commit is to add a `page.Page` interface to replace the very file-oriented `hugolib.Page` struct.
This is all a preparation step for issue  #5074, "pages from other data sources".

But this also fixes a set of annoying limitations, especially related to custom output formats, and shortcodes.

Most notable changes:

* The inner content of shortcodes using the `{{%` as the outer-most delimiter will now be sent to the content renderer, e.g. Blackfriday.
  This means that any markdown will partake in the global ToC and footnote context etc.
* The Custom Output formats are now "fully virtualized". This removes many of the current limitations.
* The taxonomy list type now has a reference to the `Page` object.
  This improves the taxonomy template `.Title` situation and make common template constructs much simpler.

See #5074
Fixes #5763
Fixes #5758
Fixes #5090
Fixes #5204
Fixes #4695
Fixes #5607
Fixes #5707
Fixes #5719
Fixes #3113
Fixes #5706
Fixes #5767
Fixes #5723
Fixes #5769
Fixes #5770
Fixes #5771
Fixes #5759
Fixes #5776
Fixes #5777
Fixes #5778
2019-03-23 18:51:22 +01:00
Bjørn Erik Pedersen e54213f525
tpl/tplimpl: Fix mutex unlock 2019-03-16 09:40:27 +01:00
Bjørn Erik Pedersen 02eaddc2fb
tpl/tplimpl: Fix template truth logic
Before this commit, due to a bug in Go's `text/template` package, this would print different output for typed nil interface values:

```
{{ if .AuthenticatedUser }}User is authenticated!{{ else }}{{ end }}
{{ if not .AuthenticatedUser }}{{ else }}}User is authenticated!{{ end }}
```

This commit works around this by wrapping every `if` and `with` with a custom `getif` template func with truth logic that matches `not`, `and` and `or`.

Those 3 template funcs from Go's stdlib are now pulled into Hugo's source tree and adjusted to support custom zero values, e.g. types that implement `IsZero`.

This means that you can now do:

```
{{ with .Date }}{{ . }}{{ end }}
```

And it would work as expected.

Fixes #5738
2019-03-06 22:52:38 +01:00
Iskander (Alex) Sharipov 7201042946 tpl: Fix strings.HasPrefix args order 2019-02-02 01:26:05 +01:00
Bjørn Erik Pedersen c52045bbb3 Fix some inline shortcode issues
Fixes #5645
Fixes #5653
2019-01-31 19:08:19 +01:00
Elliot Murphy 526b5b1c49 Fix OpenGraph image fallback to site params
Signed-off-by: Elliot Murphy <statik@users.noreply.github.com>
2019-01-25 18:14:10 +01:00
Bjørn Erik Pedersen e1a66c7343 Fix Params case handling in the new site global
Fixes #5615
2019-01-20 12:42:24 +00:00
Cameron Moore 9e4f9e0bb6 tpl: Fix reflect
Fixes #5564
2018-12-28 10:41:46 +01:00
Bjørn Erik Pedersen 64b6b29075 tpl: Fix case handling in cast params
Fixes #5538
2018-12-19 13:19:22 +01:00
Bjørn Erik Pedersen 831d23cb4d Add tpl/site and tpl/hugo
This means that the current `.Site` and ´.Hugo` is available as a globals, so you can do `site.IsServer`, `hugo.Version` etc.

Fixes #5470
Fixes #5467
Fixes #5503
2018-12-06 14:37:25 +01:00
Bjørn Erik Pedersen 89e2716d29
tpl: Regenerate templates 2018-11-27 18:15:55 +01:00
Max Arnold aba2647c15 tpl: Fix whitespace issue
Introduced  in #5276.
2018-11-27 18:15:10 +01:00
Bjørn Erik Pedersen f37c5a2567 tpl: Add "param" shortcode
Fixes #4010
2018-11-27 17:34:03 +01:00
Bjørn Erik Pedersen 1d18eb0574 Add file (line/col) info to ref/relref errors
See #5371
2018-11-01 21:06:35 +01:00
Bjørn Erik Pedersen 3a786a248d tpl: Fix BOM issue in templates
Fixes #4895
2018-10-30 18:12:14 +01:00
Bjørn Erik Pedersen 889aca054a Run gofmt -s 2018-10-24 00:12:32 +02:00
Bjørn Erik Pedersen d1661b823a
hugolib: Continue the file context/line number errors work
See #5324
2018-10-22 20:46:14 +02:00
Bjørn Erik Pedersen 35fbfb19a1
commands: Show server error info in browser
The main item in this commit is showing of errors with a file context when running `hugo server`.

This can be turned off: `hugo server --disableBrowserError` (can also be set in `config.toml`).

But to get there, the error handling in Hugo needed a revision. There are some items left TODO for commits soon to follow, most notable errors in content and config files.

Fixes #5284
Fixes #5290
See #5325
See #5324
2018-10-16 22:10:56 +02:00
Akshay Raj Gollahalli c21e5179ce tpl: Use .Lastmod in embedded schema template
Fixes #5320
2018-10-16 11:52:32 +02:00
Bjørn Erik Pedersen 8e825ddf5b
Revert "tpl: Fix baseof.html in error message"
I need to rethink this.

This reverts commit 646a52a5c5.
2018-10-07 21:08:41 +02:00
Bjørn Erik Pedersen 646a52a5c5
tpl: Fix baseof.html in error message
This fix should also make the template loadin slightly faster, as we avoid to reparse the baseof.html files more than one time.

Fixes #5288
2018-10-06 12:04:29 +02:00
Kaushal Modi 6818170308 Render Markdown in figure shortcode "caption" and "attr" params
Fixes https://github.com/gohugoio/hugo/issues/4406.
2018-10-03 09:55:53 +03:00
Kaushal Modi c5279064df Re-organize the figure shortcode for better readability 2018-10-03 09:55:53 +03:00
Ricardo N Feliciano 4f9c109dc5 tpl/opengraph: Use safeHTMLAttr instead of safeHTML for HTML attributes
Fixes #5236
2018-09-22 00:36:15 +02:00
Cameron Moore f6f22ad944 tpl: Fix golint godoc issues 2018-09-07 08:25:51 +02:00
Bjørn Erik Pedersen b9a503febb
tpl/tplimpl: Make the autogenerated templates collapsed in PRs 2018-08-23 22:03:43 +02:00
Bjørn Erik Pedersen fdff0d3af4 tpl/tplimpl: Fix .Site.Params case regression
Fixes #5094
2018-08-19 14:30:37 +02:00
Steven Allen 3743875778 tpl/tplimpl: Fix compiling Amber templates that import other templates
Without this patch, amber would try to load templates from the OS filesystem
instead of the layouts virtual filesystem.
2018-08-17 10:04:07 +02:00
Bjørn Erik Pedersen 5c5384916e tpl/tplimpl: Reimplement the ".Params tolower" template transformer
All `.Params` are stored lowercase, but it should work to access them `.Page.camelCase` etc. There was, however, some holes in the logic with the old transformer.

This commit fixes that by applying a blacklist instead of the old whitelist logic. `.Param` is a very distinct key. The original case will be kept in `.Data.Params.myParam`, but other than that it will be lowercased.

Fixes #5068
2018-08-14 17:54:48 +02:00
Anthony Fok c09ee78fd2
tpl: Suppress blank lines from opengraph internal template 2018-08-12 12:27:38 -06:00
Bjørn Erik Pedersen 755d1ffe7a
tpl/tmplimpl: Add MIME type to embedded JS
So they get minified correctly.

See #5042
2018-08-06 23:11:53 +02:00
Bjørn Erik Pedersen 0ba19c57f1 tpl/partials: Add templates.Exists
Fixes #5010
2018-07-31 13:28:15 +02:00
Bjørn Erik Pedersen d741064beb Add optional lang as argument to rel/relref
Fixes #4956
2018-07-18 00:07:20 +02:00
Anthony Fok 2b73e89d6d
tpl: Set permission of embedded templates to 0644 2018-07-09 12:57:08 -06:00
Bjørn Erik Pedersen 2b8d907ab7 Add a newScratch template func
Fixes #4685
2018-07-06 17:51:38 +02:00
Bjørn Erik Pedersen dea71670c0
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.

This commit adds

* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.

This means that you can now do this in your templates (or shortcodes):

```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```

This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:

```
HUGO_BUILD_TAGS=extended mage install
```

Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.

The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:

```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```

The transformation funcs above have aliases, so it can be shortened to:

```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```

A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.

Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test

New functions to create `Resource` objects:

* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.

New `Resource` transformation funcs:

* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.

Fixes #4381
Fixes #4903
Fixes #4858
2018-07-06 11:46:12 +02:00
Bjørn Erik Pedersen 91ab455d84
tpl: Remove some "debug info"
See #4881
2018-06-26 11:33:12 +02:00
Bjørn Erik Pedersen ca1e46efb9
tpl: Update internal pagination template to support Bootstrap 4
Fixes #4881
2018-06-26 11:31:46 +02:00
Anthony Fok 3d5928889a
Revert "tpl: Support text/template/parse API change in go1.11"
Go developers have undone the breaking API changes
in the following commit:

commit bedfa4e1c37bd08063865da628f242d27ca06ec4
Author: Daniel Theophanes <kardianos@gmail.com>
Date:   Thu Jun 21 10:41:26 2018 -0700

    text/template/parse: undo breaking API changes

    golang.org/cl/84480 altered the API for the parse package for
    clarity and consistency. However, the changes also broke the
    API for consumers of the package. This CL reverts the API
    to the previous spelling, adding only a single new exported
    symbol.

    Fixes #25968

    Change-Id: Ieb81054b61eeac7df3bc3864ef446df43c26b80f
    Reviewed-on: https://go-review.googlesource.com/120355
    Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
    Reviewed-by: Rob Pike <r@golang.org>
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>

See https://github.com/golang/go/issues/25968

This reverts commit 9f27091e10.

Closes #4784
Fixes #4873
2018-06-23 15:07:52 -06:00
Anthony Fok 9f27091e10 tpl: Support text/template/parse API change in go1.11
Thanks to @rjoleary for the investigation.

Fixes #4784
2018-06-14 08:58:42 +02:00
Bjørn Erik Pedersen 80230f26a3
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.

With this, it helps thinking about a theme as a set of ordered components:

```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```

The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.

So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.

Hugo uses two different algorithms to merge the filesystems, depending on the file type:

* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.

The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are  plans to improve on this and get a URL scheme so this can be resolved automatically.

Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:

* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`

The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.

A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.

Fixes #4460
Fixes #4450
2018-06-10 23:55:20 +02:00
Christian Oliff 2e6712e281 tpl: Always load GA script over HTTPS 2018-06-09 23:47:44 +02:00
Alexandros 65deb72dc4 tplimpl: Remove speakerdeck shortcode
Fixes #4830
2018-06-09 11:13:36 +02:00
Anthony Fok c3115292a7 tpl: Prevent isBaseTemplate() from matching "baseof" in dir
Fixes #4809
2018-06-04 10:09:55 +03:00
Alex 07b96d16e8 Fixes #4798 2018-05-31 18:05:38 +02:00
Alex ceaff7cafc tpl: Remove frameborder attr YT iframe + CSS fixes 2018-05-30 14:06:32 +02:00
Alex b84389c5e0 Fix vimeo_simple thumb scaling 2018-05-30 11:30:28 +02:00
Alexandros 8de5324479 Add vimeo_simple
Fixes #4749
2018-05-30 00:48:36 +02:00
Alex d68367cbe7 fix typo instagram_simple 2018-05-27 11:06:40 +02:00
Bjørn Erik Pedersen 4ed1228d55
Fix GA anonymizeIp order 2018-05-25 16:05:45 +02:00
Bjørn Erik Pedersen a51945ea4b Add no-cookie variants of the Google Analytics templates
The current full set of options for GA is now:

```toml
[privacy]
[privacy.googleAnalytics]
disable = false
respectDoNotTrack = true
anonymizeIP = true
useSessionStorage = true
```

Fixes #4775
2018-05-25 15:56:10 +02:00
Bjørn Erik Pedersen 0bf0e1972d
tpl: Remove the shortcode assets for now
Not in use.
2018-05-25 14:34:40 +02:00
Bjørn Erik Pedersen 1f244b802e
tpl: Adjust instagram_simple margins 2018-05-25 12:38:25 +02:00
Bjørn Erik Pedersen 448081b840
Remove youtube_simple for now
We need to revisit and complete that.

See #4751
2018-05-25 11:16:23 +02:00
Bjørn Erik Pedersen 1f1d955b56
Add anonymizeIP to GA privacy config
See #4751
2018-05-25 10:53:39 +02:00
Bjørn Erik Pedersen ffcf26e68c
Fix broken test 2018-05-24 13:03:23 +02:00
Bjørn Erik Pedersen 9753cb59f1
Support DNT in Twitter shortcode for GDPR
Fixes #4765
2018-05-24 12:25:52 +02:00
Bjørn Erik Pedersen 3bfe8f4be6
tpl: Alias tweet shortode to twitter
See #4765
2018-05-24 11:40:47 +02:00
Bjørn Erik Pedersen 6aa2c38507
Regenerate embedded templates
See #4761
2018-05-23 21:25:04 +02:00
Alexandros 6d69dac9da Fix youtube_simple thumb scaling
Fixes #4761
2018-05-23 21:22:25 +02:00
Bjørn Erik Pedersen 9ad46a2035 Add instagram_simple shortcode
Fixes #4748
2018-05-23 16:52:08 +02:00
Bjørn Erik Pedersen bed7a0faff
Remove the id from youtube_simple
For now, anyway.

See #4751
2018-05-23 10:24:01 +02:00
Bjørn Erik Pedersen 35ccf06dae
Fix some recently broken embedded templates
And add tests for them.

Fixes #4757
2018-05-23 10:03:11 +02:00
Bjørn Erik Pedersen 353148c2bc Move the privacy config into a parent
See #4751
2018-05-22 18:11:03 +02:00
Bjørn Erik Pedersen 14705ecead
tpl: Add another class and an id to youtube_simple
To provide some more styling options.

See #4616
2018-05-22 09:11:34 +02:00
Bjørn Erik Pedersen 69ee6b41e3
Make the simple mode YouTube links schemaless
See #4616
2018-05-21 22:25:04 +02:00
Bjørn Erik Pedersen 88e3568680 Add YouTube shortcode simple mode
Adapted from the work of @onedrawingperday.

See #4616
2018-05-21 21:56:42 +02:00
Bjørn Erik Pedersen 5f24a2c047 Add PrivacyEnhanced mode for YouTube to the GDPR Policy
See #4616
2018-05-21 16:49:00 +02:00
Bjørn Erik Pedersen 710142016b Add RespectDoNotTrack to GDPR privacy policy for Google Analytics
See #4616
2018-05-21 13:16:43 +02:00
Bjørn Erik Pedersen f45b522ebf
tpl/tplimpl: Adjust GA templates
See #4616
2018-05-21 10:21:36 +02:00
Bjørn Erik Pedersen 6789207347 tpl/tplimpl/embedded: Wrap the relevant templates with the privacy policy disable check
See #4616
2018-05-21 00:41:42 +02:00
Bjørn Erik Pedersen c2bb62d63e
tpl/tplimpl: Move README one level up 2018-05-05 11:00:39 +02:00
Bjørn Erik Pedersen 34ad9a4f17
tpl/tplimpl: Extract internal templates
Having them in separate files should make maintainance easier.

When adding new or making changes to the templates:

```bash
mage generate
```

This will get the Go code in sync.

Fixes #4457
2018-05-04 23:12:10 +02:00
Bjørn Erik Pedersen 01b72eb592 tpl: Add path.Split template func 2018-04-15 22:19:12 +02:00
Bjørn Erik Pedersen eb42774e58
Add support for a content dir set per language
A sample config:

```toml
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true

[Languages]
[Languages.en]
weight = 10
title = "In English"
languageName = "English"
contentDir = "content/english"

[Languages.nn]
weight = 20
title = "På Norsk"
languageName = "Norsk"
contentDir = "content/norwegian"
```

The value of `contentDir` can be any valid path, even absolute path references. The only restriction is that the content dirs cannot overlap.

The content files will be assigned a language by

1. The placement: `content/norwegian/post/my-post.md` will be read as Norwegian content.
2. The filename: `content/english/post/my-post.nn.md` will be read as Norwegian even if it lives in the English content folder.

The content directories will be merged into a big virtual filesystem with one simple rule: The most specific language file will win.
This means that if both `content/norwegian/post/my-post.md` and `content/english/post/my-post.nn.md` exists, they will be considered duplicates and the version inside `content/norwegian` will win.

Note that translations will be automatically assigned by Hugo by the content file's relative placement, so `content/norwegian/post/my-post.md` will be a translation of `content/english/post/my-post.md`.

If this does not work for you, you can connect the translations together by setting a `translationKey` in the content files' front matter.

Fixes #4523
Fixes #4552
Fixes #4553
2018-04-02 08:06:21 +02:00
Bjørn Erik Pedersen 0602135fd4
Make ge, le etc. work with the Hugo Version number
This means that you can do something ala:

```html
{{ if ge .Hugo.Version "0.36" }}Reasonable new Hugo version!{{ end }}
```

The intented use is feature toggling, but please note that it will take some time and Hugo versions until this can be trusted. It does not work in older Hugo versions.

Fixes #4443
2018-02-22 09:15:12 +01:00
Kaushal Modi 2e95ec6844 Add "target" and "rel" parameters to figure shortcode
Also:

- Remove unnecessary space from `figure` tag if no class is specified.
  - Update related tests.
- Add test cases for the changes made to the figure shortcode.
- Document the newly added target and rel parameters
- Add more detail to the documentation of all figure shortcode parameters.
2018-02-09 22:27:58 +01:00
Kaushal Modi 76d38d5e53 Use more canonical "twitter:image" property, not "twitter:image:src"
This change is made in the "twitter_cards" internal template.

References:

- https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary-card-with-large-image
- https://twittercommunity.com/t/twitter-image-src-or-twitter-image/16085/7
2018-02-09 20:27:09 +01:00
Cameron Moore 084cf4191b tpl: Ensure site templates can override theme templates
The tplimpl package was misusing the TemplateLookupDescriptor.WorkingDir
field from the output package. By incorrectly setting it to the theme
directory instead of the site root, the user is unable to override theme
templates in some situations.

Fixes #3505
2018-02-05 08:38:04 +01:00