blogdown home page not showing toc of posts any more - hugo

I am using blogdown 0.14 with a slightly modified hugo-lithium theme.
It seems that the home page of the blog created has changed.
It used to be a page with the toc of the posts, not it is a page with a link to a page where this toc is displayed.
Is there a way to get back the old behavior?

That was mentioned an hour ago on twitter:
See gohugoio/hugoThemes issue 682 and gohugoio/hugoThemes issue 678
As stated in gohugoio/hugo#6153, Hugo 0.57.0 has a breaking change since now:
(Actually, 0.58.0 will have those changes, 0.57.2 has reverted some of those breaking changes)
home.Pages work like the other sections
Also due to gohugoio/hugo#6154 now:
.Pages include the sub sections
The above breaking changes were made for developing new features like Cascading Front Matter and will be also needed in the future.
However during local testing with Hugo 0.57.0 I noticed that plenty of theme demos currently on the showcase use .Data.Pages or just .Pages to render lists (particularly on the index page) and as a result the list pages of these themes now look weird.
The author of the lithium theme has been notified.
As Yihui Xie (Software engineer #rstudio) comments, the yihui/hugo-lithium fork already illustrates the kind of patch most themes will have to do.
Commit 6da5ac2:
The layouts/_default/list.html included before:
{{ range (where .Data.Pages "Section" "!=" "").GroupByDate "2006" }}
Now:
{{ $pages := .Pages }}
{{ if .IsHome }}
{{ $pages = .Site.RegularPages }}
{{ end }}
{{ range (where $pages "Section" "!=" "").GroupByDate "2006" }}
As mentioned in "Hugo 0.57.2: A couple of Bug Fixes":
This release reverts the behavior for .Pages on the home page to how it behaved in 0.56, but adds a WARNING telling you what to do to prepare for Hugo 0.58.
In short, .Page home will from 0.58 only return its immediate children (sections and regular pages).
In this release it returns .Site.RegularPages.
So to prepare for Hugo 0.58 you can either use .Site.RegularPages in your home template, or if you have a general list.html or RSS template, you can do something like this:
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}}
{{- $pages := $pctx.RegularPages -}}

Related

Integrating code via partials on a Hugo site not working

I am running an open source comment engine on my server which I want to integrate to my Hugo site.
After doing all the listed things below, the comment section is not visible, and only the heading appears.
What are the possible reasons for this and error and how can I solve it?
So I created a partials file for It, added some code in single.hmtl and edited my config.toml correspondingly.
This is what's inside my partial file named commento.html:
<div id="commento"></div>
<script defer src="{{ .Site.Params.CommentoURL }}/js/commento.js"></script>
<noscript>Please enable JavaScript to load the comments.</noscript>
This is what's inside my single.html file:
{{ if and .Site.Params.CommentoURL (and (not .Site.BuildDrafts) (not .Site.IsServer)) -}}
<h2>Comments</h2>
{{ partial "commento.html" . }}
{{- end }}
and I added the commentoURL parameter in config.toml file like this:
CommentoURL = "http://qwerty.abc:8080"
Please Inspect the output HTML. I am pretty sure you will find this empty div:
<div id="commento"></div>
This means that your Javascript is broken. This has nothing to do with Hugo, partials or even Hugo themes. You probably also have a red error in your Javascript console. This is what you should focus on.

The Most recent post will only show at the bottom of the page in hugo

