Commit graph

104 commits

Author SHA1 Message Date
Bjørn Erik Pedersen
8f60c0c1ec livereloadinject: Save some allocations
As suggested by @DominoPivot

```
name                 old time/op    new time/op    delta
LiveReloadInject-10    1.11µs ± 2%    1.04µs ± 2%   -6.45%  (p=0.029 n=4+4)

name                 old alloc/op   new alloc/op   delta
LiveReloadInject-10    1.23kB ± 0%    0.89kB ± 0%  -27.69%  (p=0.029 n=4+4)

name                 old allocs/op  new allocs/op  delta
LiveReloadInject-10      12.0 ± 0%      10.0 ± 0%  -16.67%  (p=0.029 n=4+4)
```
2023-10-29 18:37:05 +01:00
Domino Goupil
9dc608084b livereloadinject: Use more robust injection method 2023-10-29 18:37:05 +01:00
Bjørn Erik Pedersen
b8fbd4a578
transform/livereloadinject: Add benchmark 2023-10-29 17:50:55 +01:00
Bjørn Erik Pedersen
7c9fada778 Replace the old log setup, with structured logging etc.
Fixes #11124
2023-06-18 13:03:04 +02:00
Oleksandr Redko
d453c12742 Replace deprecated ioutil with io and os
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
2023-03-01 16:28:43 +01:00
JB
01ebb6e304
Don't use self-closing generator tag 2022-10-14 12:16:53 +02:00
satotake
b017f7cb01 livereload: Inject script without head or body tag
Currently, Hugo does not inject `livereload` script if html does not contain `<head>` or `<body>`. This sometimes happens if you create new sites without `theme` and it is hard to catch the cause soon.

This PR:

* Inject livereload script even if html does not include `<head>`, `<body>`, or `<html>`
    - Modern browsers execute scripts even if they are outside `<html>`
    - Some js frameworks (confirmed with vite) inject HRM script without `<html>` tag
* Append warning script to html if `<head>` or `<body>` is not in html
* Fix bug that livereload cannot be appended to the tags with attrs

Close #10105
2022-08-07 18:34:01 +02:00
Bjørn Erik Pedersen
fc9f315d86 Improve SASS errors
Fixes #9897
2022-05-15 20:25:25 +02:00
Bjørn Erik Pedersen
4b189d8fd9 postcss: Fix import error handling
Note that we will now fail if `inlineImports` is enabled and we cannot resolve an import.

You can work around this by either:

* Use url imports or imports with media queries.
* Set `skipInlineImportsNotFound=true` in the options

Also get the argument order in the different NewFileError* funcs in line.

Fixes #9895
2022-05-15 20:25:25 +02: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
b80853de90
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
2022-03-17 22:03:27 +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
sth
0ad378b09c
Use --baseURL path for live-reload URL
Fixes #6595
2020-12-02 12:52:26 +01:00
Ralph Slooten
4b430d456a Encode & in livereload injected code 2020-09-09 22:09:40 +02:00
Helder Pereira
145b3fcce3 Fix aliases with relativeURLs 2020-06-14 14:08:41 +02:00
Bjørn Erik Pedersen
b3f0674b80
transform/livereloadinject: Add defer to livereload script tag
In #6821 we moved the loading from end of body to head to make Turbolinks and similar work.

This commit adds a defer attribute to avoid page parse blocking.
2020-01-31 08:15:22 +01:00
Bjørn Erik Pedersen
ef78a0d18a
transform/livereloadinject: Don't use document.write to inject livereload
I suspect the person who originally implemented it saw examples using location.host etc. to build the URL.

We have all that information ready at build (static) time.

Fixes #6507
2020-01-31 08:02:53 +01:00
Bjørn Erik Pedersen
8f08cdd0ac transform/livereloadinject: Inject livereload script right after head if possible
We used to insert the livereload script right before the closing body.

This dord  not work when combined with tools such as Turbolinks.

This commit changes it So we try to inject the script as early as possible.

Fixes #6821
2020-01-29 21:12:07 +01:00
Bjørn Erik Pedersen
9e57182705
tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
HyeonGyu Lee
a843ca53b5 transform/urlreplacers: Cache the next position of urlreplacer.prefix
Improved performance due to `bytes.Index` repeated calls

