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

base URL #7

Open
rothos opened this issue Apr 30, 2014 · 24 comments
Open

base URL #7

rothos opened this issue Apr 30, 2014 · 24 comments

Comments

@rothos
Copy link

rothos commented Apr 30, 2014

If I am, say, at a university where my webspace is at http://univ.edu/~name/, is there a way to prefix all internal reflinks by that URL? It seems now that urubu assumes it lives at the base directory.

@jandecaluwe
Copy link
Owner

I understand the issue, but I don't have a good solution immediately. I would like to keep the concepts that the locally generated site is deployed to production unchanged, and that links are root-relative. Anyone with ideas?

@rothos
Copy link
Author

rothos commented May 2, 2014

I think the best solution is to introduce a parameter base_URL in _site.yml that by default is set to /.

@jrborbars
Copy link

+1 to the solution above. So, congratulations for Jan. Urubu is very good.

@SoftwareMaven
Copy link
Contributor

The other option is to leave all URLs relative instead of having them assume '/' or some base url.

@jandecaluwe
Copy link
Owner

From what I read there are good reasons to avoid relative URLs. Certainly root-relative is simpler and a natural fit to systems like Urubu (with local testing and remote deployment).

Another idea: would it be possible to keep the desired feature out of Urubu by some clever redirection trick on a server?

@webplate
Copy link

I don't know that kind of trick, but as the feature is capital to me, I've added an optionnal root: parameter in _site.yml. Don't specify it, the behaviour stays the same, specify it and it gets appended at the beginning of every internal link.
There's two pull requests, on for urubu and one for urubu-quickstart.

If you accept this pull, I could write the appropriate doc modifications.

@webplate
Copy link

Also, Urubu is great ! Just the lean python tool I needed to NOT create a static blog.

@SoftwareMaven
Copy link
Contributor

Many people who hit this problem aren't going to have access to the Apache configurations to do URL re-writing, since it will depend on the admin giving them access to mod_rewrite.

If you do have access to mod_rewrite, you can add something like this to your .htaccess file:

RewriteRule /(.*) /~name/$1

This tells Apache to rewrite URLs as the pages are served so that /foo becomes /~name/foo but it ignores any relative URLs, so ../foo remains ../foo.

But the idea of a root parameter seems useful to me, as I use Urubu in various contexts where I might not be able to include a RewriteRule like that. A big part of the value of a static site generator, IMO, is that the server isn't needing to perform any processing on the pages it serves.

@jandecaluwe
Copy link
Owner

Ok - the proposed pull request seems ok to me, have you reviewed it and do you agree?

@webplate
Copy link

To be honest, I haven't tested functionalities outside the quickstart default. Could you send me a template with tags and any other functionality worth testing ? I haven't found out how to use them in the manual...

@jandecaluwe
Copy link
Owner

Mm, my question was intended for @SoftwareMaven to have a 2nd opinion.

@SoftwareMaven
Copy link
Contributor

So I just got a chance to review it. The only things I would change:

  • Make sure there is not a trailing slash on root. Or make sure there is. Either way, make sure that the output is consistent and isn't adding spurious /'s based on whatever assumption is made.
  • Add documentation of the above.

@jandecaluwe
Copy link
Owner

I tried the pull request, and my problem is that I cannot test a root setting locally, with the local server. Shouldn't that be a requirement?

@SoftwareMaven
Copy link
Contributor

If you are on a *nix flavor, after you create a build with root=foo, you could create a symlink in the _build directory:

cd _build && ln -s . foo

Now, /foo will serve everything in /, and the URLs will go through /foo.

The alternative is to manually move the contents of _build into foo:

cd _build && mkdir foo && mv * foo  # foo will get passed since if can't move into itself

This would probably be a slightly better test, as it would cause 404's for anything without the proper /foo URI prefix.

@jandecaluwe
Copy link
Owner

I see - do the required modifications outside of Urubu, e.g. in the Makefile. Fine. I don't have much time, but if someone wants to update the pull request taking into account your earlier comments, I will gladly accept it.

@jiffyclub
Copy link
Contributor

Jekyll has a baseurl option that causes the server to serve pages from a prefix, e.g. localhost:8000/prefix/. But I don't know enough about Python's built in servers to say how to do the same thing here.

@jandecaluwe
Copy link
Owner

I am OK with the solution as outlined in this thread. All it takes is for someone to update PR #15 or raise a new one accordingly. (I have no need/time for this feature.)

@jiffyclub
Copy link
Contributor

I will probably have a go at re-writing that PR soon because I'm currently unable to deploy to gh-pages without some kind of prefix/root option.

As for the server, I wrote this little script that starts a Tornado static file server with an optional prefix: https://gist.github.com/jiffyclub/043a44b524859a3cf70b

I can do tserv _build --prefix=prefix and then browse the site at http://localhost:8000/prefix/.

@jiffyclub
Copy link
Contributor

I've opened PRs at #18 and jandecaluwe/urubu-quickstart#2 adding a base URL feature. It's working great for me.

@jandecaluwe
Copy link
Owner

Works fine. With bash extended blogging, the _build fix can be done with mv !(prefix) prefix.

@jandecaluwe
Copy link
Owner

Just add some documentation (copied from the PR) so this should be ready to go.

@jiffyclub
Copy link
Contributor

👍 Thanks!

@jiffyclub
Copy link
Contributor

If anyone is still looking for a way to preview their site with the baseurl set, I've released my Tornado static file server tool as an installable Python package called tservice, more info at https://github.com/jiffyclub/tservice.

@jandecaluwe
Copy link
Owner

Could be interesting to add the prefix question + possible local solutions (i.e. patching _build or tservice) as an anticipated FAQ. PR welcome :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants