summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
AgeCommit message (Collapse)Author
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-22Move the shortcode parser to the new pageparser packageBjørn Erik Pedersen
See #5324
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-08-17hugolib: Fix shortcode output wrapped in pgllera
Fixes #1642
2018-07-18Add optional lang as argument to rel/relrefBjørn Erik Pedersen
Fixes #4956
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-06Add a newScratch template funcBjørn Erik Pedersen
Fixes #4685
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-05-28hugolib: A little more on shortcode ordinalBjørn Erik Pedersen
2018-05-21Do not return error on .Get "class" and vice versa in shortcodesBjørn Erik Pedersen
The current error handling makes parameter checking in shortcodes too verbose for no good reason. Fixes #4745
2018-05-12Improve markup determination logicVas Sudanagunta
Sets Page.markup earlier (as early as possible, when the page is loaded). Sets it once and only once, removing many redundant calls to determineMarkupType(). This kills a sleeping bug that was avoided by the parts of the code depending on this value making those redundant calls.
2018-04-25hugolib: Fix some shortcode vs .Content corner casesBjørn Erik Pedersen
This is a follow-up to #4632. There were some assumptions in that implementation that did not hold water in all situations. This commit simplifies the content lazy initalization making it more robust. Fixes #4664
2018-04-23hugolib: Add zero-based Ordinal to shortcodeBjørn Erik Pedersen
The count starts at 0 relative to the shortcode's parent: Either the page or the surrounding shortcode. Access it in a shortcode like this: ```bash Ordinal is {{ .Ordinal }} ``` Note that this is a shared ordinal for all shortcodes in the relevant context, so, as an example, you have this in a content page: ```markdown This is a shortcode: {{< hello >}} This is another shortcode: {{< hugo >}} The `.Ordinal` you get in the two shortcodes above is 0 and 1. ``` See #3359
2018-04-22hugolib: Process and render shortcodes in their order of appearanceBjørn Erik Pedersen
Fixes #3359
2018-04-21Make .Content (almost) always available in shortcodesBjørn Erik Pedersen
This resolves some surprising behaviour when reading other pages' content from shortcodes. Before this commit, that behaviour was undefined. Note that this has never been an issue from regular templates. It will still not be possible to get **the current shortcode's page's rendered content**. That would have impressed Einstein. The new and well defined rules are: * `.Page.Content` from a shortcode will be empty. The related `.Page.Truncated` `.Page.Summary`, `.Page.WordCount`, `.Page.ReadingTime`, `.Page.Plain` and `.Page.PlainWords` will also have empty values. * For _other pages_ (retrieved via `.Page.Site.GetPage`, `.Site.Pages` etc.) the `.Content` is there to use as you please as long as you don't have infinite content recursion in your shortcode/content setup. See below. * `.Page.TableOfContents` is good to go (but does not support shortcodes in headlines; this is unchanged) If you get into a situation of infinite recursion, the `.Content` will be empty. Run `hugo -v` for more information. Fixes #4632 Fixes #4653 Fixes #4655
2018-04-17.Get doesn't crash on missing positional paramcmal
fixes #4619
2017-07-04output: Support templates per site/languageBjørn Erik Pedersen
This applies to both regular templates and shortcodes. So, if the site language is French and the output format is AMP, this is the (start) of the lookup order for the home page: 1. index.fr.amp.html 2. index.amp.html 3. index.fr.html 4. index.html 5. ... Fixes #3360
2017-06-13all: Update import paths to gohugoio/hugoBjørn Erik Pedersen
2017-05-13hugolib: Handle shortcode per output formatBjørn Erik Pedersen
This commit allows shortcode per output format, a typical use case would be the special AMP media tags. Note that this will only re-render the "overridden" shortcodes and only in pages where these are used, so performance in the normal case should not suffer. Closes #3220
2017-05-13hugolib: Prepare render per output formatBjørn Erik Pedersen
See #3220
2017-05-09hugolib: Improve shortcode error messageBjørn Erik Pedersen
2017-05-01tpl/collections: Make it a package that stands on its ownBjørn Erik Pedersen
See #3042
2017-04-02tpl: Rework to handle both text and HTML templatesBjørn Erik Pedersen
Before this commit, Hugo used `html/template` for all Go templates. While this is a fine choice for HTML and maybe also RSS feeds, it is painful for plain text formats such as CSV, JSON etc. This commit fixes that by using the `IsPlainText` attribute on the output format to decide what to use. A couple of notes: * The above requires a nonambiguous template name to type mapping. I.e. `/layouts/_default/list.json` will only work if there is only one JSON output format, `/layouts/_default/list.mytype.json` will always work. * Ambiguous types will fall back to HTML. * Partials inherits the text vs HTML identificator of the container template. This also means that plain text templates can only include plain text partials. * Shortcode templates are, by definition, currently HTML templates only. Fixes #3221
2017-04-02Revert "tpl: Rework to handle both text and HTML templates"Bjørn Erik Pedersen
Will have to take another stab at this ... This reverts commit 5c5efa03d2512749950b0d05a7d4bde35ecbdc37. Closes #3260
2017-04-02tpl: Rework to handle both text and HTML templatesBjørn Erik Pedersen
Before this commit, Hugo used `html/template` for all Go templates. While this is a fine choice for HTML and maybe also RSS feeds, it is painful for plain text formats such as CSV, JSON etc. This commit fixes that by using the `IsPlainText` attribute on the output format to decide what to use. A couple of notes: * The above requires a nonambiguous template name to type mapping. I.e. `/layouts/_default/list.json` will only work if there is only one JSON output format, `/layouts/_default/list.mytype.json` will always work. * Ambiguous types will fall back to HTML. * Partials inherits the text vs HTML identificator of the container template. This also means that plain text templates can only include plain text partials. * Shortcode templates are, by definition, currently HTML templates only. Fixes #3221
2017-03-11hugolib: Fix reloading corner cases for shortcodesBjørn Erik Pedersen
This commit fixes two different, but related issues: 1) Live-reload when a new shortcode was defined in the content file before the shortcode itself was created. 2) Live-reload when a newly defined shortcode changed its "inner content" status. This commit also improves the shortcode related error messages to include the full path to the content file in question. Fixes #3156
2017-02-21hugolib: Include full filepath on shortcode errorsBjørn Erik Pedersen
Fixes #3079
2017-02-17tpl: Refactor packageBjørn Erik Pedersen
Now: * The template API lives in /tpl * The rest lives in /tpl/tplimpl This is bound te be more improved in the future. Updates #2701
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-04all: Refactor to nonglobal file systemsBjørn Erik Pedersen
Updates #2701 Fixes #2951
2017-01-10 all: Refactor to nonglobal template handlingBjørn Erik Pedersen
Updates #2701
2017-01-07all: Refactor to non-global loggerBjørn Erik Pedersen
Note that this looks like overkill for just the logger, and that is correct, but this will make sense once we start with the template handling etc. Updates #2701
2017-01-05hugolib: Correct usage of "shortcode" in error messagesmagikstm
2016-10-13Add context to asciidoc/-tor error loggingC. Hoeppler
Add DocumentName (path to the file being rendered) to RenderingContext and use that information to include the path in the error print. See #2399 Closes #2567
2016-09-08Fix shortcode vs pygmentsBjørn Erik Pedersen
This is the nth attempt to fix an issue by changing the placeholder token pattern, but now we actually have tests for all the historic trouble cases. Fixes #2223
2016-09-06Fix multilingual reload when shortcode changesBjørn Erik Pedersen
This commit also refines the partial rebuild logic, to make sure we do not do more work than needed. Updates #2309
2016-09-06Make it possible to configure Blackfroday per languageBjørn Erik Pedersen
See #2309
2016-09-06Render the shortcodes as late as possibleBjørn Erik Pedersen
This is needed to make shortcode users happy with the new multilanguage support, but it will also solve many other related posts about "stuff not available in the shortcode". We will have to revisit this re the handler chain at some point, but that will be easier now as the integration test story has improved so much. As part of this commit, the site-building tests in page_test.go is refreshed, they now tests for all the rendering engines (when available), and all of them now uses the same code-path as used in production. Fixes #1229 Fixes #2323 Fixes ##1076
2016-07-21Check for nil Params in shortcode's GetBjørn Erik Pedersen
Fixes #2294
2016-06-15Fix shortcode in markdown headersBjørn Erik Pedersen
This issue was introduced as a fix to shortcode not working in RST. One could argue that Blackfriday and friends should handle `#` in titles, but that will be a discussion for another day. The new placeholder pattern should be RST safe and work with titles. And now with a test so this doesn't break again. Fixes #2192 Fixes #2209 Closes #2210
2016-04-12Revert "Use Node.ID for anchor ID"Bjørn Erik Pedersen
This reverts commit cd558958a0c0ecd06f7560a38e27334fe983e0de.
2016-04-11Use Node.ID for anchor IDBjørn Erik Pedersen
Fixes #2057
2016-04-09Fix potential data race in testBjørn Erik Pedersen
2016-04-09Save auto-detected markup type in Page.Markupypnos
If Page.Markup was not set by the user, it will now be set after guessing from the file extension. This means, Page.Markup will be set in any case. It can be used by a theme to differentiate between markup types. Fixes #1950
2016-03-24hugolib: Some more GoLint fixesBjørn Erik Pedersen
2016-03-21Add Scratch to shortcodeBjørn Erik Pedersen
Fixes #2000
2016-03-21Re-render shortcode on template or data file changeBjørn Erik Pedersen
Fixes #1971
2016-03-14Remove unnecessary type conversionsBjørn Erik Pedersen
2016-03-14Create an alias from shortcode.Page.Site to shortcode.SiteBjørn Erik Pedersen
Fixes #1976