-
-
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 #12440
Conversation
cbac41a
to
a882237
Compare
0bce7e5
to
02c63e5
Compare
113971e
to
4b1c839
Compare
80ec32c
to
651b34f
Compare
651b34f
to
a489689
Compare
QuestionShould we disallow ProblemYou may already be aware of this... I am unable to capture a remote resource as a page resource using
The remote resources appear in the root with their original names, and they should be placed within their respective bundles at the specified path. |
f2cd607
to
235086f
Compare
1bcae26
to
1d7fd9f
Compare
I have added a check for this.
No, that is currently not supported, and will not be in As to
|
FYI... This works almost perfectly:
In the above, The only problem is figuring out how to set the path. With the example site referenced above, I'm getting this:
Instead of this:
The The |
This...
...produces this:
I can get the desired/expected result by passing the resource's
Which produces this:
|
So, the desire may be in the eye of the beholder, but:
|
Regarding resource as value vs. string... thanks. This is great. I'll update the docs. |
In the above, I have to specify |
I've got an updated, working example of adding pages and page resources:
Navigate through the books section, and you'll see content and images as expected... works great! What is unexpected is the structure of the public directory...
The same things happens whether I'm adding a global resource (assets directory) or a remote resource. Again, the site works, it's just the public structure that's surprising. |
Hmm... That doesn't look right .... I will fix. But it's a little odd, because I see no such issues in my tests ... I'll look at your example. |
@jmooring I will see if I can improve/fix this (tomorrow), but you can adjust your example to make the paths "compatible", e.g.
|
I don't know if this is possible, but it would be convenient if the value I give to With |
@jmooring yea, that was the intention, but I was tripped by how we handle resources from "file bundles", where we "tip toe" a little around mixed case filenames. cdb9828 should fix/improve this. I have tested your setup with this template OK: {{/* Get remote data. */}}
{{ $data := dict }}
{{ $url := "https://gohugo.io/shared/examples/data/books.json" }}
{{ with resources.GetRemote $url }}
{{ with.Err }}
{{ errorf "Unable to get remote resource %s: %s" $url . }}
{{ else }}
{{ $data = . | transform.Unmarshal }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %s" $url }}
{{ end }}
{{/* Add pages and page resources. */}}
{{ range $data }}
{{/* Add page. */}}
{{ $content := dict "mediaType" "text/markdown" "value" .summary }}
{{ $dates := dict "date" (time.AsTime .date) }}
{{ $params := dict "author" .author "isbn" .isbn "rating" .rating "tags" .tags }}
{{ $page := dict
"content" $content
"dates" $dates
"kind" "page"
"params" $params
"path" .title
"title" .title
}}
{{ $.AddPage $page }}
{{/* Add page resource. */}}
{{ $item := . }}
{{ with $url := $item.cover }}
{{ with resources.GetRemote $url }}
{{ with.Err }}
{{ errorf "Unable to get remote resource %s: %s" $url . }}
{{ else }}
{{ $content := dict "type" .MediaType.Type "value" .Content }}
{{ $params := dict "alt" $item.title }}
{{ $resource := dict
"content" $content
"params" $params
"path" (printf "%s/cover.%s" $item.title .MediaType.SubType)
}}
{{ $.AddResource $resource }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %s" $url }}
{{ end }}
{{ end }}
{{ end }}
|
This is working really well. I'm sure we'll run into other things later, but this looks good to me. |
772f14d
to
0590671
Compare
Closes gohugoio#12427 Closes gohugoio#12485 Closes gohugoio#6310 Closes gohugoio#5074
0590671
to
e2d66e3
Compare
i18n
for current language.lang
is defined.path
starts with a slashSome API/implementation notes:
.Page.File.IsContentAdapter
(new) returns whether the backing file is a content adapter.