How to change the homepage in hugo?
Asked Answered
W

4

5

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

Will answered 5/5, 2019 at 9:30 Comment(0)
O
3

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)

Orly answered 9/5, 2019 at 18:30 Comment(4)
Thank you @Saif Azmi . Do you have any idea how I can determine on what file the index from /posts bases? Thus I'd be able to copy its content to the home.html as you suggested. Modifying the current files here didn't result in changes of /posts index: github.com/luizdepra/hugo-coder/tree/master/layouts/partials/…Will
The index of /posts is rendered by the list.html file. That can be found here: github.com/luizdepra/hugo-coder/blob/master/layouts/posts/…Orly
Thank you @Saif Azmi. After replacing the content of home.html with the one from list.html, the homepage becomes empty. Any other ideas? Maybe I should emphasize my goal: I want visitors to land on /posts in place of the homepage. Similar to wordpress' "Use another page as homepage" function.Will
Then just replace the code in the index page with the one in posts.Orly
P
3

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.

Promote answered 23/1, 2021 at 14:51 Comment(0)
A
2

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.

Arteriosclerosis answered 15/12, 2022 at 10:49 Comment(0)
B
0

As mentioned by Saif, you need to replace the content inside your home.html file located in the 'partials' folder.

# Remove 
{{ partialCached "home/avatar.html" . }}
{{ partialCached "home/author.html" . }}
{{ partialCached "home/socials.html" . }}

# Add
{{ partialCached "posts/li.html" . }}

This should list your blogs on the homepage. However, the blog list also comes with it's own title. This means you will have two titles. To remove the title from the blog list, remove these lines from your index.html.

# Remove these lines from the file
    <header>
      <h1 class="title">
        <a class="title-link" href="{{ .Permalink | safeURL }}">
          {{ title (i18n (lower .Title)) | default .Title }}
        </a>
      </h1>
    </header>

Now you will have a homepage with a list of blogs and without 2 titles.

Make sure to make backups of the files you edit.

Babushka answered 14/3, 2023 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.