I am trying to add the most recent post to _index.md. When I put in the code on the home page it only shows it at the bottom of the page. If it does show it where I want to go then there will be dupilcation at the bottom of the page. The shortcode is
{{ range .Site.RegularPages.ByDate | first 5 }}
<li>{{ .Title }}</li>
{{end}}
And in my _index.md I have
# Posts
{{< post >}}
# My and Other Projects
[Github](https://github.com/Luharion)
[🔒Cyberscecurity blog](https://rebootcyber.xyz)
Can anyone help me out with this problem?
I tried to move the {{< post >}} and nothing changes.
Your <li> items need to be wrapped in an <ul>. Now you will get:
<p><li>...</li><li>...</li><li>...</li><li>...</li></p>
The rest seems good to me.

How to change the homepage in hugo?

How can I have /posts as homepage?
Should I redirect, change the baseURL in hugo 1config or make changes in
the theme 2config?
Footnotes
1 https://gohugo.io/getting-started/configuration/
2 https://github.com/luizdepra/hugo-coder/wiki/Configurations
You can modify the home.html file, as the index.html file is embedding it and there is nothing else in index.html
https://github.com/luizdepra/hugo-coder/blob/master/layouts/partials/home.html
Make the changes in the above file in theme/layouts/partials/home.html these changes will take effect on the site as soon as you save the file (if you are already running $ hugo server -D)
For me, it helped to add a layouts/index.html file to my theme. Here is its content:
{{ define "main" }}
{{ $pag := .Paginate (where site.RegularPages "Type" "in" site.Params.mainSections ) 6 }}
<div class="archive-body">
{{ range $pag.Pages }}
{{ .Render "li" }}
{{ end }}
</div>
{{ partial "pagination" . }}
{{ end }}
"li" is a partial HTML template, which renders a single page for me.
Then I had to specify mainSections in my config.toml. Since my content is located inside content/post directory, here is the configuration.
[params]
mainSections = ["post"]
Since this is a list, you should be able to add more than one section. For example, if your content is spread let's say between content/post and content/articles and so on. I haven't tried this, though.
I know this is an old question, but the easiest way for me to set a particular markdown page as the landing page was simply to create a layouts/index.html to override my theme's, and put this in it:
<script>window.location = "/mainlist"</script>
This way, I can keep all my theme's styling, not worry about editing templates, and just focus on creating the content. As a newcomer to hugo, this worked quite well as a replacement for Pelican's save_as: index.html.

How to display Hugo categories used to create list

In my Hugo list.html page that is accessed when a user clicks on a category, I'd like the user to be able to see which category they clicked on by displaying it.
I've tried the following code which I think is attempting to get it from the URL:
{{ range .Params.categories }}
{{ . }}
{{ end }}
And my config.toml includes the relevant lines:
[taxonomies]
tag = "tags"
category = "categories"
Presently, nothing is displayed, and no 'a' tags are generated.
The variable .Title is what you are looking for.
When an individual taxonomy term page is being generated, the variable .Title will be set to the current term (that is the actual tag or category).
When the list taxonomy page itself is being generated, it is set to the name of the taxonomy (e.g. tags).
This is different from .Site.Title which is set in the config.toml file.
This is also different from .Title for an individual post which is set from the file's front matter.
So, the following snippet from my website :
<title>{{ .Site.Title }} {{ with .Title }} | {{ . }}{{ end }}</title>
Works equally well for any kind of page since .Title will be automatically set as appropriate for the page type.

How do I make a home/landing page in markdown with Hugo?

Look, Hugo is for writing static (and blog) sites in markdown. GREAT! How do I create the home page (i.e. not the home post)?!
By home page I mean I want to have some markdown file rendered in my theme at the root: http://example.com/, not http://example.com/home (I will change themes if necessary, but I'm currently using hugo-nuo).
Here's how I'm trying to do it:
add my own layouts/index.html (overriding the theme's)
{{ define "main" }}
{{ partial "header.html" . }}
<section class="main">
WHERE I WISH I COULD IMPORT home.md OR SOME SUCH, HECK I'D BE ALRIGHT JUST PUTTING MARKDOWN HERE
</section>
{{ partial "footer.html" . }}
{{ end }}
This incredibly long thread seems to discuss a bunch of issues that've been addressed, but I don't see this answer.
This answer says to use shortcodes. I'm willing to do that, but it looks like shortcodes can only be used from within content (citation needed).
You can add a _index.md into the folder content/ and access it, e.g. via {{ .Content }}.

Resources