Fixes #5942
2019-08-06 17:46:20 +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
2fc0abd22a
Fix livereload for @import case
Fixes #6106
2019-07-22 13:54: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
Berin Larson
c154c2f7b2 Rewrite relative action URLS
Fixes #5701
2019-02-26 11:31:34 +01:00
Bjørn Erik Pedersen
f7691fe965 transform/urlreplacers: Simplify implementation 2018-12-17 19:17:56 +01:00
Bjørn Erik Pedersen
efe0b4e5c0 transform/urlreplacers: Support unquoted URLs in canonifyURLs replacer
Fixes #5529
2018-12-17 19:17:56 +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
789ef8c639
Add support for minification of final output
Hugo Pipes added minification support for resources fetched via ´resources.Get` and similar.

This also adds support for minification of the final output for supported output formats: HTML, XML, SVG, CSS, JavaScript, JSON.

To enable, run Hugo with the `--minify` flag:

```bash
hugo --minify
```

This commit is also a major spring cleaning of the `transform` package to allow the new minification step fit into that processing chain.

Fixes #1251
2018-08-06 19:58:41 +02:00
Bjørn Erik Pedersen
a6b1eb1e91
transform: Reduce allocation in the benchmark itself 2018-08-05 17:27:16 +02:00
Bjørn Erik Pedersen
27110133ff
transform: Simplify the 0 transformer case 2018-08-05 11:24:16 +02:00
Jorin Vogel
81c13171a9 Add some missing doc comments
As pointed out by the linter, some exported functions and types are
missing doc comments.
The linter warnings have been reduced from 194 to 116.
Not all missing comments have been added in this commit though.
2017-08-03 15:57:51 +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
7f6430d84d Automate the Hugo release process
This commit adds a work flow aroung GoReleaser to get the Hugo release process automated and more uniform:

* It can be run fully automated or in two steps to allow for manual edits of the relase notes.
* It supports both patch and full releases.
* It fetches author, issue, repo info. etc. for the release notes from GitHub.
* The file names produced are mainly the same as before, but we no use tar.gz as archive for all Unix versions.
* There isn't a fully automated CI setup in place yet, but the release tag is marked in the commit message with "[ci deploy]"

Fixes #3358
2017-04-24 11:08:56 +02:00
Bjørn Erik Pedersen
c4a1165587 all: Handle all errors
As reported by `errcheck`.
2017-04-06 20:35:26 +02: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
3739871f1e transform: Simplify 2016-11-23 18:42:47 +01:00
Bjørn Erik Pedersen
0cd0adda20 transform: Return any read or write error from Apply 2016-11-04 00:44:49 +01:00
Bjørn Erik Pedersen
223073c6fd transform: Add missing GoDoc 2016-07-06 23:23:44 +02:00
Dragos Plesca
7e08d23eeb transform: Explicitly bind LiveReload to server port
If hugo server is run on port 80 or 443, LiveReload does not
correctly bind to the same port, instead using port 35729.
This commit adds functionality to inform LiveReload of the
correct port to bind to.

See https://github.com/livereload/livereload-js/issues/16

Partially contributed by Jeff Minard (@chuyskywalker).

Fixes #2205
2016-06-30 16:47:56 -06:00
Cameron Moore
e3b162ccc6 transform: Don't use helpers.StringToReader 2016-06-25 18:02:07 -05:00
Cameron Moore
e2aea65170 helpers: Remove ToReader funcs
Remove StringToReader and BytesToReader in favor of using the stdlib directly.
2016-06-25 17:57:05 -05:00
Bjørn Erik Pedersen
a7f51703c4 Add Hugo generator tag to home page if not present
Fixes #2182
2016-06-04 21:55:56 -04:00
Bjørn Erik Pedersen
944090722e transform: Group vars and consts in chain_test 2016-03-23 21:55:14 +01:00
Bjørn Erik Pedersen
c7869fd772 transform: Clean up the var naming mess in chain_test 2016-03-23 20:03:13 +01:00
Bjørn Erik Pedersen
626874b94c transform: Golint fixes 2016-03-23 09:35:50 +01:00
Bjørn Erik Pedersen
70739c972e Remove unnecessary type conversions 2016-03-14 20:35:50 +01:00
Bjørn Erik Pedersen
f6c3ca8b2a transform: Remove unused code 2016-03-14 15:46:20 +01:00
Bjørn Erik Pedersen
b21d280c67 transform: Complete test statement coverage
"coverage: 100.0% of statements"
2016-02-06 20:50:26 +01:00