summaryrefslogtreecommitdiffstats
path: root/parser
AgeCommit message (Collapse)Author
2018-10-22parser/pageparser: File renames and splittingBjørn Erik Pedersen
See #5324
2018-10-22Move the shortcode parser to the new pageparser packageBjørn Erik Pedersen
See #5324
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-04-17parser: Add some context to front matter parse errorBjørn Erik Pedersen
Fixes #4638
2018-02-12parser: Add WARNING for integer YAML keysBjørn Erik Pedersen
```bash benchmark old ns/op new ns/op delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 3053 2015 -34.00% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 5.23 5.18 -0.96% BenchmarkStringifyMapKeysIntegers-4 2320 5177 +123.15% benchmark old allocs new allocs delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 6 6 +0.00% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 0 0 +0.00% BenchmarkStringifyMapKeysIntegers-4 6 14 +133.33% benchmark old bytes new bytes delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 1008 1008 +0.00% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 0 0 +0.00% BenchmarkStringifyMapKeysIntegers-4 1008 1776 +76.19% ``` Closes #4393
2018-02-12parser: Tune stringifyMapKeysBjørn Erik Pedersen
```bash benchmark old ns/op new ns/op delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 3269 3053 -6.61% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 4.79 5.23 +9.19% BenchmarkStringifyMapKeysIntegers-4 2707 2320 -14.30% benchmark old allocs new allocs delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 16 6 -62.50% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 0 0 +0.00% BenchmarkStringifyMapKeysIntegers-4 16 6 -62.50% benchmark old bytes new bytes delta BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 1080 1008 -6.67% BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 0 0 +0.00% BenchmarkStringifyMapKeysIntegers-4 1080 1008 -6.67% ```
2018-02-12parser: Rename stringifyYAMLMapKeys to stringifyMapKeysBjørn Erik Pedersen
2018-02-12parser: Add benchmarks for stringifyYAMLMapKeysBjørn Erik Pedersen
```bash BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4 500000 3269 ns/op 1080 B/op 16 allocs/op BenchmarkStringifyMapKeysStringsOnlyStringMaps-4 300000000 4.79 ns/op 0 B/op 0 allocs/op BenchmarkStringifyMapKeysIntegers-4 500000 2707 ns/op 1080 B/op 16 allocs/op ```
2018-02-12Add support for YAML array data filesVas Sudanagunta
* Unmarshaled YAML arrays indistinguishable from JSON arrays. * Fixes #3890
2018-02-09parser: Fix YAML maps key typeDawid Gaweł
Recurse through result of yaml package parsing and change all maps from map[interface{}]interface{} to map[string]interface{} making them jsonable and sortable. Fixes #2441, #4083
2018-02-02Fix JSON array-based data file handling regressionVas Sudanagunta
This bug was introduced in Hugo 0.35. Fixes #4361
2018-01-26Support pages without front matterVas Sudanagunta
* Page without front matter now treated same as a page with empty front matter. * Test cases added to cover this and repro issue #4320. * Type safety of front matter code improved. Fixes #4320
2017-07-08parser: Final (!) fix for issue with escaped JSON front matterBjørn Erik Pedersen
Fixes #3682
2017-07-08parser: Fix issue with escaped JSON front matterBjørn Erik Pedersen
Fixes #3682
2017-07-03parser: Fix handling of JSON front matter with escaped quotesBjørn Erik Pedersen
Fixes #3661
2017-06-19parser: Fix handling of quoted brackets in JSON front matterBjørn Erik Pedersen
Also remove a broken JSON test. Fixes #3511
2017-06-18create: Use archetype template as-is as a Go templateBjørn Erik Pedersen
This commit removes the fragile front matter decoding, and takes the provided archetype file as-is and processes it as a template. This also means that we no longer will attempt to fill in default values for `title` and `date`. The upside is that it is now easy to create these values in a dynamic way: ```toml +++ title = {{ .BaseFileName | title }} date = {{ .Date }} draft = true +++ ``` You can currently use all of Hugo's template funcs, but the data context is currently very shallow: * `.Type` gives the archetype kind provided * `.Name` gives the target file name without extension. * `.Path` gives the target file name * `.Date` gives the current time as RFC3339 formatted string The above will probably be extended in #1629. Fixes #452 Updates #1629
2017-06-03parser: Add horizontal YAML tags to benchmarkBjørn Erik Pedersen
2017-06-03all: Temporarily revert to BurntSushi for TOML front matter handlingBjørn Erik Pedersen
We still have go-toml as a transitive dependency, and it is the way to go eventually, but we care about speed, so let us wait that one out. Note that the issue this fixes is about taxonomies, but I guess this is a general issue for sites with many pages that uses TOML as front matter. ``` benchmark old ns/op new ns/op delta BenchmarkFrontmatterTags/TOML:1-4 23206 8543 -63.19% BenchmarkFrontmatterTags/TOML:11-4 80117 18495 -76.92% BenchmarkFrontmatterTags/TOML:21-4 140676 28727 -79.58% benchmark old allocs new allocs delta BenchmarkFrontmatterTags/TOML:1-4 173 60 -65.32% BenchmarkFrontmatterTags/TOML:11-4 625 138 -77.92% BenchmarkFrontmatterTags/TOML:21-4 1106 210 -81.01% benchmark old bytes new bytes delta BenchmarkFrontmatterTags/TOML:1-4 9231 2912 -68.45% BenchmarkFrontmatterTags/TOML:11-4 19808 5184 -73.83% BenchmarkFrontmatterTags/TOML:21-4 31200 7536 -75.85% ``` See #3541 Updates #3464
2017-06-03parser: Add BenchmarkFrontmatterTagsBjørn Erik Pedersen
The list handling is surprisingly expensive: ``` ▶ go test -run="NONE" -bench="BenchmarkFrontmatterTags" -test.benchmem=true ./parser | prettybench PASS benchmark iter time/iter bytes alloc allocs --------- ---- --------- ----------- ------ BenchmarkFrontmatterTags/JSON:1-4 1000000 2039.00 ns/op 912 B/op 20 allocs/op BenchmarkFrontmatterTags/JSON:11-4 300000 5202.00 ns/op 1640 B/op 44 allocs/op BenchmarkFrontmatterTags/JSON:21-4 200000 7993.00 ns/op 2392 B/op 65 allocs/op BenchmarkFrontmatterTags/YAML:1-4 200000 9359.00 ns/op 5928 B/op 66 allocs/op BenchmarkFrontmatterTags/YAML:11-4 100000 21218.00 ns/op 8408 B/op 140 allocs/op BenchmarkFrontmatterTags/YAML:21-4 50000 32852.00 ns/op 10920 B/op 211 allocs/op BenchmarkFrontmatterTags/TOML:1-4 100000 21505.00 ns/op 9231 B/op 173 allocs/op BenchmarkFrontmatterTags/TOML:11-4 20000 82919.00 ns/op 19808 B/op 625 allocs/op BenchmarkFrontmatterTags/TOML:21-4 10000 141847.00 ns/op 31200 B/op 1106 allocs/op ok github.com/spf13/hugo/parser 17.890s ``` See #3464
2017-03-20parser: Improve TOML frontmatter parser performanceAlbert Nigmatzianov
Difference between toml.Load(string(datum)) and toml.LoadReader(bytes.NewReader(datum)): benchmark old ns/op new ns/op delta BenchmarkLoad-4 82068 78489 -4.36% benchmark old allocs new allocs delta BenchmarkLoad-4 494 493 -0.20% benchmark old bytes new bytes delta BenchmarkLoad-4 17009 16913 -0.56%
2017-03-15Update to new go-toml APIBjørn Erik Pedersen
Closes #3142
2017-03-13parser: Accept JSON frontmatter without leading "{\n"crasm
Accept JSON frontmatter without leading "{\n" so that one line frontmatters such as `{"param":"paramvalue"}` no longer silently render empty html.
2017-03-11parser: Refactor frontmatter parser and add testsCameron Moore
Lots of cleanups here: - Refactor InterfaceToConfig and InterfaceToFrontMatter to use io.Writer. - Simplify InterfaceToFrontMatter by wrapping InterfaceToConfig. - Export FrontmatterType since we return it in DetectFrontMatter. - Refactor removeTOMLIdentifier to avoid blindly replacing "+++". - Update HandleJSONMetaData to return an empty map on nil input. - Updates vendored goorgeous package and test for org-mode frontmatter. - Add tests and godoc comments. Coverage for parser package increased from 45.2% to 85.2%.
2017-02-21all: Add org-mode supportChase Adams
Fixes #1483 See #936
2016-11-22commands, hugolib, parser, tpl: Use errors.New instead of fmt.Errorfbogem
2016-09-11parser: Use strings.Contains instead of strings.Indexbogem
Closes #2400
2016-09-11parser: Simplify err conditionsbogem
2016-08-20Switch to a more up to date TOML libraryBjørn Erik Pedersen
Fixes #2089
2016-07-13Update frontmatter.goHenrique Dias
2016-04-26Export "detectFrontMatter" to fix caddy-hugoHenrique Dias
Closes #2108
2016-04-14Chomp Unicode BOM if presentMattias Wadman
Useful if using or sharing files with users that use editors that append a unicode byte order marker header (like Windows notepad). This will still assume files are UTF-8 encoded. Closes #2075
2016-03-24parser: Remove unused varsBjørn Erik Pedersen
2016-03-23parser: Make the constant vars ... constantsBjørn Erik Pedersen
2016-03-23parser: Fix ALL_CAPS var names in testBjørn Erik Pedersen
2016-03-23parser: Spring code cleaningBjørn Erik Pedersen
2016-03-14parser: Unexport some internalsBjørn Erik Pedersen
2016-03-14parser: Remove unused codeBjørn Erik Pedersen
2016-02-13Fix spelling and go vet errorsDerek Perkins
2015-12-10Add copyright header to that source files that don’t have one.Anthony Fok
See #1646
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-09-25Allow for any (short) line begining or ending with html commentSven Dowideit
Fixes #1428
2015-08-19Fix typo, "delemiters" -> "delimiters"Icaro Seara
2015-08-03Fix searching YAML/TOML delimiters in frontmatterTatsushi Demachi
When a YAML/TOML's delimiter character sequence is included in a frontmatter string, parser mistakes it as a delimiter. This fixes it by checking a character right before the delimiter sequence is '\n' or it is the beginning of the frontmatter. Fix #1320
2015-08-02Trim trailing spaces from YAML and TOML delimitersJeff Hodges
When someone hits space after typing "---" (or "+++") but before they hit return, hugo silently failed to parse the file. This corrects that.
2015-05-08Update test logs for uniformity and consistencybep
Many minor fixes to make test logs more consistent and correct a mispelling. Standardize on "[%i] got X but expected Y" for log messages. Using a consistent layout makes it easier to read the test results. This was mostly changing "Got" to "got". Swapped the order of values on several calls to bring them in line with the convention. A few log messages had a sequence number added to identify the exact scenario that failed. Otherwise, there would be no way to ascertain which failed When there are many scenarios. Correct spelling of "expected." Fixes #1028 Merged be2097e1ad789eca5d893805a059d94defbe5c48 [close #1040]
2015-05-08add undraft commandJoel Scoble
2015-03-11Correct initialisms as suggested by golintAnthony Fok
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.
2015-03-10parser: add some frontmatter test casesbep