I started converting my personal website from Jekyll after spending way too much time in dependency hell. After a day of acquainting myself with Hugo I only look forward to playing more with it.
Conversion and building the theme is mostly working out fine, but I thought I’d gather some questions that have arisen during the process in one thread. I hope that’s fine.
The now function {{ now.Format "2006-01-02"}} doesn’t seem to work in a content page (not a template). How can I use the now function in the body text of a content page? The page is HTML if that matters.
Can I somehow access the slug from my filename in the content dir? Jekyll creates the rendered post slug from the post filename. In Jekyll, Front Matter title: for a given post may be “Carrots are very tasty”, but if filename is 2006-01-02-tasty-carrots.html the rendered filename for :title will be tasty-carrots. I’d like to access tasty-carrots in Hugo. Is it possible? Also, with Jekyll I can also do :title:output_ext to get tasty-carrots.html instead of making it a directory with an index file inside. Is that possible? Which leads me to…
content/about.html too gets rendered as /about/index.html. How can I render it as /about.html?
I have some trouble interpreting the documentation regarding GDPR and “Disable All Services”. It says “An example Privacy Config that disables all the relevant services in Hugo. With this configuration, the other settings will not matter.”
Does the below quoted text mean that all privacy features for Twitter are “enabled”?
[privacy.twitter]
disable = true
I.e., is it the same as below quoted text?
[privacy.twitter]
enableDNT = true
simple = true
My blog images gets rendered to /images/blog/2006/01/02/FILENAME.jpg. Can I somehow call them from my HTML files that I write in content/blog/ without entering the entire path? Would it be possible to create a shortcode that I could call from my blog content pages (say {{< logimg shoe.jpg >}}). As shown above the image/images for a post will be in a path that matches the page publish date that I’m calling it from. I made an attempt but ended up with errors.
You may want to ask this question separately, unless you get others’ responses here. I am inclined to interpret it similarly, however I am neither a Hugo dev nor do I use twitter on my sites.
Should be doable. Easier to help you if you show what you’ve tried.
I created layouts/shortcodes/now.html and put {{ now.Format "2006"}} in it. I used {{< now >}} on content/apage.html and {{ now.Format "2006"}} got printed to the rendered page, unparsed.
Read through them both. Closest I can find is .File.TranslationBaseName, but I guess that would include the date (2006-01-02-tasty-carrots, not tasty-carrots)? Problem is I can’t use .File.TranslationBaseName to format my URLs under [permalinks] in config.toml?
Great, thanks!
OK, I’ll do.
This is somewhat uncomfortable. In layouts/shortcodes/logimg.html there’s <img src="/images/blog/{{ .PublishDate.Format "2006" }}/{{ .PublishDate.Format "02" }}/{{ .PublishDate.Format "01" }}/{{ .Get 0 }}">.
Error is:
execute of template failed: template: shortcodes/logimg.html:1:38: executing "shortcodes/logimg.html" at <.PublishDate.Format>: can't evaluate field PublishDate in type *hugolib.ShortcodeWithPage
Sorry, I was not clear. I said I wanted to “access” tasty-carrots, but actually I wanted to fetch it for use in my URLs so that I could replicate what I had in Jekyll and not break the URLs.
No, in my rendered post URL. Like so: domain.tld/blog/2016/01/02/tasty-carrots/ or domain.tld/blog/2016/01/02/tasty-carrots.html
From this point on, I guess I am. But for the posts that already exist I’d have to go in and edit Front Matter slug: manually. It’d be awesome if hugo import jekyll created a slug: in Front Matter from tasty-carrots in the Jekyll post filename. If I could dream a slugFromFilename option in config.toml:filenameslugPermalink Configuration Value would be awesome That way of creating slugs seems quite sane.