digitalcraftsman / hugo-material-docs

Port of Martin Donath's mkdocs-material theme to Hugo
MIT License
706 stars 186 forks source link

Top-Level index.md not found if baseurl contains subdirectory #32

Closed griestopf closed 8 years ago

griestopf commented 8 years ago

If you specify the following in your config.toml:

  baseurl = http://mydom.com/subdir

and at the same time specify a menu entry pointing to the top level as shown in the "material" demo

[[menu.main]]
    name   = "Getting Started"
    url    = "/"
    weight = 0

and start hugo server your content will be served to http://localhost/subdir. However, the menu item created with the above [[menu.main]] section points to http://localhost/ (without subdir), where the hugo server just finds a 404.

I tried with url = ".". This got around the 404 but the menu item is not populated with the level2 headlines from the root's index.md.

Any idea?

digitalcraftsman commented 8 years ago

Hello @griestopf,

for all menu links I used the absURL template function to make all urls absolute by taking the baseurl into account. But the template function seems to have a bug. I've tested it with relURL that makes the menu links relative to the base url. Now, the subdir from which you're serving the site is respected.

Just pull the latest changes.

nathanaa5 commented 7 years ago

@digitalcraftsman I have the same or a similar issue. I used a baseUrl with a subdirectory and the menu no longer rendered. This line in nav_link.html

{{ $isCurrent := eq .Permalink ($currentMenuEntry.URL | absURL | printf "%s") }}

sets $isCurrent to false on the main page when it should be true. This is because $currentMenuEntry.URL | absURL = "example.com" while .Permalink ="example.com\subdirectory"

Please help - how can I fix it? Thanks!

(Also, when using a subdirectory the main content on the main page wouldn't render until I added "type: index", not sure if that is related.)

nathanaa5 commented 7 years ago

Changing that line from: {{ $isCurrent := eq .Permalink ($currentMenuEntry.URL | absURL | printf "%s") }}

to: {{ $isCurrent := eq .URL ($currentMenuEntry.URL | relURL | printf "%s") }}

Fixes it.