HUGO

"Make your site browsable from a local file system"

This question is basically identical to an older one: How to make hugo generate links with "/index.html" instead of simply "/" by the end of the link

When I open the html files generated in the public folder, I want the site navigation to work. I don’t want to run the “hugo -server” command at all, I just want the site in the public folder to work as is. Setting relativeUrl and uglyUrl to true in my config file has gotten me most of the way there, but some links are still broken.

I want every single link hugo generates to end in “index.html”, and I don’t want to manually set frontmatter for every page to make this happen. The documentation about URL management URL Management | Hugo suggests that what I am trying to do should be possible.

This will be difficult to troubleshoot without seeing your code. See:
https://discourse.gohugo.io/t/requesting-help/9132

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Sorry, here is a link to the project!

I tried to edit it in to the original post but I can only put two links as I am a new user.

Edit: I should also give an example of a broken link! The link to the homepage “My blog” at the top left, is missing “index.html”. The link to the french version of the page is also broken. Interestingly, the link to the different language pages work, if you open post.hmtl in the public folder, instead of index.html. I don’t know what post.html is, or why it exists. The link to “My blog” however, is always broken.

First, what you are trying to accomplish can be quite difficult. See warning here:
https://discourse.gohugo.io/t/open-built-website-from-local-folder-without-running-a-server/34193/2

Second, ask yourself if it is really worth the effort.

Third, to fix the links to the home page:

mkdir -p layouts/partials
cp themes/ananke/layouts/partials/i18nlist.html layouts/partials/
cp themes/ananke/layouts/partials/site-navigation.html layouts/partials/
layouts/partials/i18nlist.html
{{ if .IsTranslated }}
<h4>{{ i18n "translations" }}</h4>
<ul class="pl0 mr3">
    {{ range .Translations }}
    <li class="list f5 f4-ns fw4 dib pr3">
      {{ $href := .RelPermalink }}
      {{ if .IsHome }}
        {{ $href = path.Join .RelPermalink "index.html" }}
      {{ end }}
      <a class="hover-white no-underline white-90" href="{{ $href }}">{{ .Lang }}</a>
    </li>
    {{ end}}
</ul>
{{ end }}

layouts/partials/site-navigation.html
<nav class="pv3 ph3 ph4-ns" role="navigation">
  <div class="flex-l justify-between items-center center">
    <a href="{{ path.Join .Site.Home.RelPermalink "index.html" }}" class="f3 fw2 hover-white no-underline white-90 dib">
      {{ with .Site.Params.site_logo }}
        <img src="{{ . }}" class="w100 mw5-ns" alt="{{ $.Site.Title }}" />
      {{ else }}
        {{ .Site.Title }}
      {{ end }}
    </a>
    <div class="flex-l items-center">
      {{ partial "i18nlist.html" . }}
      {{ if .Site.Menus.main }}
        <ul class="pl0 mr3">
          {{ range .Site.Menus.main }}
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="{{ .URL }}" title="{{ i18n "pageTitle" . }}">
              {{ .Name }}
            </a>
          </li>
          {{ end }}
        </ul>
      {{ end }}
      {{ partialCached "social-follow.html" . }}
    </div>
  </div>
</nav>

Finally, you still need to sort out a few image URLs (see 404s in your browser’s dev tools).

1 Like

Thanks, I made the changes you suggested, and now there is a link to the homepage that works!
It actually appears above the original link to the homepage, but that’s ok:


It is extremely helpful to understand that this is not a regular use case for hugo, so I will look into other ways to provide a offline version of a site. Thanks again for your help!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.