Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the [params] concept to front matter #11055

Closed
bep opened this issue Jun 1, 2023 · 4 comments
Closed

Add the [params] concept to front matter #11055

bep opened this issue Jun 1, 2023 · 4 comments

Comments

@bep
Copy link
Member

bep commented Jun 1, 2023

Note that this is

  • Mostly about documentation.
  • We will never (or if we do, we should get some way of converting old) break the "old way" of doing it.

We had a similar situation in language.params, where we allowed custom params at the top level. Now we warn about that and we will eventually remove that option.

So, from a documentation standpoint (API spec) this is problematic because it's hard to define which fields that makes up the API when "field A, B, C are Hugo configuration, all the rest are params".

So this proposal suggest that we from a documentation standpoint encourages front matter on the form:

title: Hello World
date: 2020-01-01
params:
  color: blue

And just to make this clear, this would also continue to work:

title: Hello World
date: 2020-01-01
color: blue

The "world" is a little more complicated than the above, but let us keep it simple for now.

/cc @jmooring

@bep bep added the Proposal label Jun 1, 2023
@bep bep changed the title Add the [params] concept to Add the [params] concept to front matter Jun 1, 2023
@jmooring
Copy link
Member

jmooring commented Jun 1, 2023

Makes sense to me.

I have seen things like this in the wild

{{ .Page.Params.date }}
{{ .Page.Params.draft }}
{{ .Page.Params.iscjklanguage }}
{{ .Page.Params.lastmod }}
{{ .Page.Params.linktitle }}
{{ .Page.Params.publishdate }}
{{ .Page.Params.title }}
{{ .Page.Params.type }}

So, to be backwards compatible, predefined fields (in the root of front matter) need to be available under .Page.Params, but obviously not documented.

Taxonomy terms

Which would be the correct way?

title = 'How to change a lightbulb'
date = 2023-06-01T09:53:36-07:00
tags = ['tag a','tag b']

or

title = 'How to change a lightbulb'
date = 2023-06-01T09:53:36-07:00
[params]
  tags = ['tag a','tag b']

or

title = 'How to change a lightbulb'
date = 2023-06-01T09:53:36-07:00
[taxonomies]
  tags = ['tag a','tag b']

@jmooring
Copy link
Member

Another thing to watch out for. If you define the summary in front matter, and then use the .Summary method in a template, it returns the rendered summary, not the raw field value.

To get the raw field value, you currently have to use .Params.Summary or .Params.summary. A .RawSummary method on page would resolve this, but we need to be aware of breaking existing sites.

@bep bep added Enhancement and removed Proposal labels Aug 14, 2023
@bep bep self-assigned this Aug 14, 2023
@bep bep added this to the v0.118.0 milestone Aug 14, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep added the Pri 1 label Dec 29, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0 Jan 27, 2024
bep added a commit to bep/hugo that referenced this issue Jan 28, 2024
This is deliberately very simple, but should not break anything. We need to introduce this in baby steps, but this should allow us to introduce this in the documentation.

Note that the `params` section's key/values will be added to `.Params` last. This means that you can have different values for "Hugo's summary" and the custom ".Params.summary" if you want to.

Updates gohugoio#11055
bep added a commit to bep/hugo that referenced this issue Jan 28, 2024
This is deliberately very simple, but should not break anything. We need to introduce this in baby steps, but this should allow us to introduce this in the documentation.

Note that the `params` section's key/values will be added to `.Params` last. This means that you can have different values for "Hugo's summary" and the custom ".Params.summary" if you want to.

Updates gohugoio#11055
bep added a commit to bep/hugo that referenced this issue Jan 28, 2024
This is deliberately very simple, but should not break anything. We need to introduce this in baby steps, but this should allow us to introduce this in the documentation.

Note that the `params` section's key/values will be added to `.Params` last. This means that you can have different values for "Hugo's summary" and the custom ".Params.summary" if you want to.

Updates gohugoio#11055
bep added a commit that referenced this issue Jan 28, 2024
This is deliberately very simple, but should not break anything. We need to introduce this in baby steps, but this should allow us to introduce this in the documentation.

Note that the `params` section's key/values will be added to `.Params` last. This means that you can have different values for "Hugo's summary" and the custom ".Params.summary" if you want to.

Updates #11055
@bep bep modified the milestones: v0.123.0, v0.124.0 Jan 29, 2024
@bep bep added this to the v0.123.0 milestone Jan 29, 2024
@bep
Copy link
Member Author

bep commented Jan 29, 2024

I'm marking this as closed for now, I'll create another issue(s) for following up work.

@bep bep closed this as completed Jan 29, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants