summaryrefslogtreecommitdiffstats
path: root/commands/hugo.go
AgeCommit message (Collapse)Author
2020-02-13commands: Rename doWithCommandeer to cfgInit/cfgSetAndInitMark Rosemaker
This will make it clearer what it does and make the code more consistent.
2020-01-22tpl/tplimpl: Rework template management to get rid of concurrency issuesBjørn Erik Pedersen
This more or less completes the simplification of the template handling code in Hugo started in v0.62. The main motivation was to fix a long lasting issue about a crash in HTML content files without front matter. But this commit also comes with a big functional improvement. As we now have moved the base template evaluation to the build stage we now use the same lookup rules for `baseof` as for `list` etc. type of templates. This means that in this simple example you can have a `baseof` template for the `blog` section without having to duplicate the others: ``` layouts ├── _default │   ├── baseof.html │   ├── list.html │   └── single.html └── blog └── baseof.html ``` Also, when simplifying code, you often get rid of some double work, as shown in the "site building" benchmarks below. These benchmarks looks suspiciously good, but I have repeated the below with ca. the same result. Compared to master: ``` name old time/op new time/op delta SiteNew/Bundle_with_image-16 13.1ms ± 1% 10.5ms ± 1% -19.34% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 13.0ms ± 0% 10.7ms ± 1% -18.05% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 46.4ms ± 2% 43.1ms ± 1% -7.15% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 52.2ms ± 2% 47.8ms ± 1% -8.30% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 77.9ms ± 1% 70.9ms ± 1% -9.01% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 43.0ms ± 0% 37.2ms ± 1% -13.54% (p=0.029 n=4+4) SiteNew/Page_collections-16 58.2ms ± 1% 52.4ms ± 1% -9.95% (p=0.029 n=4+4) name old alloc/op new alloc/op delta SiteNew/Bundle_with_image-16 3.81MB ± 0% 2.22MB ± 0% -41.70% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 3.60MB ± 0% 2.01MB ± 0% -44.20% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 19.3MB ± 1% 14.1MB ± 0% -26.91% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 70.7MB ± 0% 69.0MB ± 0% -2.40% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 37.1MB ± 0% 31.2MB ± 0% -15.94% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 17.6MB ± 0% 10.6MB ± 0% -39.92% (p=0.029 n=4+4) SiteNew/Page_collections-16 25.9MB ± 0% 21.2MB ± 0% -17.99% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Bundle_with_image-16 52.3k ± 0% 26.1k ± 0% -50.18% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 52.3k ± 0% 26.1k ± 0% -50.16% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 336k ± 1% 269k ± 0% -19.90% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 422k ± 0% 395k ± 0% -6.43% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 401k ± 0% 313k ± 0% -21.79% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 247k ± 0% 143k ± 0% -42.17% (p=0.029 n=4+4) SiteNew/Page_collections-16 282k ± 0% 207k ± 0% -26.55% (p=0.029 n=4+4) ``` Fixes #6716 Fixes #6760 Fixes #6768 Fixes #6778
2020-01-01Support files in content mountsBjørn Erik Pedersen
This commit is a general improvement of handling if single file mounts. Fixes #6684 Fixes #6696
2019-12-20hugolib: Improve error and reload handling of hook templates in server modeBjørn Erik Pedersen
Fixes #6635
2019-11-21Add some more output if loading modules takes timeBjørn Erik Pedersen
Also include the time to collect modules etc. in the "Total in ..." time reported for the `hugo` command. Fixes #6519
2019-08-15commands: Make sure the hugo field is always initialized before it's usedHyeonGyu Lee
Wrap the field to make it accessible after initialization. Fixes #6193
2019-07-30commands: Fix config reloading in Vim and similarBjørn Erik Pedersen
The config path was simplified in Hugo 0.56.0 to support more config dirs/files (go.mod etc.), and the new code path assumed that every file change would trigger a `Write` event. This is not true for Vim etc. which triggers a `Chmod` and then a `Rename`. Lesson learned: Be really careful changing Os/editor specific code without proper tests. Fixes #6139
2019-07-24Add Hugo ModulesBjørn Erik Pedersen
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-05-06deploy: Support invalidating a CloudFront CDN cacheRobert van Gent
2019-05-03Add a "deploy" commandRobert van Gent
2019-04-23commands: Init mem profile at the endBjørn Erik Pedersen
Much more useful ...
2019-03-23Make Page an interfaceBjørn Erik Pedersen
The main motivation of this commit is to add a `page.Page` interface to replace the very file-oriented `hugolib.Page` struct. This is all a preparation step for issue #5074, "pages from other data sources". But this also fixes a set of annoying limitations, especially related to custom output formats, and shortcodes. Most notable changes: * The inner content of shortcodes using the `{{%` as the outer-most delimiter will now be sent to the content renderer, e.g. Blackfriday. This means that any markdown will partake in the global ToC and footnote context etc. * The Custom Output formats are now "fully virtualized". This removes many of the current limitations. * The taxonomy list type now has a reference to the `Page` object. This improves the taxonomy template `.Title` situation and make common template constructs much simpler. See #5074 Fixes #5763 Fixes #5758 Fixes #5090 Fixes #5204 Fixes #4695 Fixes #5607 Fixes #5707 Fixes #5719 Fixes #3113 Fixes #5706 Fixes #5767 Fixes #5723 Fixes #5769 Fixes #5770 Fixes #5771 Fixes #5759 Fixes #5776 Fixes #5777 Fixes #5778
2019-01-10Add configFile(s) back to the watch list after RENAME event tooAnthony Fok
Alleviates #5205
2018-12-23Add CSV support to transform.UnmarshalBjørn Erik Pedersen
Fixes #5555
2018-12-11Add /config dir supportBjørn Erik Pedersen
This commit adds support for a configuration directory (default `config`). The different pieces in this puzzle are: * A new `--environment` (or `-e`) flag. This can also be set with the `HUGO_ENVIRONMENT` OS environment variable. The value for `environment` defaults to `production` when running `hugo` and `development` when running `hugo server`. You can set it to any value you want (e.g. `hugo server -e "Sensible Environment"`), but as it is used to load configuration from the file system, the letter case may be important. You can get this value in your templates with `{{ hugo.Environment }}`. * A new `--configDir` flag (defaults to `config` below your project). This can also be set with `HUGO_CONFIGDIR` OS environment variable. If the `configDir` exists, the configuration files will be read and merged on top of each other from left to right; the right-most value will win on duplicates. Given the example tree below: If `environment` is `production`, the left-most `config.toml` would be the one directly below the project (this can now be omitted if you want), and then `_default/config.toml` and finally `production/config.toml`. And since these will be merged, you can just provide the environment specific configuration setting in you production config, e.g. `enableGitInfo = true`. The order within the directories will be lexical (`config.toml` and then `params.toml`). ```bash config ├── _default │   ├── config.toml │   ├── languages.toml │   ├── menus │   │   ├── menus.en.toml │   │   └── menus.zh.toml │   └── params.toml ├── development │   └── params.toml └── production ├── config.toml └── params.toml ``` Some configuration maps support the language code in the filename (e.g. `menus.en.toml`): `menus` (`menu` also works) and `params`. Also note that the only folders with "a meaning" in the above listing is the top level directories below `config`. The `menus` sub folder is just added for better organization. We use `TOML` in the example above, but Hugo also supports `JSON` and `YAML` as configuration formats. These can be mixed. Fixes #5422
2018-12-06Add tpl/site and tpl/hugoBjørn Erik Pedersen
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-11-15Fix Permalink for resource, baseURL with path and canonifyURLs setBjørn Erik Pedersen
Fixes #5226
2018-11-03Make WARN the new default log log levelBjørn Erik Pedersen
This commit also pulls down the log level for a set of WARN statements to INFO. There should be no ERRORs or WARNINGs in a regular Hugo build. That is the story about the Boy Who Cried Wolf. Since the WARN log is now more visible, this commit also improves on some of them, most notable the "layout not found", which now would look something like this: ```bash WARN 2018/11/02 09:02:18 Found no layout for "home", language "en", output format "CSS": create a template below /layouts with one of these filenames: index.en.css.css, home.en.css.css, list.en.css.css, index.css.css, home.css.css, list.css.css, index.en.css, home.en.css, list.en.css, index.css, home.css, list.css, _default/index.en.css.css, _default/home.en.css.css, _default/list.en.css.css, _default/index.css.css, _default/home.css.css, _default/list.css.css, _default/index.en.css, _default/home.en.css, _default/list.en.css, _default/index.css, _default/home.css, _default/list.css ``` Fixes #5203
2018-11-02Skip watcher event files if matched in ignoreFilesKris Budhram
2018-10-28common/loggers: Make sure the global logger also gets colored labelsBjørn Erik Pedersen
See #4414
2018-10-26commands: Only show Ansi escape codes if in a terminalBjørn Erik Pedersen
2018-10-24Revert "commands: Read disableFastRender from flag even if it's not changed"Bjørn Erik Pedersen
On second thought, removing this isn't worth it. This reverts commit 78a4c2e32ef9ea8e92bb7bb3586e4c22b02eb494.
2018-10-24commands: Read disableFastRender from flag even if it's not changedBjørn Erik Pedersen
Fixes #5353
2018-10-23commands, hugolib: Get file context in "config parse failed" errorsBjørn Erik Pedersen
Fixes #5325
2018-10-22hugolib: Improve errors in /i18n handllingBjørn Erik Pedersen
See #5324
2018-10-22parser/metadecoders: Consolidate the metadata decodersBjørn Erik Pedersen
See #5324
2018-10-17Prevent stale content in Fast Render ModeBjørn Erik Pedersen
We do that by re-render visited pages that is not already in the stack. This may potentially do some double work, but that small penalty should be well worth it. Fixes #5281
2018-10-16commands: Show server error info in browserBjørn Erik Pedersen
The main item in this commit is showing of errors with a file context when running `hugo server`. This can be turned off: `hugo server --disableBrowserError` (can also be set in `config.toml`). But to get there, the error handling in Hugo needed a revision. There are some items left TODO for commits soon to follow, most notable errors in content and config files. Fixes #5284 Fixes #5290 See #5325 See #5324
2018-09-21commands: Remove deprecated flagsBjørn Erik Pedersen
2018-09-07commands: Fix golint issuesCameron Moore
commands/hugo.go:65:1: exported method Response.IsUserError should have comment or be unexported commands/import_jekyll.go:100:21: error strings should not be capitalized or end with punctuation or a newline commands/server.go:417:1: receiver name sc should be consistent with previous receiver name s for serverCmd
2018-08-16Add configFile(s) back to the watch list after REMOVE eventAnthony Fok
Fixes #4701
2018-08-16commands: Gracefully handle typos in server config when running the serverBjørn Erik Pedersen
Fixes #5081
2018-08-14commands: Include theme name in version mismatch errorBjørn Erik Pedersen
Fixes #5044
2018-08-06Add support for minification of final outputBjørn Erik Pedersen
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-07-22Get rid of the utils packageBjørn Erik Pedersen
2018-07-06Add Hugo Piper with SCSS support and much moreBjørn Erik Pedersen
Before this commit, you would have to use page bundles to do image processing etc. in Hugo. This commit adds * A new `/assets` top-level project or theme dir (configurable via `assetDir`) * A new template func, `resources.Get` which can be used to "get a resource" that can be further processed. This means that you can now do this in your templates (or shortcodes): ```bash {{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }} ``` This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed: ``` HUGO_BUILD_TAGS=extended mage install ``` Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo. The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline: ```bash {{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }} <link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen"> ``` The transformation funcs above have aliases, so it can be shortened to: ```bash {{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }} <link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen"> ``` A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding. Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test New functions to create `Resource` objects: * `resources.Get` (see above) * `resources.FromString`: Create a Resource from a string. New `Resource` transformation funcs: * `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`. * `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option). * `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`. * `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity.. * `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler. * `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template. Fixes #4381 Fixes #4903 Fixes #4858
2018-06-28commands: Fix broken server-reload on config changesBjørn Erik Pedersen
This was accidently broken in Hugo 0.42. Fixes #4878
2018-06-13commands: Do not fail server build when /static is missingBjørn Erik Pedersen
This was a un-intended change in Hugo 0.42. Most sites will have a static directory so this should not be a big issue, but this commit will revert back to old behaviour. Fixes #4846
2018-06-10Add support for theme composition and inheritanceBjørn Erik Pedersen
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
2018-06-05Reset the "distinct error logger" on rebuildsBjørn Erik Pedersen
Fixes #4818
2018-05-23Fix some recently broken embedded templatesBjørn Erik Pedersen
And add tests for them. Fixes #4757
2018-04-15commands: Remove accidental and breaking space in baseURL flagBjørn Erik Pedersen
And added key-trimming to prevent future mishaps. See #4607
2018-04-14commands: Properly handle CLI slice argumentsBjørn Erik Pedersen
Like `--disableKinds` -- this handling was kind of broken when we recently moved this from global vars See #4607
2018-04-14commands: Correctly handle destination and i18n-warningsBjørn Erik Pedersen
And add some more CLI tests. See #4607
2018-04-13commands: Fix handling of persistent CLI flagsBjørn Erik Pedersen
See #4607
2018-04-11commands: Make commands.Execute return a Response objectBjørn Erik Pedersen
We have no global `Hugo` object no more (yay!), and there are some external tools that depends on that value. These tools need to use get that value from `Response.Result`. Note that `commands.Execute` now also takes the arguments as a string slice. This should also make it easier to use, not having to modify `os.Args`. This commit also wraps up this particular issue. Phew! Test coverage in /commands before: 14.4% Now: 53.5% Still work to do, now it is at least possible. Closes #4598
2018-04-11commands: Remove some TODOsBjørn Erik Pedersen
See #4598
2018-04-11commands: Remove the Hugo globalBjørn Erik Pedersen
There are still some cleaning to do, but that felt good. See #4598
2018-04-11commands: Move the commands related logic to its own fileBjørn Erik Pedersen
See #4598
2018-04-11commands: Add CLI testsBjørn Erik Pedersen
See #4598