summaryrefslogtreecommitdiffstats
path: root/helpers/url_test.go
Commit message (Collapse)AuthorAge
* all: Run modernize -fix ./...Bjørn Erik Pedersen2025-02-26
|
* all: Rework page store, add a dynacache, improve partial rebuilds, and some ↵develop2024Bjørn Erik Pedersen2024-01-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix defaultContentLanguageInSubdir with only 1 languageBjørn Erik Pedersen2023-07-08
| | | | Fixes #10064
* Adjust benchmarksBjørn Erik Pedersen2023-06-12
|
* Adjust benchmarkBjørn Erik Pedersen2023-06-12
|
* Add BenchmarkAbsURLBjørn Erik Pedersen2023-06-12
|
* helpers: Improve schema detection when creating relative URLsJoe Mooring2023-06-12
| | | | Fixes #11080
* helpers: Add a basic benchmark for RelURLBjørn Erik Pedersen2023-06-12
|
* Create a struct with all of Hugo's config optionsBjørn Erik Pedersen2023-05-16
| | | | | | | | | | | | 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
* Fix relURL with leading slash when baseURL includes a subdirectoryBjørn Erik Pedersen2022-06-13
| | | | Fixes #9994
* Split out the puthe path/filepath functions into common/pathsBjørn Erik Pedersen2021-06-18
| | | | | | So they can be used from the config package without cyclic troubles. Updates #8654
* all: Format code with gofumptBjørn Erik Pedersen2020-12-03
| | | | See https://github.com/mvdan/gofumpt
* Fix RelURL and AbsURL when path starts with languageivan-meridianbanc-com2020-12-02
|
* tests: Convert from testify to quicktestBjørn Erik Pedersen2019-08-12
|
* Block symlink dir traversal for /staticBjørn Erik Pedersen2019-07-25
| | | | | This is in line with how it behaved before, but it was lifted a little for the project mount for Hugo Modules, but that could create hard-to-detect loops.
* Add support for theme composition and inheritanceBjørn Erik Pedersen2018-06-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add support for a content dir set per languageBjørn Erik Pedersen2018-04-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* all: Update import paths to gohugoio/hugoBjørn Erik Pedersen2017-06-13
|
* all: Propagate baseURL error to the callersBjørn Erik Pedersen2017-03-27
|
* all: Refactor to nonglobal Viper, i18n etc.Bjørn Erik Pedersen2017-02-17
| | | | | | | | 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
* all: Refactor to nonglobal file systemsBjørn Erik Pedersen2017-02-04
| | | | | Updates #2701 Fixes #2951
* hugolib: Fix regressions with uglyURLsBjørn Erik Pedersen2016-11-27
| | | | Fixes #2734
* all: Unify case of config variable namesAlbert Nigmatzianov2016-10-24
| | | | | | | | | All config variables starts with low-case and uses camelCase. If there is abbreviation at the beginning of the name, the whole abbreviation will be written in low-case. If there is abbreviation at the end of the name, the whole abbreviation will be written in upper-case. For example, rssURI.
* Avoid reading from Viper for path and URL funcsBjørn Erik Pedersen2016-10-24
| | | | | | | | | | | | | | | | The gain, given the "real sites benchmark" below, is obvious: ``` benchmark old ns/op new ns/op delta BenchmarkHugo-4 14497594101 13084156335 -9.75% benchmark old allocs new allocs delta BenchmarkHugo-4 57404335 48282002 -15.89% benchmark old bytes new bytes delta BenchmarkHugo-4 9933505624 9721984424 -2.13% ``` Fixes #2495
* helpers: Avoid adding language prefix if already presentBjørn Erik Pedersen2016-09-13
| | | | Fixes #2444
* Render main content language in root by defaultBjørn Erik Pedersen2016-09-06
| | | | Fixes #2312
* Improve language handling in URLsBjørn Erik Pedersen2016-09-06
| | | | | | | The current "rendering language" is needed outside of Site. This commit moves the Language type to the helpers package, and then used to get correct correct language configuration in the markdownify template func. This commit also adds two new template funcs: relLangURL and absLangURL. See #2309
* Fix panic when using URLizeMathias Biilmann2016-07-11
| | | Using URLize on a string like '100%-true' would cause a panic
* helpers: Use net/url for URL parsing in AbsURLCameron Moore2016-04-27
| | | | Fixes #2112
* Make absURL properly handle baseURL with path componentMarek Janda2016-03-10
|
* Fixes #1292Daniel TISCHER2016-01-01
|
* Add copyright header to that source files that don’t have one.Anthony Fok2015-12-10
| | | | See #1646
* Stop Viper from leaking across many of the tests (now tests pass regardless ↵spf132015-05-20
| | | | of order tested)
* Add relURL template funcbep2015-05-11
| | | | Fixes #1126
* Add absURL template funcbep2015-05-11
| | | | Fixes #1106
* Do not add trailing slash to baseURLbep2015-05-05
| | | | Fixes #1105
* More initialism corrections (golint)Anthony Fok2015-03-18
| | | | | | | | | | | | | | | | | | | | | Thanks to @bep's new, brilliant helpers.Deprecated() function, the following functions or variables are transitioned to their new names, preserving backward compatibility for v0.14 and warning the user of upcoming obsolescence in v0.15: * .Url → .URL (for node, menu and paginator) * .Site.BaseUrl → .Site.BaseURL * .Site.Indexes → .Site.Taxonomies * .Site.Recent → .Site.Pages * getJson → getJSON * getCsv → getCSV * safeHtml → safeHTML * safeCss → safeCSS * safeUrl → safeURL Also fix related initialisms in strings and comments. Continued effort in fixing #959.
* Correct initialisms as suggested by golintAnthony Fok2015-03-11
| | | | | | | | | | | | | | | | | | | First step to use initialisms that golint suggests, for example: Line 116: func GetHtmlRenderer should be GetHTMLRenderer as see on http://goreportcard.com/report/spf13/hugo Thanks to @bep for the idea! Note that command-line flags (cobra and pflag) as well as struct fields like .BaseUrl and .Url that are used in Go HTML templates need more work to maintain backward-compatibility, and thus are NOT yet dealt with in this commit. First step in fixing #959.
* Keep trailing slash when baseUrl contains a sub pathbep2015-02-28
| | | | | | | | | | | | | | Before this commit, .Site.BaseUrl ended up as: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub Now it becomes: http://mysite.com/ => http://mysite.com/ http://mysite.com/sub/ => http://mysite.com/sub/ Fixed #931
* ignore root path, no need strip traling slashfundon2015-01-28
|
* Fix RelPermalink() and Urls in menus vs canonifyUrlsbep2015-01-23
| | | | | | | | | | | | | | | | | | | | | canonifyUrls=true, RelPermalink and baseUrl with sub-path did not work. This fixes that by adding a check for canonifyUrl=trues=true in RelPermalink(). So given - baseUrl "http://somehost.com/sub/" - the path "some-path/file.html" For canonifyUrls=false RelPermalink() returns "/sub/some-path/file.html" For canonifyUrls=true RelPermalink() returns "/some-path/file.html" In the last case, the Url will be made absolute and clickable in a later step. This commit also makes the menu urls defined in site config releative. To make them work with canonifying of urls, the context root is prepended if canonifying is turned off. Fixes #519 Fixes #711
* Fix various Windows-issuesbep2014-12-09
| | | | | | | | | File handling was broken on Windows. This commit contains a revision of the path handling with separation of file paths and urls where needed. There may be remaining issues and there may be better ways to do this, but it is easier to start that refactoring job with a set of passing tests. Fixes #687 Fixes #660
* Fixing some testsspf132014-11-04
|
* Added the url modules test files.Owen Waller2014-11-04
Added the new url module test file. This replaces the original helpers_test.go file. The TestUrlPrep test currently fails. The only minor change to url.go is to add some trace printf's to UrlPrep.