summaryrefslogtreecommitdiffstats
path: root/helpers
AgeCommit message (Collapse)Author
2023-12-18all: Remove unused codeBjørn Erik Pedersen
Using x/tools/cmd/deadcode
2023-11-16helpers: Fix TrimShortHTML used by markdownify and RenderStringJoe Mooring
Closes #11698
2023-10-26Revise the deprecation loggingBjørn Erik Pedersen
This introduces a more automatic way of increasing the log levels for deprecation log statements based on the version it was deprecated. The thresholds are a little arbitrary, but * We log INFO for 6 releases * We log WARN for another 6 releases * THen ERROR (failing the build) This should give theme authors plenty of time to catch up without having the log filled with warnings.
2023-10-24markdown: Pass emoji codes to yuin/goldmark-emojiJoe Mooring
Removes emoji code conversion from the page and shortcode parsers. Emoji codes in markdown are now passed to Goldmark, where the goldmark-emoji extension converts them to decimal numeric character references. This disables emoji rendering for the alternate content formats: html, asciidoc, org, pandoc, and rst. Fixes #7332 Fixes #11587 Closes #11598
2023-09-24Add $image.ProcessBjørn Erik Pedersen
Which supports all the existing actions: resize, crop, fit, fill. But it also allows plain format conversions: ``` {{ $img = $img.Process "webp" }} ``` Which will be a simple re-encoding of the source image. Fixes #11483
2023-08-04testing: Write test caches to /tmpBjørn Erik Pedersen
Fixes #11327
2023-07-27Use os.UserCacheDir as first fallback if cacheDir is not setBjørn Erik Pedersen
We will now try 1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`) 2. if on Netlify we use `/opt/build/cache/hugo_cache/` 3. os.UserCacheDir 4. A temp dir Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS, which this commit tries to fix. This should also make it easier to locate the Hugo cache: >UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own application-specific subdirectory within this one and use that. > >On Unix systems, it returns $XDG_CACHE_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache. > >If the location cannot be determined (for example, $HOME is not defined), then it will return an error. Fixes #11286 Fixes #11291
2023-07-08Fix defaultContentLanguageInSubdir with only 1 languageBjørn Erik Pedersen
Fixes #10064
2023-07-05Add titleCaseStyle none and firstupperBjørn Erik Pedersen
Fixes #11204
2023-06-19helpers: Remove superflous formatting flag in deprecation warningsBjørn Erik Pedersen
2023-06-19all: Fix typos in function names and commentsOleksandr Redko
2023-06-18Replace the old log setup, with structured logging etc.Bjørn Erik Pedersen
Fixes #11124
2023-06-12cache: Set default cache path based on $USERErica Mays
Change the default cache directory to `$TMPDIR/hugo_cache_$USER`, so that multi-user systems do not have caches that interfere with each other. The other cache-choosing logic (e.g. Netlify exceptions, configuration options) are not affected. Fixes #7391
2023-06-12helpers: Avoid url.Parse in RelURL and AbsURL if we canBjørn Erik Pedersen
``` RelURL-10 159ns ± 5% 18ns ± 4% -88.89% (p=0.029 n=4+4) AbsURL/relurl-10 532ns ± 0% 537ns ± 0% +1.09% (p=0.029 n=4+4) AbsURL/absurl-10 142ns ± 0% 4ns ± 3% -96.91% (p=0.029 n=4+4) name old alloc/op new alloc/op delta RelURL-10 144B ± 0% 0B -100.00% (p=0.029 n=4+4) AbsURL/relurl-10 544B ± 0% 544B ± 0% ~ (all equal) AbsURL/absurl-10 144B ± 0% 0B -100.00% (p=0.029 n=4+4) name old allocs/op new allocs/op delta RelURL-10 1.00 ± 0% 0.00 -100.00% (p=0.029 n=4+4) AbsURL/relurl-10 10.0 ± 0% 10.0 ± 0% ~ (all equal) AbsURL/absurl-10 1.00 ± 0% 0.00 -100.00% (p=0.029 n=4+4) ```
2023-06-12Adjust benchmarksBjørn Erik Pedersen
2023-06-12Adjust benchmarkBjørn Erik Pedersen
2023-06-12Add BenchmarkAbsURLBjørn Erik Pedersen
2023-06-12helpers: Improve schema detection when creating relative URLsJoe Mooring
Fixes #11080
2023-06-12helpers: Add a basic benchmark for RelURLBjørn Erik Pedersen
2023-05-18all: Fix comments for exported functions and packagesOleksandr Redko
2023-05-16helpers: simplify path tests with T.TempDirOleksandr Redko
2023-05-16Create a struct with all of Hugo's config optionsBjørn Erik Pedersen
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-03-14commands: Fix data race in testBjørn Erik Pedersen
Note that this is a test fix only.
2023-03-02Correct typos in Go commentsOleksandr Redko
2023-03-01Replace deprecated ioutil with io and osOleksandr Redko
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
2023-02-22Adjust tests for GO 1.20Bjørn Erik Pedersen
Updates #10691
2023-01-25Only invoke a given cached partial onceBjørn Erik Pedersen
Note that this is backed by a LRU cache (which we soon shall see more usage of), so if you're a heavy user of cached partials it may be evicted and refreshed if needed. But in most cases every partial is only invoked once. This commit also adds a timeout (the global `timeout` config option) to make infinite recursion in partials easier to reason about. ``` name old time/op new time/op delta IncludeCached-10 8.92ms ± 0% 8.48ms ± 1% -4.87% (p=0.016 n=4+5) name old alloc/op new alloc/op delta IncludeCached-10 6.65MB ± 0% 5.17MB ± 0% -22.32% (p=0.002 n=6+6) name old allocs/op new allocs/op delta IncludeCached-10 117k ± 0% 71k ± 0% -39.44% (p=0.002 n=6+6) ``` Closes #4086 Updates #9588
2022-12-19helpers: Allow at signs in UnicodeSanitize (note)Joe Mooring
Closes #10548
2022-12-14Also consider wrapped errors when checking for file IsNotExist errorsBjørn Erik Pedersen
Fixes #10534
2022-06-14deps: Udpate to github.com/alecthomas/chroma/v2Bjørn Erik Pedersen
Fixes #9932 Fixes #9931
2022-06-13Fix relURL with leading slash when baseURL includes a subdirectoryBjørn Erik Pedersen
Fixes #9994
2022-05-25Fix Plainify edge casesBjørn Erik Pedersen
This commit replaces the main part of `helpers.StripHTML` with Go's implementation in its html/template package. It's a little slower, but correctness is more important: ```bash BenchmarkStripHTMLOld-10 680316 1764 ns/op 728 B/op 4 allocs/op BenchmarkStripHTMLNew-10 384520 3099 ns/op 2089 B/op 10 allocs/op ``` Fixes #9199 Fixes #9909 Closes #9410
2022-05-25Add resources.CopyBjørn Erik Pedersen
Implemented by most Resource objects, but not Page (for now). Fixes #9313
2022-05-06Improve error messages, esp. when the server is runningBjørn Erik Pedersen
* 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-04-08Rework the Destination filesystem to make --renderStaticToDisk workBjørn Erik Pedersen
See #9626
2022-03-21commands: Improve server startup to make tests less flakyBjørn Erik Pedersen
Do this by announcing/listen on the local address before we start the server.
2022-03-17all: gofmt -w -r 'interface{} -> any' .Bjørn Erik Pedersen
Updates #9687
2022-02-24Add Markdown diagrams and render hooks for code blocksBjørn Erik Pedersen
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-23helpers: Allow hyphens in UnicodeSanitizeCameron Moore
Improve handling of existing hyphens in input to UnicodeSanitize. This commit accomplishes three things: 1. Explicitly allow hyphens 2. Avoid appending a hyphen if a preceeding hyphen is found 3. Avoid prepending a hyphen if a trailing hyphen is found Fixes #7288
2022-01-27general: Fix issue causing log threads to hang indefinitely when print() panicsEphex2
The function printIfNotPrinted() defined for DistinctLogger unlocked the mutex within the logger only after the print() function ran. If print panics, the mutex would stay locked and future attempts to read or write from the logger mutex would cause the goroutine to hang indefinitely. Deferred the unlocking of the mutex to prevent this. Also, put l.m[key] before the print() call since this will prevent another bug where the same warning potentially gets logged multiple times if the print() call panics. Fixes #9380
2022-01-16helpers: Remove unused codeBjørn Erik Pedersen
2022-01-06Add --panicOnWarning flagBjørn Erik Pedersen
Fixes #9357 Fixes #9359
2022-01-04Remove mmarkBjørn Erik Pedersen
Closes #9350
2021-12-16Add some basic security policies with sensible defaultsBjørn Erik Pedersen
This ommmit contains some security hardening measures for the Hugo build runtime. There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers". For `asciidoctor` and some others we use Go's `os/exec` package to start a new process. These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off. You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do. The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all. ```toml [security] enableInlineShortcodes = false [security.exec] allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$'] osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$'] [security.funcs] getenv = ['^HUGO_'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*'] ```
2021-11-17helpers: Make UniqueStringsReuse allocation freeBjørn Erik Pedersen
This should be faster for all of our use cases (small string slices), but more important, it makes UniqueStringsReuse allocation free. ```bash name old time/op new time/op delta UniqueStrings/Safe-16 776ns ± 0% 305ns ± 0% -60.68% (p=0.029 n=4+4) UniqueStrings/Reuse_slice-16 621ns ± 3% 174ns ± 0% -72.01% (p=0.029 n=4+4) UniqueStrings/Reuse_slice_sorted-16 319ns ± 4% 313ns ± 0% -2.01% (p=0.029 n=4+4) name old alloc/op new alloc/op delta UniqueStrings/Safe-16 224B ± 0% 128B ± 0% -42.86% (p=0.029 n=4+4) UniqueStrings/Reuse_slice-16 96.0B ± 0% 0.0B -100.00% (p=0.029 n=4+4) UniqueStrings/Reuse_slice_sorted-16 24.0B ± 0% 24.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta UniqueStrings/Safe-16 7.00 ± 0% 1.00 ± 0% -85.71% (p=0.029 n=4+4) UniqueStrings/Reuse_slice-16 6.00 ± 0% 0.00 -100.00% (p=0.029 n=4+4) UniqueStrings/Reuse_slice_sorted-16 1.00 ± 0% 1.00 ± 0% ~ (all equal) ```
2021-07-25Bump all long-living deprecations to ERRORsBjørn Erik Pedersen
2021-07-15hugofs: Make FileMeta a structBjørn Erik Pedersen
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct. This is easier to reason about, and it's more effective: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-16 71.5ms ± 3% 69.4ms ± 5% ~ (p=0.200 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-16 29.7MB ± 0% 27.9MB ± 0% -5.82% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-16 313k ± 0% 303k ± 0% -3.35% (p=0.029 n=4+4) ``` See #8749
2021-07-15Fix the deprecation error/warn log levelsBjørn Erik Pedersen
2021-06-30Fix Cloudflare vs Netlify cache dir issueBjørn Erik Pedersen
Re-add the additional environment checks to determine if its Netlify. Seems that Cloudflare also sets `NETLIFY=true`. This makes it look, basically, like a variant of the conditional we had before we started fixing this, but I have checked this logic on Netlify now and it should work. Fixes #8714
2021-06-29config: Fix Netlify default cache dir logicBjørn Erik Pedersen
Fixes #8710