summaryrefslogtreecommitdiffstats
path: root/parser
AgeCommit message (Collapse)Author
2019-09-29Support typed bool, int and float in shortcode paramsBjørn Erik Pedersen
This means that you now can do: {{< vidur 9KvBeKu false true 32 3.14 >}} And the boolean and numeric values will be converted to `bool`, `int` and `float64`. If you want these to be strings, they must be quoted: {{< vidur 9KvBeKu "false" "true" "32" "3.14" >}} Fixes #6371
2019-08-12tests: Convert from testify to quicktestBjørn Erik Pedersen
2019-08-10Avoid unnecessary conversionsChristian Muehlhaeuser
No need to convert these types.
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-06-08Refactor Org mode front matter: Introduce '#+KEY[]:' array notationNiklas Fasching
Hugo requires some front matter values to be arrays (e.g. for taxonomies). Org mode front matter syntax (`#+KEY: VALUE`) does however not support anything but string values normally - which is why goorgeous hardcoded the values for the keys tags, categories & aliases to be parsed as string arrays. This causes problems with custom taxonomies. A simple thing we can do instead is make keywords ending in '[]' be parsed as string arrays.
2019-06-08Improve Org mode support: Replace goorgeous with go-orgNiklas Fasching
Sadly, goorgeous has not been updated in over a year and still has a lot of open issues (e.g. no support for nested lists). go-org fixes most of those issues and supports a larger subset of Org mode syntax.
2019-03-24all: Apply staticcheck recommendationsBjørn Erik Pedersen
2019-03-23Run gofmt -sBjørn Erik Pedersen
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-31Fix some inline shortcode issuesBjørn Erik Pedersen
Fixes #5645 Fixes #5653
2019-01-29Accept hyphen and plus sign in emoji detectionAnthony Fok
Fixes #5635
2018-12-23tpl/transform: Include options in cache keyBjørn Erik Pedersen
See #5555
2018-12-23Rename CSV option from comma to delimiterBjørn Erik Pedersen
See #5555
2018-12-23Add CSV support to transform.UnmarshalBjørn Erik Pedersen
Fixes #5555
2018-12-23tpl/transform: Add transform.Unmarshal funcBjørn Erik Pedersen
Fixes #5428
2018-12-20Move the emoji parsing to pageparserBjørn Erik Pedersen
This avoids double parsing the page content when `enableEmoji=true`. This commit also adds some general improvements to the parser, making it in general much faster: ```bash benchmark old ns/op new ns/op delta BenchmarkShortcodeLexer-4 90258 101730 +12.71% BenchmarkParse-4 148940 15037 -89.90% benchmark old allocs new allocs delta BenchmarkShortcodeLexer-4 456 700 +53.51% BenchmarkParse-4 28 33 +17.86% benchmark old bytes new bytes delta BenchmarkShortcodeLexer-4 69875 81014 +15.94% BenchmarkParse-4 8128 8304 +2.17% ``` Running some site benchmarks with Emoji support turned on: ```bash benchmark old ns/op new ns/op delta BenchmarkSiteBuilding/TOML,num_langs=3,num_pages=5000,tags_per_page=5,shortcodes,render-4 924556797 818115620 -11.51% benchmark old allocs new allocs delta BenchmarkSiteBuilding/TOML,num_langs=3,num_pages=5000,tags_per_page=5,shortcodes,render-4 4112613 4133787 +0.51% benchmark old bytes new bytes delta BenchmarkSiteBuilding/TOML,num_langs=3,num_pages=5000,tags_per_page=5,shortcodes,render-4 426982864 424363832 -0.61% ``` Fixes #5534
2018-12-20parser/pageparser: Split the page lexer into some more filesBjørn Erik Pedersen
See #5534
2018-12-19parser/pageparser: Add a benchmarkBjørn Erik Pedersen
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-11-28parser/pageparser: Fix handling of commented out front matterBjørn Erik Pedersen
When the page parser was rewritten in 0.51, this was interpreted literally, but commented out front matter is used in the wild to "hide it from GitHub", e.g: ``` <!-- +++ title = "hello" +++ --> ``` Fixes #5478
2018-11-27Add inline shortcode supportBjørn Erik Pedersen
An inline shortcode's name must end with `.inline`, all lowercase. E.g.: ```bash {{< time.inline >}}{{ now }}{{< /time.inline >}} ``` The above will print the current date and time. Note that an inline shortcode's inner content is parsed and executed as a Go text template with the same context as a regular shortcode template. This means that the current page can be accessed via `.Page.Title` etc. This also means that there are no concept of "nested inline shortcodes". The same inline shortcode can be reused later in the same content file, with different params if needed, using the self-closing syntax: ``` {{< time.inline />}} ``` Fixes #4011
2018-11-24parser/pageparser: Fix when only shortcode and then summaryBjørn Erik Pedersen
Fixes #5464
2018-11-13More spelling correctionsBjørn Erik Pedersen
2018-11-05Fix shortcode directly following a shortcode delimiterBjørn Erik Pedersen
Fixes #5402
2018-10-31hugolib: Fix broken manual summary handlingBjørn Erik Pedersen
Fixes #5381
2018-10-23Resolve error handling/parser related TODOsBjørn Erik Pedersen
See #5324
2018-10-23herrors: Improve handling of JSON errorsBjørn Erik Pedersen
`*json.UnmarshalTypeError` and `*json.SyntaxError` has a byte `Offset`, so use that. This commit also reworks/simplifies the errror line matching logic. This also makes the file reading unbuffered, but that should be fine in this error case. See #5324
2018-10-22hugolib: Continue the file context/line number errors workBjørn Erik Pedersen
See #5324
2018-10-22hugolib: Remove the now superflous Source structBjørn Erik Pedersen
See #5324
2018-10-22Convert the rest to new page parser code pathsBjørn Erik Pedersen
And remove some now unused code. See #5324
2018-10-22parser/metadecoders: Consolidate the metadata decodersBjørn Erik Pedersen
See #5324
2018-10-22hugolib: Redo the summary delimiter logicBjørn Erik Pedersen
Now that we have a proper page parse tree, this can be greatly simplified. See #5324
2018-10-22hugolib: Integrate new page parserBjørn Erik Pedersen
See #5324
2018-10-22hugolib: Use []byte in shortcode parsingBjørn Erik Pedersen
See #5324
2018-10-22parser/pageparser: Use []byte in page lexerBjørn Erik Pedersen
See #5324
2018-10-22parser/pageparser: Add front matter etc. supportBjørn Erik Pedersen
See #5324
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