I'm trying to get the size (width and height) of an image located inside my static folder
I wrote:
{{$imagelink := print "/static" (.Params.image | relURL) }}
{{$imgData := imageConfig $imagelink }}
<p>{{ $imgData.Height }}</p>
<p>{{ $imgData.Width }}</p>
where .Params.image is taken from the YAML metadata, e.g.: image: "images/my-image.PNG" of each post.
The previous works well if I save the file when the server is running. I can get the width and the height, but if I build my site with build_site(local = TRUE) (I'm using blogdown) HUGO can't find the images.
I tried debugging the error with {{ errorf "Specified file at %s not found." $imagelink }}, but whatever path I try it never founds the images.
I also followed this tutorial about imageConfig, where they point out the following:
but {{$imagelink := print "/static/static" (.Params.image | relURL) }} doesn't work either.
I haven't found official documentation regarding this issue. Any help is appreciated.
This issue was solved upgrading HUGO and blogdown to the latest version
Related
I can add a new page with hugo new posts/new-page. But I want to add a page bundle. None of the following work
hugo new posts/2021/10/new-page creates a single new-page.md
hugo new posts/2021/10/new-page/ does the same as above
hugo new posts/2021/10/new-page/index.md works, kind. It creates index.md in the correct path and populates index.md with the archetypes/default.md except, it set the title to index instead of new page
so, how can I add a page bundle with hugo new
You can achieve that using Archetypes , quoting from the docs:
Since Hugo 0.49 you can use complete directories as archetype templates.
in the archetypes/ folder create a new folder named post-bundle/
inside it create a new file index.md
archetypes/post-bundle/index.md :
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---
Then to create a page bundle:
hugo new --kind post-bundle posts/new-page
Notice: I don't think the approach you're doing to set the date in the url is correct , the above method will give a post with the following Permalink : example.com/posts/new-page you can then do the following to get the desired Permalink:
config.toml :
[permalinks]
posts = '/:year/:month/:title/'
In support of Mossab's answer...
a page bundle has three categories:
Branch,
headless
and leaf.
So if you made a file _index.md - it's a Branch bundle, off-the-bat. So viola that's how you make it with hugo new.
If you want a headless bundle, I believe you first need a leaf bundle, and then add:
headless = true to the front matter.
If you want a lead bundle you create an index.md file at any directory level.
So, I believe my point in this is, the way you do this is:
hugo new _index.md
Or
hugo new index.md
and if you want it headless, you use an archetype with the front matter (as Mossab desribes).
Please let me know if I'm possibly misunderstanding something.
I'm using the blogdown theme:
https://github.com/shawnohare/hugo-tufte
I've fixed most of the build warnings I get, but I'm having trouble resolving this one:
Page.UniqueID is deprecated and will be removed in a future release. Use .File.UniqueID
I've tracked down the instance of Page.UniqueID to a couple of files which are used to create margin notes via a shortcode.
{{ $marginnoteDomIdSuffix := .Ordinal }}<label for="marginnote-{{ .Page.UniqueID}}-{{ $marginnoteDomIdSuffix }}" class="margin-toggle">⊕</label>
<input type="checkbox" id="marginnote-{{ .Page.UniqueID}}-{{ $marginnoteDomIdSuffix }}" class="margin-toggle"/>
<span class="marginnote">{{ .Inner }}</span>
I've tried a number of replacements of the .File.UniqueID type (.File.UniqueID, .UniqueID, ..File.UniqueId, you get the idea) as suggested in the warning, but have not had much success.
For my blogdown-created website (using the Xmin theme), the posts directory - from which I can view individual posts - appears on the homepage, instead of individual posts.
https://joshuamrosenberg.com/
This seemed to happen after updating to the lastest version of Hugo. The source for my website is here. I'm a bit puzzled about what to do: do you have any advice?
This is due to a breaking change in Hugo 0.57.0, and I have fixed the issue in the latest version of the XMin theme. Basically you need to replace
{{ range (where .Data.Pages "Section" "!=" "") }}
with
{{ $pages := .Pages }}
{{ if .IsHome }}{{ $pages = .Site.RegularPages }}{{ end }}
{{ range (where $pages "Section" "!=" "") }}
in the template file layouts/_default/list.html.
I'm setting up a blog with HUGO, as a commented code repo, and I'm including source files right from the repos on the posts.
I've been able to get it to a working condition and want to improve it but I'm stuck.
What I've done
There's a .gitignore'd repos dir inside the HUGO site root, that holds the source code repos.
There's a getSourceFile.html shortcode:
{{ with .Get 0 }}
<pre><code>{{ readFile . }}</code>
<span class="source-footer">{{.}}</span>
</pre>
{{ end }}
Then, in the post I can use the shortcode like so:
#### Base/EntityTypeConfiguration.cs
Estas clases permiten manejar una clase de configuración por cada clase del modelo...
{{< getSourceFile "repos/EFCoreApp/src/EFCore.App/Base/EntityTypeConfiguration.cs" >}}
and I get this:
Which is pretty nice, since I don't have to copy and paste code, it's 100% up to date and I am sure it compiles.
But this is where I'm stuck!
What I would like to do
1) Setting up the repo root in the front matter so the shortcode is simpler to use, like so:
{{< getSourceFile "src/EFCore.App/Base/EntityTypeConfiguration.cs" >}}
2) Being able to pass the language as a parameter to the shortcode to use it in the highlighting feature, something like so (this does not work):
{{< getSourceFile "src/EFCore.App/Base/EntityTypeConfiguration.cs" "csharp" >}}
getSourceFile.html:
{{ with .Get 0 }}
```{{.Get 1}}
<pre><code>{{ readFile . }}</code>
<span class="source-footer">{{.}}</span>
</pre>
```
{{ end }}
Or better yet, infer it from the file extension! ;-)
I think it shouldn't be too difficult but this is my first experience with Hugo, Go and the Templates, so, Could someone help me with this, please?
Thanks in advance.
I finally got the answer in HUGO's dicussion forum, so I just wanted to post it here to finish the question.
This is the final shortcode:
{{ $file := .Get 0 }}
{{ $repoFilePath := printf "%s/%s" $.Page.Params.reponame $file }}
{{ $repoFile := printf "repos/%s" $repoFilePath }}
{{ $fileExt := replace (index (findRE "(\\.)\\w+$" $file) 0) "." "" }}
<pre><code class="language-{{ $fileExt }}">{{ readFile $repoFile }}</code>
<span class="source-footer">{{ $repoFilePath }}</span>
</pre>
And this even solves the language highlighting from the file extension.
From the "getting started" section it seems this should work, but it doesn't.
hugo new site my-site
hugo new privacy.md
hugo server --watch --includeDrafts
curl -L localhost:1313/privacy/index.html
# 404 page not found
curl -L localhost:1313/privacy.html
# 404 page not found
curl -L localhost:1313/privacy/
# 404 page not found
How can I add a new page?
This is the best tutorial how to create static "landing pages" on Hugo: https://discuss.gohugo.io/t/creating-static-content-that-uses-partials/265/19?u=royston
Basically, you create .md in /content/ with type: "page" in front matter, then create custom layout for it, for example layout: "simple-static" in front matter, then create the layout template in themes/<name>/layouts/page/, for example, simple-static.html. Then, use all partials as usual, and call content from original .md file using {{ .Content }}.
All my static (landing) pages are using this method.
By the way, I'm not using hugo new, I just clone .md file or copy a template into /content/ and open it using my iA Writer text editor. But I'm not using Hugo server either, adapted npm-build-boilerplate is running the server and builds.
Just tested OK with this on Hugo 0.13:
hugo new site my-site
cd my-site
hugo new privacy.md
hugo server -w -D
curl -L localhost:1313/privacy/
Note: You have to either use a theme or provide your own layout template to get something more than a blank page. And of course, some Markdown in privacy.md would also make it even nicer.
See http://gohugo.io/overview/introduction for up-to-date documentation.
I had a similar requirement, to add static page (aboutus in this case). Following steps did the trick,
Created an empty file content/aboutus/_index.md
Created aboutus.html page layouts/section/aboutus.html
Make you have some default frontmatter set in archetypes/default.md
# archetypes/default.md
+++
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
+++
And the single layout in layouts/_default/single.html to render some variable or content
# tags to render markdown content
<h1>{{ .Title }}</h1>
<p>{{ .Content }}</p>
<span>{{ .Params.date }}</span>
Now type hugo new privacy.md which will create a new page on the following directory in content/privacy.md
Take "About" as example:
# will create content/about.md
hugo new about.md
Edit about.md and add the last 2 lines, the metadata/front matter looks like:
title: "About"
date: 2019-03-26
menu: "main"
weight: 50
That should work.