summaryrefslogtreecommitdiffstats
path: root/resource
AgeCommit message (Collapse)Author
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-10-16resource: Optimize integrity string generationCameron Moore
Remove use of fmt.Sprintf for simple string concatenation. A simple change for a small perf boost. ``` name old time/op new time/op delta Integrity-4 525ns ± 2% 268ns ± 2% -48.92% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Integrity-4 144B ± 0% 112B ± 0% -22.22% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Integrity-4 5.00 ± 0% 3.00 ± 0% -40.00% (p=0.000 n=10+10) ```
2018-09-23resource/integrity: Make Data.Integrity be of type template.HTMLAttrBjørn Erik Pedersen
2018-09-14tpl/collections: Add collections.AppendBjørn Erik Pedersen
Before this commit you would typically use `.Scratch.Add` to manually create slices in a loop. With variable overwrite in Go 1.11, we can do better. This commit adds the `append` template func. A made-up example: ```bash {{ $p1 := index .Site.RegularPages 0 }}{{ $p2 := index .Site.RegularPages 1 }} {{ $pages := slice }} {{ if true }} {{ $pages = $pages | append $p2 $p1 }} {{ end }} ``` Note that with 2 slices as arguments, the two examples below will give the same result: ```bash {{ $s1 := slice "a" "b" | append (slice "c" "d") }} {{ $s2 := slice "a" "b" | append "c" "d" }} ``` Both of the above will give `[]string{a, b, c, d}`. This commit also improves the type handling in the `slice` template function. Now `slice "a" "b"` will give a `[]string` slice. The old behaviour was to return a `[]interface{}`. Fixes #5190
2018-09-07resource: Fix golint issuesCameron Moore
Fix godoc comments and the following: resource/image.go:33:2: a blank import should be only in a main or test package, or have a comment justifying it resource/image.go:35:2: a blank import should be only in a main or test package, or have a comment justifying it resource/image.go:41:2: a blank import should be only in a main or test package, or have a comment justifying it resource/image.go:538:10: if block ends with a return statement, so drop this else and outdent its block resource/resource.go:54:7: exported const DefaultResourceType should have comment or be unexported resource/resource.go:233:1: receiver name r1 should be consistent with previous receiver name r for Resources resource/resource.go:254:1: receiver name r1 should be consistent with previous receiver name r for Resources
2018-09-07common: Fix golint errorsCameron Moore
common/errors/errors.go:21:1: comment on exported var FeatureNotAvailableErr should be of the form "FeatureNotAvailableErr ..." common/errors/errors.go:23:5: error var FeatureNotAvailableErr should have name of the form ErrFoo common/maps/scratch.go:76:1: comment on exported method Scratch.Delete should be of the form "Delete ..." common/maps/scratch.go:133:1: exported function NewScratch should have comment or be unexported common/types/types.go:44:1: exported function NewKeyValuesStrings should have comment or be unexported
2018-09-03resource: Fix broken buildBjørn Erik Pedersen
2018-09-02resource: Remove some duplicate codeBjørn Erik Pedersen
2018-08-26resource: Add instruction to install PostCSS when missingAnthony Fok
Fixes #5111
2018-08-25Update Travis to Go 1.11 and Go 1.10.4Bjørn Erik Pedersen
See #5115
2018-08-13Fix Resource output in multihost setupsBjørn Erik Pedersen
In Hugo 0.46 we made the output of what you get from resources.Get and similar static, i.e. language agnostic. This makes total sense, as it is wasteful and time-consuming to do SASS/SCSS/PostCSS processing for lots of languages when the output is lots of duplicates with different filenames. But since we now output the result once only, this had a negative side effect for multihost setups: We publish the resource once only to the root folder (i.e. not to the language "domain folder"). This commit removes the language code from the processed image keys. This creates less duplication in the file cache, but it means that you should do a `hugo --gc` to clean up stale files. Fixes #5058
2018-08-09Fix broken testsBjørn Erik Pedersen
2018-08-06resource: Remove test debugBjørn Erik Pedersen
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-31Make resources fetched via resources.Get and similar language agnosticBjørn Erik Pedersen
With the newly released Hugo Pipes, resources fetched and processed via `resources.Get` and similar was published to the relevant language sub folder when in multilingual mode. The thought behind that was maximum flexibility with support for `assetDir` per language. In practice this was a bad idea: * You get duplication of identical content, with added processing time * You end up with path issues that seem to be hard to find a way around (`@fa-font-path` is one example) This commit changes that. Now there is only one `assetDir` and if you, as one example, need to generate a CSS per langugage, you need to set the paths yourself. Fixes #5017
2018-07-31tocss/scss: Improve _ prefix handling in SCSS importsBjørn Erik Pedersen
See #5008
2018-07-31Fix file paths for uncached transformed imagesRob Jackson
This commit also fixes an existing test to work according to the correct logic. The test was written based on erroneous behavior. We resize the image to 300x200px, and are now trying to fit it within a 50px square. The longest edge is 300 pixels, so we need to divide it by 6 (300 / 50 == 6). And then scale the shortest edge with the same proportion (200 / 6 == 33.33). The original test was transforming the original source image, hence the previous values: 900 x 562 900 / 50 == 18 562 / 18 == 31.22 Fixes #5012
2018-07-31tocss/scss: Improve SCSS project vs themes import resolutionBjørn Erik Pedersen
Before this commit, only SASS/SCSS components imported from main.scss at first level can be overwritten by homonymous files in projects or over-preceding theme components. This commit fixes that by implementing a custom import resolver which will be tried first. This resolver will make sure that the project/theme hierarchy is always respected. Fixes #5008
2018-07-29Fix image cache eviction for sites with subdir in baseURLBjørn Erik Pedersen
Fixes #5006
2018-07-20resource/scss: Add IncludePaths config optionBjørn Erik Pedersen
Takes paths relative to the current working dir. Fixes #4921
2018-07-20resource/scss: Fix source maps on WindowsBjørn Erik Pedersen
I have tested this OK on * Windows 10 (it did not work before this commit) * MacOS Fixes #4968
2018-07-18resource/postcss: Try node_modules/postcss-cli/bin/postcss firstBjørn Erik Pedersen
Fixes #4952
2018-07-16resource/bundler: Improve error messageBjørn Erik Pedersen
2018-07-14resource/integrity: Remove unused codeBjørn Erik Pedersen
2018-07-12resource: Clean up the in-memory Resource reader usageBjørn Erik Pedersen
Turns out `strings.Reader` implements both `io.Reader` and `io.Seeker`, so we don't need anything special. Updates #4936
2018-07-12resource: Move opening of the transformed resources after cache checkBjørn Erik Pedersen
The old version should be functionally the same, but opening up these readers (potentially files) every time is wasteful if we don't read from them.
2018-07-12resource: Fix resources.Concat for transformed resourcesBjørn Erik Pedersen
Fixes #4936
2018-07-12Improve type support in resources.ConcatBjørn Erik Pedersen
This allows the result of `.Resources.Match` and similar to be concatenated. Fixes #4934
2018-07-11resource: Include the transformation step in the error messageBjørn Erik Pedersen
Fixes #4924
2018-07-10media: Allow multiple file suffixes per media typeBjørn Erik Pedersen
Before this commit, `Suffix` on `MediaType` was used both to set a custom file suffix and as a way to augment the mediatype definition (what you see after the "+", e.g. "image/svg+xml"). This had its limitations. For one, it was only possible with one file extension per MIME type. Now you can specify multiple file suffixes using "suffixes", but you need to specify the full MIME type identifier: [mediaTypes] [mediaTypes."image/svg+xml"] suffixes = ["svg", "abc ] In most cases, it will be enough to just change: [mediaTypes] [mediaTypes."my/custom-mediatype"] suffix = "txt" To: [mediaTypes] [mediaTypes."my/custom-mediatype"] suffixes = ["txt"] Hugo will still respect values set in "suffix" if no value for "suffixes" is provided, but this will be removed in a future release. Note that you can still get the Media Type's suffix from a template: {{ $mediaType.Suffix }}. But this will now map to the MIME type filename. Fixes #4920
2018-07-07Fix typosYang Li
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-26Enhance Page and Resource String()Vas Sudanagunta
2018-04-19Add language merge support for Pages in resource.ResourcesBjørn Erik Pedersen
Fixes #4644
2018-04-15resource: Implement Resource.ContentBjørn Erik Pedersen
Fixes #4622
2018-04-02Add support for a content dir set per languageBjørn Erik Pedersen
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
2018-03-20Bump some deprecationsBjørn Erik Pedersen
2018-03-14resource: Fix path duplication/flattening in processed imagesBjørn Erik Pedersen
Fixes #4502 Closes #4501
2018-02-27resource: Fix SVG and similar resource handlingBjørn Erik Pedersen
The validation of if we could process the image (resize etc.) was moved up in Hugo 0.37, which meant SVG and other "non-processable" images would fail. This commit fixes that by creating a regular resource for these image formats. They will not have `.Resize` or any of the other image methods. Fixes #4455
2018-02-26resource: Use Floyd-Steinberg dithering for PNGsBjørn Erik Pedersen
Fixes #4453
2018-02-21Run gofmt -s with Go 1.10Bjørn Erik Pedersen
See #4434
2018-02-19resource: Preserve color palette for PNG imagesBjørn Erik Pedersen
This commit will force a reprocessing of PNG images with new names, so it is adviced to run a `hugo --gc` to remove stale files. Fixes #4416
2018-02-14resource: Fix multi-threaded image processing issueBjørn Erik Pedersen
When doing something like this with the same image from a partial used in, say, both the home page and the single page: ```bash {{ with $img }} {{ $big := .Fill "1024x512 top" }} {{ $small := $big.Resize "512x" }} {{ end }} ``` There would be timing issues making Hugo in some cases try to process the same image with the same instructions in parallel. You would experience errors of type: ```bash png: invalid format: not enough pixel data ``` This commit works around that by adding a mutex per image. This should also improve the performance, sligthly, as it avoids duplicate work. The current workaround before this fix is to always operate on the original: ```bash {{ with $img }} {{ $big := .Fill "1024x512 top" }} {{ $small := .Fill "512x256 top" }} {{ end }} ``` Fixes #4404
2018-02-13resource: Improve error processing error messageBjørn Erik Pedersen
2018-02-05resource: Add smart croppingBjørn Erik Pedersen
This commit `smart` as a new and default anchor in `Fill`. So: ```html {{ $image.Fill "200x200" }} ``` Is, with default configuration, the same as: ```html {{ $image.Fill "200x200" "smart" }} ``` You can change this default in your `config.toml`: ```toml [imaging] [imaging] resampleFilter = "box" quality = 68 anchor = "Smart" ``` Fixes #4375
2018-01-29resource: Make resource counters for name and title independentBjørn Erik Pedersen
This is the most flexible with the current syntax, and probably what most people would expcect. Updates #4335
2018-01-27resource: Start Resources :counter first time they're usedBjørn Erik Pedersen
This is less surprising and more flexible than the original implementation. Given: ```toml [[resources]] src = "documents/photo_specs.pdf" title = "Photo Specifications" [[resources]] src = "**.pdf" name = "pdf-file-:counter" ``` Every `pdf` in the bundle will have an unique counter, but the `photo_specs.pdf` is still allowed to have its specific `title`. If you change the above example to: ```toml [[resources]] src = "documents/*specs.pdf" title = "Photo Specifications #:conter" [[resources]] src = "**.pdf" name = "pdf-file-:counter" ``` We are talking about two different groups of documents, each with its own counters starting at 1. Fixes #4335
2018-01-24resource: Fix typo in commentAlexey Grachov
2018-01-23Merge matching resources params mapsBjørn Erik Pedersen
This allows setting default params values in the more general resource matchers. I also allows override with more specific values if needed. ```toml [[resources]] src = "documents/photo_specs.pdf" title = "Photo Specifications" [resources.params] ref = 90564687 icon = "photo" [[resources]] src = "documents/guide.pdf" title = "Instruction Guide" [resources.params] ref = 90564568 [[resources]] src = "documents/checklist.pdf" title = "Document Checklist" [resources.params] ref = 90564572 [[resources]] src = "documents/payment.docx" title = "Proof of Payment" [[resources]] src = "documents/*.pdf" title = "PDF file" [resources.params] icon = "pdf" [[resources]] src = "documents/*.docx" title = "Word document" [resources.params] icon = "word" ``` In the above `TOML` example, `photo_specs.pdf` will get the `photo` icon, the other pdf files will get the default `pdf` icon. Note that in the example above, the order matters: It will take the first value for a given params key, title or name that it finds. Fixes #4315