Commit graph

29 commits

Author SHA1 Message Date
Bjørn Erik Pedersen ce524d0b5e Add a page template func
Fixes #9339
2023-02-25 19:53:18 +01:00
Bjørn Erik Pedersen f2946da9e8 Improve error messages, esp. when the server is running
* Add file context to minifier errors when publishing
* Misc fixes (see issues)
* Allow custom server error template in layouts/server/error.html

To get to this, this commit also cleans up and simplifies the code surrounding errors and files. This also removes the usage of `github.com/pkg/errors`, mostly because of https://github.com/pkg/errors/issues/223 -- but also because most of this is now built-in to Go.

Fixes #9852
Fixes #9857
Fixes #9863
2022-05-06 19:43:22 +02:00
Bjørn Erik Pedersen 05b45c35c8 tpl/lang: Handle nil values in lang.Merge 2022-04-23 22:22:50 +02:00
Bjørn Erik Pedersen b80853de90
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
2022-03-17 22:03:27 +01:00
Bjørn Erik Pedersen 08fdca9d93 Add Markdown diagrams and render hooks for code blocks
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`).

We also used this new hook to add support for diagrams in Hugo:

* Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams.
* Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information.

Updates #7765
Closes #9538
Fixes #9553
Fixes #8520
Fixes #6702
Fixes #9558
2022-02-24 18:59:50 +01:00
Joe Mooring bddcfd911c deps: Update github.com/gohugoio/localescompressed v0.14.0 => v0.15.0
Fixes #9446
2022-02-19 11:34:00 +01:00
Joe Mooring 04a3b45db4 Fix description of lang.FormatNumberCustom
It currently refers to itself as a simple alternative, when it should
refer to lang.FormatNumber.
2021-11-01 18:54:43 +01:00
Paul Gottschling a864ffe9ac Clarify "precision" in currency format functions
The documentation of the FormatAccounting and FormatCurrency
functions could be clearer in terms of how the precision param
works. This commit makes it more explicit that adding a precision
of < 2 will not format the return values to include fewer decimals.

Resolves #8858
2021-09-22 20:00:30 +02:00
Salim B d6c8cd7718 Fix lang.FormatPercent description
Successor PR for https://github.com/gohugoio/hugoDocs/pull/1504
2021-08-03 16:56:06 +02:00
Bjørn Erik Pedersen 3a96655592 Reduce binary size vs locale, update to CLDR v36.1
Test building with `go build -ldflags="-s -w"`

Hugo 0.86.2: 46MB
Before this commit: 77MB
After this commit: 54MB

Fixes #8839
Fixes #8841
2021-08-02 19:40:32 +02:00
Bjørn Erik Pedersen 6c70e1f22f Fix error handling for the time func alias
Fixes #8835
2021-08-01 13:39:30 +02:00
Bjørn Erik Pedersen 7907d24ba1
tpl/lang: Add new localized versions of lang.FormatNumber etc.
Fixes #8820
2021-07-29 16:40:06 +02: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
Bjørn Erik Pedersen 97987e5c02 langs/i18n: Upgrade to go-i18n v2
Fixes #5242
2020-09-29 17:48:07 +02:00
Sam Smith 3d9235e8fc tpl: Fix bad rounding in NumFmt
strconv.FormatFloat doesn't round properly sometimes, this adds a
different method of rounding, fixes #7116
2020-06-02 17:20:36 +02:00
Bjørn Erik Pedersen 9e57182705
tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
Cameron Moore 30a7c9ea37 tpl: Add godoc packages comments
Also fix package name in tpl/templates.
2018-11-30 08:56:30 +01:00
Cameron Moore ce264b936c tpl: Add a delimiter parameter to lang.NumFmt
The original implementation of NumFmt did not take into account that the
options delimiter (a space) could be a valid option.  Adding a delim
parameter seems like the simplest, safest, and most flexible way to
solve this oversight in a backwards-compatible way.

Fixes #5260
2018-10-02 17:41:48 +03:00
Cameron Moore f6f22ad944 tpl: Fix golint godoc issues 2018-09-07 08:25:51 +02:00
Bjørn Erik Pedersen ffaec4ca8c
Add a way to merge pages by language
As an example:

```html
{{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }}
```

Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English.

Fixes #4463
2018-03-16 10:10:01 +01:00
Bjørn Erik Pedersen 873a6f1885 Run gofmt to get imports in line vs gohugoio/hugo 2017-06-13 19:12:10 +02:00
Bjørn Erik Pedersen d8717cd4c7 all: Update import paths to gohugoio/hugo 2017-06-13 18:42:45 +02:00
Bjørn Erik Pedersen 1f9e8dcc60 tpl: Make the Namespace func signature explicit
This makes it cleaner and avoids breaking client code, such as the docs helper JSON generator.
2017-05-20 11:34:38 +03:00
Cameron Moore 93b3b13867 tpl/lang: Add NumFmt function
NumFmt formats a number with a given precision using the requested
decimal, grouping, and negative characters.

Fixes #1444
2017-05-18 09:49:20 +03:00
Cameron Moore f69df916df tpl: Add basic tests for all namespace init funcs 2017-05-02 00:07:33 +02:00
Bjørn Erik Pedersen 690b0f8ff5 tpl: Add docshelper for template funcs
And fix some other minor related issues.

Updates #3418
2017-05-01 21:44:15 +02:00
Bjørn Erik Pedersen 0e2260421e tpl: Fix the remaining template funcs namespace issues
See #3042
2017-05-01 15:13:41 +02:00
Bjørn Erik Pedersen c5373efcf0 tpl: Add TemplateFuncsNamespaceRegistry
As a first step to remove the hard ties between `tplimpl` and the different namespace packages.

The `lang` package is used as the first example use case.

See #3042
2017-05-01 15:13:41 +02:00
Cameron Moore de7c32a1a8 tpl: Add template function namespaces
This commit moves almost all of the template functions into separate
packages under tpl/ and adds a namespace framework.  All changes should
be backward compatible for end users, as all existing function names in
the template funcMap are left intact.

Seq and DoArithmatic have been moved out of the helpers package and into
template namespaces.

Most of the tests involved have been refactored, and many new tests have
been written.  There's still work to do, but this is a big improvement.

I got a little overzealous and added some new functions along the way:

- strings.Contains
- strings.ContainsAny
- strings.HasSuffix
- strings.TrimPrefix
- strings.TrimSuffix

Documentation is forthcoming.

Fixes #3042
2017-04-30 10:56:38 +02:00