-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Create pages from _content.gotmpl #12427
Comments
Thoughts and questions... ConceptHistorically we instruct users that the content directory is for content, and the layouts directory is for templates. This introduces a blended structure, clearly identified by the NamingShould these be called "content templates" or something else? We currently define an archetype as a "template for new content" but this can easily be changed. And we also have content view templates. Possibilities:
ExtensionThe example above uses the Page kindsCan I use Front matter limitationsWould the PathIt looks like the
|
@jmooring thanks for the feedback, much appreciated. I'll put my comments below the same headings as you. A general comment is that part of this needs to be ironed out when testing this. I have the building blocks to relatively quickly get a version ready, and I think it would be good to release a version saying that "the API for this new feature may change slightly in the upcoming versions depending on feedback from users". Concept
I have thought a lot about creating something "new" on the side of everything, but
NamingWell, I don't know. But I can list the different types of
ExtensionI wanted something that didn't have HTML in it, and Page kindsMy example wasn't great. You would set the Front matter limitationsNo limitations that I can think of. From your list, PathYea, that was a mistake. I have adjusted my examples. I thought I would make it explicit that this was a |
Naming:
|
That I like. |
Here's how I imagine the context/API we would pass to the type PagesFromDataTemplateContext interface {
// UseCached returns whether Hugo can use a cached version
// matching the given ETag.
UseCached(eTag any) bool
// AddPage adds a new page to the site.
// The first return value will always be an empty string.
AddPage(any) (string, error)
// AddResource adds a new resource to the site.
// The first return value will always be an empty string.
AddResource(any) (string, error)
// The site to which the pages will be added.
Site() page.Site
// The same template may be executed multiple times for multiple languages.
// The Store can be used to store state between these invocations.
Store() *maps.Scratch
// By default, the template will be executed for the language
// defined by the _content.gotmpl file (e.g. its mount definition).
// This method can be used to activate the template for all languages.
// The return value will always be an empty string.
SetForAllLanguages() string
} |
I assume this means that AddPage will ignore the
I haven't spent any time looking into it, but is there ever a reason to use |
That or throw an error. My initial idea was to allow setting
I rename it to Store, thanks. Yes, it doesn't really matter, but it ... sounds better. |
I agree. I'd say throw an error if |
@jmooring can I borrow your eyes for a minute. For attaching content to pages and resources, I have introduced a new With some examples, I think it would look like this: {{/* Add pages */}}
{{ $.AddPage (dict "path" "p1" "content" (dict "value" "some *markdown*" "mediaType" "text/markdown") }}
{{ $.AddPage (dict "path" "p2" "content" (dict "value" "some <b>HTML</b>" "mediaType" "text/html") }}
{{/* Add resources */}}
{{ $resource := resources.Get "mydata.yaml" }}
{{/* The resource can be accessed via p1's .Resources but it will link to $resource.RelPermalink */}}
{{/* Only path and content needs to be provided. */}}
{{ $.AddResource (dict "path" "p1/data1.yaml" "content" (dict "value" $resource ) "name" "mydata.yaml" "title" "My Data" "params" dict }}
{{ $.AddResource (dict "path" "p1/mytext.txt" "content" (dict "value" "some text" "mediaType" "text/plain") }} Comments:
Thoughts? |
Is this a typo? Should the last two lines above begin with |
Yes, copy and paste ... Fixed. |
1) I am in favor of not using a "markup" field in the content map. In addition to not supporting your 2) While documenting/testing the current implementation, the 3) "For pages, content.value is always a string." I think that's fine. You can always do $resource.Content to populate content.value. As always, I'm sure I'll have more comments and questions after taking this for a spin, but your proposed implementation above looks good to me... it's quite clear. |
One more comment... Initially I suspect that > 90% of usage will be |
Yea; but I suspect Note that |
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
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. |
Note
There will be support for other data sources, e.g.
_content.json
, but that's outside the scope of this proposal.I have experimented and thought long and hard about where to start re. generating
Pages
from data sources. The only scripting language we have built into Hugo is currently Go Templates. It works great as a templating language for HTML markup, but it's a little clunky for more advanced logic. But it's what we have, it's very familiar to many, and we have already a large API set up ready to use.So, I suggest we start there by introducing a new reserved name identifier in the
content
file system_content.*
where the first extension will begotmpl
, i.e._content.gotmpl
:A short example of how it may look:
For bundled
Resources
I think we can say that you would either:Resource
. It would be accessible in a page's.Resources
, but the.Permalink
would point to the original's.content
.As this is early in the build process, the context passed to the template will be limited:
.Site.Title
and similar andi18n
would work as expected..Site.RegularPages
will return empty._content.gotmpl
file in the content tree./cc @jmooring
The text was updated successfully, but these errors were encountered: