Commit graph

196 commits

Author SHA1 Message Date
Joe Mooring
09eb822822 hugolib: Display server address after each rebuild
Closes #12359
2024-04-13 22:16:00 +02:00
Ville Skyttä
a67650b6f7 completion: Improve existing argument completions, add many more
Do not offer filenames to arguments not taking one, complete arguments
of options taking resource kinds, directory names, --logLevel, release
--step, config and new --format.

As an internal refactoring, use higher level functions to set flag
completions.  SetAnnotation works, but is more verbose than
alternatives, and uses bash specific wording.

While at it, move setting completions next to flag definitions
consistently.

Remove superfluous --destination completer setting, which is already
set elsewhere.
2024-04-11 15:34:26 +02:00
Christian Oliff
17765a7451
all: Typo fixes 2024-04-11 09:23:17 +02:00
Joe Mooring
dc6a292133 common/hugo: Rename IsMultiHost and IsMultiLingual
hugo.IsMultiHost => hugo.IsMultihost
hugo.IsMultiLingual => hugo.IsMultilingual

Closes #12232
2024-03-13 17:34:42 +02:00
Andreas Deininger
ada3fceea8 docs: Fix hyphens and grammar in synopsis of command 'hugo server' 2024-03-07 14:03:49 +01:00
Bjørn Erik Pedersen
621194a319 Fix dart sass import regression
Fixes #12072
2024-02-20 17:00:32 +01:00
Bjørn Erik Pedersen
bd0200da6e
commands: Remove unused memstats flag 2024-02-05 19:06:27 +01:00
Bjørn Erik Pedersen
a80c3021ba
source: Remove unused Filesystem struct 2024-02-05 15:03:03 +01:00
Bjørn Erik Pedersen
c37bf19c89
commands: Revert the recent changes that allowed profiling on server rebuilds
There have been indications that this may freeze the server.
2024-02-05 14:27:35 +01:00
Bjørn Erik Pedersen
9c6d377872 commands: Make the server flag --renderToDisk into --renderToMemory (note)
Fixes #11987
2024-02-05 14:04:17 +01:00
Bjørn Erik Pedersen
2873324898 Misc resource fixes/improvements
* Add --pprof flag to server to enable profile debugging.
* Don't cache the resource content, it seem to eat memory on bigger sites.
* Keep --printMemoryUsag running in server

Fixes #11974
2024-02-02 18:46:23 +01:00
Bjørn Erik Pedersen
7285e74090
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaning
There are some breaking changes in this commit, see #11455.

Closes #11455
Closes #11549

This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build.

The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate.

A list of the notable new features:

* A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server.
* A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently.
* You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs.
We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections).
Memory Limit
* Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory.

New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively.

This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive):

Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get
Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers.
Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds.

Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role).

Fixes #10169
Fixes #10364
Fixes #10482
Fixes #10630
Fixes #10656
Fixes #10694
Fixes #10918
Fixes #11262
Fixes #11439
Fixes #11453
Fixes #11457
Fixes #11466
Fixes #11540
Fixes #11551
Fixes #11556
Fixes #11654
Fixes #11661
Fixes #11663
Fixes #11664
Fixes #11669
Fixes #11671
Fixes #11807
Fixes #11808
Fixes #11809
Fixes #11815
Fixes #11840
Fixes #11853
Fixes #11860
Fixes #11883
Fixes #11904
Fixes #7388
Fixes #7425
Fixes #7436
Fixes #7544
Fixes #7882
Fixes #7960
Fixes #8255
Fixes #8307
Fixes #8863
Fixes #8927
Fixes #9192
Fixes #9324
2024-01-27 16:28:14 +01:00
Oleksandr Redko
274852bcf2 all: Format files with gofmt 2023-10-05 14:45:55 +02:00
ilmari-lauhakangas
525bed9919
commands: Print language code after web server address info 2023-09-11 11:38:24 +02:00
Oleksandr Redko
2589b1295c
commands: Replace deprecated ioutil with os 2023-07-28 10:23:20 +02:00
Bjørn Erik Pedersen
5bd22ba85f commands: Delay server builds after the watcher is set up
See #11264
2023-07-19 19:50:37 +02: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
Bjørn Erik Pedersen
5446900dee
commands: Update CLI docs vs server and production
Fixes #11067
2023-06-05 11:53:14 +02:00
Bjørn Erik Pedersen
cf38c73f53
commands: Add TLS/HTTPS support to hugo server
* commands: Add TLS/HTTPS support to hugo server

The "auto cert" handling in this PR is backed by mkcert (see link below).

To get this up and running on a new PC, you can:

```
hugo server trust
hugo server --tlsAuto
```

When `--tlsAuto` (or `--tlsCertFile` and `--tlsKeyFile`) is set and no `--baseURL` is provided as a flag, the server is
started with TLS and `https` as the protocol.

Note that you only need to run `hugo server trust` once per PC.

If you already have the key and the cert file (e.g. by using mkcert directly), you can do:

```
hugo server --tlsCertFile mycert.pem --tlsKeyFile mykey.pem
```

See https://github.com/FiloSottile/mkcert

Fixes #11064
2023-06-05 09:53:53 +02:00
Oleksandr Redko
4c46f9400b all: Replace deprecated ioutil with io and os 2023-06-01 17:52:21 +02:00
Bjørn Erik Pedersen
43f1282e73 commands: Reinstate some of the removed build flags (e.g. --theme) to new and mod
Fixes #11018
2023-05-28 12:55:44 +02:00
Bjørn Erik Pedersen
8f293a1855 Fix --renderStaticToDisk regression
Fixes #11026
2023-05-27 16:56:54 +02:00
Bjørn Erik Pedersen
231374a1fa Fix regression when loading config -e is empty or HUGO_ENV or HUGO_ENVIRONMENT is set
Fixes #11013
2023-05-24 16:39:31 +02:00
Bjørn Erik Pedersen
9a235d0afc Fix regression with site.IsServer when not running a server
Fixes #11006
2023-05-24 12:42:56 +02:00
Bjørn Erik Pedersen
0a51dfac9e commands: Fix data race
By wrapping all use of the shared config in a lock.

Updates #10953
2023-05-19 16:34:22 +02:00
Bjørn Erik Pedersen
834b3d7e41
Fix some recently introduced error handling issues
Updates #10953
2023-05-18 12:47:23 +02:00
Bjørn Erik Pedersen
8a69ccbb00 commands: Improve the common build flag handling
Updates #10947
2023-05-17 22:13:29 +02:00
Bjørn Erik Pedersen
5251f015bf Re-establish all the server flags
Updates #10947
2023-05-17 22:13:29 +02:00
Bjørn Erik Pedersen
241b21b0fd Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
2023-05-16 18:01:29 +02:00
Oleksandr Redko
36ce3a4a9d Correct typos in Go comments 2023-03-02 16:32:32 +01:00
Bjørn Erik Pedersen
ce524d0b5e Add a page template func
Fixes #9339
2023-02-25 19:53:18 +01:00
Bjørn Erik Pedersen
1477d0ba90 commands: Fix server url rewrites (http status 200)
Broken by me in Hugo 0.103.0 it seems. A little bit mysterious as it has worked for me after that, but started to fail just
recently.

Closes #10668
2023-01-31 12:42:31 +01:00
Bjørn Erik Pedersen
f3560aa0e1 server: Fix 404 redirects on Windows
Fixes #10314
2022-09-23 13:07:56 +02:00
Bjørn Erik Pedersen
6be6752c8a server: Fix redirects when file path contains bytes > 0x80
Fixes #10287
2022-09-18 15:16:11 +02:00
Bjørn Erik Pedersen
a5cda5ca4d server: Add 404 support 2022-09-14 14:25:33 +02:00
Paul van Brouwershaven
c7d5f9f067
resources: Register MediaTypes before build
Fixes #9971
2022-06-03 21:37:50 +02:00
Bjørn Erik Pedersen
2f9eac480f server: Fix multihost crash
As introduced in v0.99.0.

Fixes #9901
2022-05-18 11:10:04 +02:00
Bjørn Erik Pedersen
657d1a2d95
server: Refresh the error template
We cannot cache it forever, as that will not allow the end user to edit and preview it.
2022-05-16 09:24:30 +02:00
Bjørn Erik Pedersen
87a22eb6d6 server: Fix SIGINT handling after loading bad configuration
Also fix the config error messages.

Fixes #9664
2022-05-15 22:58:05 +02:00
Bjørn Erik Pedersen
fc9f315d86 Improve SASS errors
Fixes #9897
2022-05-15 20:25:25 +02:00
Bjørn Erik Pedersen
5c96bda70a
errors: Misc improvements
* Redo the server error template
* Always add the content file context if relevant
* Remove some now superflous error string matching
* Move the server error template to _server/error.html
* Add file context (with position) to codeblock render blocks
* Improve JS build errors

Fixes #9892
Fixes #9891
Fixes #9893
2022-05-14 13:40:56 +02:00
Bjørn Erik Pedersen
51f08b0b6a Revise the use of htime.Since/htime.Now
We cannot (also, it doesn't add any value)  use that when the `clock` is set,

* To measure time (before that global is set)
* To compare file timestamps re cache eviction

Fixes #9868
2022-05-09 14:18:40 +02:00
Bjørn Erik Pedersen
35c88a7f90 Use configured timeZone for the clock
And some other related adjustments.

Updates #8787
2022-05-08 16:56:26 +02:00
satotake
e77ca3c105 Add clock cli flag
Close #8787
2022-05-08 16:56:26 +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
d070bdf10f
Rework the Destination filesystem to make --renderStaticToDisk work
See #9626
2022-04-08 13:26:17 +02:00
Bjørn Erik Pedersen
b08193971a
Revert "Revert "Some minor adjustments to the new static filesystem logic""
This reverts commit 5ef8a9f32c.
2022-04-08 13:26:17 +02:00
Bjørn Erik Pedersen
0a56f2af4e
Revert "Revert "Allow rendering static files to disk and dynamic to memory in server mode""
This reverts commit 64b7b7a897.
2022-04-08 13:26:16 +02:00
Bjørn Erik Pedersen
9539069f5e commands: Improve server startup to make tests less flaky
Do this by announcing/listen on the local address before we start the server.
2022-03-21 09:32:35 +01:00
Bjørn Erik Pedersen
b80853de90
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
2022-03-17 22:03:27 +01:00