Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hugo server not serving subdirectories #793

Closed
trombonehero opened this issue Jan 13, 2015 · 13 comments
Closed

hugo server not serving subdirectories #793

trombonehero opened this issue Jan 13, 2015 · 13 comments
Assignees
Milestone

Comments

@trombonehero
Copy link
Contributor

Hi,

Thanks for hugo: it's a fantastic change from tools like DocPad, which takes minutes (minutes!) to build a not-terribly-complex academic website.

I'm having trouble, however, using hugo server with a baseurl that includes subdirectories. Basically, everything but the front page gets a 404, even though I can see all of the content in the generated public directory.

I can reproduce this with a pretty simple configuration, a lightly modified version of what hugo create site gives me. Here is my (reduced) config.toml file:

baseurl = "http://yourSiteHere/~username/foo/bar"
languageCode = "en-us"
title = "my new hugo site"

I have one piece of content, in content/blog/post.md:

+++
date = "2015-01-01T20:28:38-03:30"
title = "post"

+++
This is the first blog post.

My layouts/index.html file looks like this:

<html>
    <head><title>{{ .Site.Title }}</title></head>
    <body>
        <h1>{{ .Site.Title }}</h1>

        <h2>Links:</h2>
        <ul><li><a href="blog/post">First blog post</a></li></ul>
    </body>
</html>

When I just run hugo server, it generates all of the expected files in the public directory:

public/404.html
public/blog/index.html
public/blog/index.xml
public/blog/post/index.html
public/index.html
public/index.xml
public/sitemap.xml

and the sitemap is correct:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <url>
    <loc>http://localhost:1313/~username/foo/bar/</loc>
    <lastmod>2015-01-01T20:28:38-03:30</lastmod>
    <priority>0</priority>
  </url>

  <url>
    <loc>http://localhost:1313/~username/foo/bar/blog/post/</loc>
    <lastmod>2015-01-01T20:28:38-03:30</lastmod>
  </url>

</urlset>

but the only URL that Hugo actually serves is http://localhost:1313/~username/foo/bar. All of the following URLs result in 404 errors:

http://localhost:1313/~username/foo/bar/
http://localhost:1313/~username/foo/bar/blog
http://localhost:1313/~username/foo/bar/blog/
http://localhost:1313/~username/foo/bar/blog/index.html
http://localhost:1313/blog
http://localhost:1313/blog/

Any idea what might be wrong or how it can be fixed?

@trombonehero trombonehero changed the title hugo server with complex baseurl not serving subdirectories hugo server not serving subdirectories Jan 13, 2015
@bep
Copy link
Member

bep commented Jan 13, 2015

What version do you use? (the output of hugo server).

@trombonehero
Copy link
Contributor Author

I'm using v13, installed via Homebrew:

Hugo Static Site Generator v0.13-DEV buildDate: 2015-01-10T18:24:52-03:30

@anthonyfok
Copy link
Member

Hello @trombonehero,

It might have to do with the theme. I just did a quick test with the Red Lounge theme which seems to work. That said, some themes might have partials with hard-coded paths without regard for baseurl. So please play around with other themes and see if some of them work for you.

Which theme are you using, by the way?

@trombonehero
Copy link
Contributor Author

Hi, and thanks for your responses so far... this seems to be a pretty
active community!

I'm actually not using any theme at all for either my site or the
reduced test case. I just tried cloning and using redlounge, but I get
the same 404 page not found error when I try to visit
/~username/foo/blog/post.

Am I doing something wrong in the configuration that's different from
what you're using?

Anthony Fok mailto:notifications@github.com
January 12, 2015 at 9:37 PM

Hello @trombonehero https://github.com/trombonehero,

It might have to do with the theme. I just did a quick test with the
Red Lounge https://github.com/tmaiaroto/hugo-redlounge theme which
seems to work. That said, some themes might have partials with
hard-coded paths without regard for baseurl. So please play around
with other themes and see if some of them work for you.

Which theme are you using, by the way?


Reply to this email directly or view it on GitHub
#793 (comment).

@anthonyfok
Copy link
Member

Hi @trombonehero,

You wrote earlier that:

I can reproduce this with a pretty simple configuration, a lightly modified version of what hugo create site gives me. Here is my (reduced) config.toml file:

baseurl = "http://yourSiteHere/~username/foo/bar"
languageCode = "en-us"
title = "my new hugo site"

Sorry, I wasn't reading carefully and didn't notice the lack of a trailing slash (/) in your baseurl, whereas I added a trailing slash to mine, as in:

baseurl = "http://yourSiteHere/~username/foo/bar/"

When I remove the trailing slash, I could reproduce your error, and see that even the stylesheet isn't properly loaded.

Note, however, as you may have already discovered, that this only affects hugo server. If you just run hugo -t redlounge without the server subcommand, the site that is generated in the public/ directory seems perfectly normal when run on your destination server.

Thank you, @trombonehero, I think you may have found a bug in the server subcommand!

Suggested TODO list for Hugo developers:

  1. Document this behaviour, especially for v0.12 users, telling the user to make sure baseurl ends with a trailing slash.
  2. Make hugo server smarter by adding the trailing slash if necessary, and warn the user of the missing trailing slash.

@trombonehero
Copy link
Contributor Author

Hi @anthonyfok,

Thanks for your help. It looks like a pretty clear case of PEBKAC on my end, but I agree that some documentation and a warning message wouldn't go astray. Even better, as you say, would be if Hugo normalized baseurl into whatever format it needs internally.

Anyway, my site is now working consistently between hugo and hugo server, so I no longer need to change config.yaml every time I compile for development vs deployment. Thanks again!

Jon

@bep
Copy link
Member

bep commented Jan 14, 2015

We will fix it.

And, if I read your nick (trombonehero) correctly, we might create a new slogan: "Hugo - for horn players!". Yes, it's me with the saxophone in my avatar.

@anthonyfok
Copy link
Member

For reference, a duplicate bug report has just been filed by @bguiz in Issue #799: "hugo server when BaseUrl has path does not serve any pages other than /".

@anthonyfok
Copy link
Member

The fix turns out to be easier than I thought, as there was already a fixUrl() in hugo/commands/server.go function purely for massaging that baseUrl into a form suitable for serving webpages locally, e.g. adding a missing http:// prefix, so it was easy to add a missing / suffix too. ;-)

The fix is committed in 1cbdd3e. @trombonehero and @bguiz, please test and see it works for you now.

Sidenote: The fact that several users have run into this problem is probably because they are used to Jekyll's norm of leaving out the trailing slash for baseurl, as evident in this paragraph in Jekyll documentation on http://jekyllrb.com/docs/github-pages/:

In _config.yml, set the baseurl option to /project-name – note the leading slash and the absence of a trailing slash.

Here is a reminder to myself to add a note about the trailing / in docs/content/overview/configuration.md.

Cheers,
Anthony

@bguiz
Copy link

bguiz commented Jan 17, 2015

Hi @anthonyfok thanks for looking into this.

I assumed that your commits have been merged into master, so I did this:

go get -v github.com/spf13/hugo

Now with the latest hugo, I run the server again, and I still have the same issue. Trailing slash or otherwise - so it does not appear to have fixed the issue.

@bguiz
Copy link

bguiz commented Jan 17, 2015

Also, I am facing issues with BaseUrl and src attributes, which may be related to this one:

#803

@k4rtik
Copy link
Contributor

k4rtik commented Jan 18, 2015

@bguiz was it -v or -u that you did?

You can otherwise just cd to the hugo directory and do a git pull --rebase.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants