summaryrefslogtreecommitdiffstats
path: root/helpers/general.go
AgeCommit message (Collapse)Author
2018-09-07helpers: Fix golint issuesCameron Moore
helpers/general.go:448:1: comment on exported function DiffStrings should be of the form "DiffStrings ..." helpers/hugo.go:42:6: exported type HugoVersionString should have comment or be unexported helpers/hugo.go:48:1: exported method HugoVersion.Version should have comment or be unexported helpers/hugo.go:56:1: comment on exported method HugoVersionString.Compare should be of the form "Compare ..." helpers/hugo.go:62:1: comment on exported method HugoVersionString.Eq should be of the form "Eq ..." helpers/path.go:548:1: comment on exported function OpenFilesForWriting should be of the form "OpenFilesForWriting ..." helpers/processing_stats.go:24:6: exported type ProcessingStats should have comment or be unexported helpers/processing_stats.go:55:1: exported function NewProcessingStats should have comment or be unexported helpers/processing_stats.go:59:1: exported method ProcessingStats.Incr should have comment or be unexported helpers/processing_stats.go:63:1: exported method ProcessingStats.Add should have comment or be unexported helpers/processing_stats.go:67:1: exported method ProcessingStats.Table should have comment or be unexported helpers/processing_stats.go:83:1: exported function ProcessingStatsTable should have comment or be unexported
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-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-05-23Fix some recently broken embedded templatesBjørn Erik Pedersen
And add tests for them. Fixes #4757
2018-03-11hugolib: Extract date and slug from filenameBjørn Erik Pedersen
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page `slug` if that value is not set in front matter. This should make it easier to move content from Jekyll to Hugo. To enable, put this in your `config.toml`: ```toml [frontmatter] date = [":filename", ":default"] ``` This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with `:filename` etc. So, if you want to use the `file modification time`, this can be a good configuration: ```toml [frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"] ``` The current `:default` values for the different dates are ```toml [frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"] ``` The above will now be the same as: ```toml [frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"] ``` Note: * We have some built-in aliases to the above: lastmod => modified, publishDate => pubdate, published and expiryDate => unpublishdate. * If you want a new configuration for, say, `date`, you can provide only that line, and the rest will be preserved. * All the keywords to the right that does not start with a ":" maps to front matter parameters, and can be any date param (e.g. `myCustomDateParam`). * The keywords to the left are the **4 predefined dates in Hugo**, i.e. they are constant values. * The current "special date handlers" are `:fileModTime` and `:filename`. We will soon add `:git` to that list. Fixes #285 Closes #3310 Closes #3762 Closes #4340
2018-02-10tpl/transform: Add template func for TOML/JSON/YAML docs examples conversionBjørn Erik Pedersen
Usage: ```html {{ "title = \"Hello World\"" | transform.Remarshal "json" | safeHTML }} ``` Fixes #4389
2017-12-28helpers: Avoid writing the last MD5 buff part twiceBjørn Erik Pedersen
2017-12-28resource: Use MD5 to identify image filesBjørn Erik Pedersen
But only a set of byte chunks spread around in the image file to calculate the fingerprint, which is much faster than reading the whole file: ```bash BenchmarkMD5FromFileFast/full=false-4 300000 4356 ns/op 240 B/op 5 allocs/op BenchmarkMD5FromFileFast/full=true-4 30000 42899 ns/op 32944 B/op 5 allocs/op ``` Fixes #4186
2017-12-27:sparkles: Implement Page bundling and image handlingBjørn Erik Pedersen
This commit is not the smallest in Hugo's history. Some hightlights include: * Page bundles (for complete articles, keeping images and content together etc.). * Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`. * Processed images are cached inside `resources/_gen/images` (default) in your project. * Symbolic links (both files and dirs) are now allowed anywhere inside /content * A new table based build summary * The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below). A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory: ```bash ▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render" benchmark old ns/op new ns/op delta BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30% BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86% benchmark old allocs new allocs delta BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47% BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30% benchmark old bytes new bytes delta BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12% BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35% BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64% ``` Fixes #3651 Closes #3158 Fixes #1014 Closes #2021 Fixes #1240 Updates #3757
2017-11-30Add Pandoc support, refactor external helpersBrian Chen
Recognize the Pandoc format under the file extension .pandoc or .pdc, and shell out to pandoc as an external helper to format Pandoc content. Refactor out repeated code with external helpers. Change the error output formatting. I did not see any of the external helpers print the string "<input>" to represent stdin as a file; just prepending the file name to error output is more general and doesn't sacrifice that much in terms of readability. Closes #234
2017-07-31Make the title case style guide configurableBjørn Erik Pedersen
This works for the `title` func and the other places where Hugo makes title case. * AP style (new default) * Chicago style * Go style (what we have today) Fixes #989
2017-07-04hugolib: Extend the sections APIBjørn Erik Pedersen
This commit adds some section related methods that have been asked for: * .CurrentSection * .IsDescendant * .IsAncestor Fixes #3591
2017-06-13Run gofmt to get imports in line vs gohugoio/hugoBjørn Erik Pedersen
2017-06-13all: Update import paths to gohugoio/hugoBjørn Erik Pedersen
2017-04-30tpl: Add template function namespacesCameron Moore
This commit moves almost all of the template functions into separate packages under tpl/ and adds a namespace framework. All changes should be backward compatible for end users, as all existing function names in the template funcMap are left intact. Seq and DoArithmatic have been moved out of the helpers package and into template namespaces. Most of the tests involved have been refactored, and many new tests have been written. There's still work to do, but this is a big improvement. I got a little overzealous and added some new functions along the way: - strings.Contains - strings.ContainsAny - strings.HasSuffix - strings.TrimPrefix - strings.TrimSuffix Documentation is forthcoming. Fixes #3042
2017-04-24Automate the Hugo release processBjørn Erik Pedersen
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-04commands, helpers: Add correct verbose log level to the global loggersBjørn Erik Pedersen
We still use those in some cases.
2017-03-29hugolib, helpers: Reduce log level to WARN on .Render for non-regular pagesBjørn Erik Pedersen
We will eventually support all types in the Render method.
2017-03-19Revert "helpers: Add a Debug method to DistinctLogger"Bjørn Erik Pedersen
Not needed. This reverts commit 4382a8a6a030520d9f094b3d7bb8f3ae3f08b187.
2017-03-18helpers: Add a Debug method to DistinctLoggerBjørn Erik Pedersen
2017-02-21all: Add org-mode supportChase Adams
Fixes #1483 See #936
2017-02-17all: Refactor to nonglobal Viper, i18n etc.Bjørn Erik Pedersen
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-11Deprecate sourceRelativeLinksBjørn Erik Pedersen
Fixes #3028 Closes #3026 Closes #2891 Closes #2691
2017-01-04helpers: Fix minor typo in error message for Seq()Anthony Fok
2017-01-03commands, helpers, vendor: Update to the latest jww loggerBjørn Erik Pedersen
Updates #2701
2017-01-01Fix Appveyor Windows build and GitInfo path issue on WindowsDavid Kassa
2016-11-23Revise the deprecation strategyBjørn Erik Pedersen
Git users and theme authors two Hugo releases to fix: 1. With a visible warning 2. Then with an ERROR that exits with -1 Fixes #2726
2016-10-16helpers: Slight improvement of ToLowerMapBjørn Erik Pedersen
See #2581
2016-10-16Fix case issue Viper vs Blackfriday configBjørn Erik Pedersen
There are still work to be done in the case department, but that will have to be another day. Fixes #2581 See https://github.com/spf13/viper/issues/261
2016-09-28Deprecate PageMeta.WordCount etc.Bjørn Erik Pedersen
Fix #2503
2016-09-08Reset the i18n func map on reloadBjørn Erik Pedersen
Also improve the error message on missing resource bundles.
2016-08-04Fix the time template func testBjørn Erik Pedersen
By making it not depend on the locale setup.
2016-06-25helpers: Remove ToReader funcsCameron Moore
Remove StringToReader and BytesToReader in favor of using the stdlib directly.
2016-03-22helpers: Silence some Golint warningsBjørn Erik Pedersen
2016-03-14Remove unnecessary type conversionsBjørn Erik Pedersen
2016-01-28Make the watch logger less chattyBjørn Erik Pedersen
2016-01-28Make the DistinctErrorLogger more genericBjørn Erik Pedersen
2015-12-07Fix copyright headers in source filesBjørn Erik Pedersen
Still need to add some missing headers and an AUTHORS file. See #1646
2015-11-23Change the license to Apache 2.0Steve Francia
2015-11-23Improve "watching for ..." loggingBjørn Erik Pedersen
2015-10-07Fix comment for NormalizeHugoFlagsAlexander Morozov
2015-10-02Rename NormalizeHugoFlagsFunc to NormalizeHugoFlagsBjørn Erik Pedersen
It IS a func.
2015-09-13Add helpers.NormalizeHugoFlagsFunc() to handle flag name changesAnthony Fok
It currently handles --baseUrl to --baseURL, and --uglyUrls to --uglyURLs. Special thanks to Eric Paris (@eparis) for writing the "normalized name" support in Cobra, and for showing us how it is used in Kubernetes. See Issue #959
2015-07-12Add RuneCount to PageBjørn Erik Pedersen
Fixes #1266
2015-06-03Add some tests for IgnoreFilesbep
And log error on invalid regexp. See #1189
2015-05-28Support `Fish and Chips` sectionbep
Section names are also used as the title of the list pages, but naming section folders as `Fish and Chips` and similar didn't work very well. This commit fixes that. This commit also changes the title casing of the section titles. Some may argue that this is a breaking change, but the old behaviour was also pretty broken, even for languages that use title capitalizations, as it didn't follow any particular style guide, `fish and chips` became `Fish And Chips` etc. Now it just turns the first letter into upper case, so `Fish and Chips` will be left as `Fish and Chips`. People wanting the good old behaviour can use the `title` template func. Fixes #1176
2015-05-26Make deprecated warning for this release more alertbep
2015-05-08Very experimental support for mmarkAnthony Fok
Either name the content files as `*.mmark`, or add `markup = "mmark"` in the front matter of your `*.md` content files.
2015-04-30tpl: add sanity check to prevent panic in seq on big numsbep
Fixes #1092
2015-04-03helpers: add some missing documentationbep