The Most recent post will only show at the bottom of the page in hugo - 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.

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.

Links not working inside featherlight popup

I've built a site with Hugo and using featherlight.js for pop-up lightbox. All working fine when hosted locally. But on the live version I'm having a weird issue where the links inside the pop-up are not working.
A full reproducible example is difficult, but I'll provide the relevant code and perhaps someone can identify what's likely causing the problem or tell me what other info they need.
Relevant code calling featherlight:
<a class="search-icon" href="#" data-featherlight="{{ .link | safeURL }}" > <i class="ti-search"></i> </a>
Where .link is html file compiled from markdown.
If I navigate directly to .link the content shows up fine, and the links in the content are fine, e.g.,:
<p>See more here </p>
But inside the pop-up lightbox, links in the content appear like this:
<p>See more here</p>
i.e., 'here' is outside the </a> tag.
This particular link uses Hugo code:
<p> {{.Params.Link_text}} <a href="{{ .Params.Link | absURL }}" > here </a> </p>
But the same thing occurs for the links written with Markdown.
A featherlight.js bug or something else?
It works after replacing this "https://code.jquery.com/jquery-latest.js" with "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js".

blogdown home page not showing toc of posts any more

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 -}}

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 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