urubu
urubu copied to clipboard
base URL
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.
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?
I think the best solution is to introduce a parameter base_URL
in _site.yml
that by default is set to /
.
+1 to the solution above. So, congratulations for Jan. Urubu is very good.
The other option is to leave all URLs relative instead of having them assume '/' or some base url.
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?
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.
Also, Urubu is great ! Just the lean python tool I needed to NOT create a static blog.
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.
Ok - the proposed pull request seems ok to me, have you reviewed it and do you agree?
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...
Mm, my question was intended for @SoftwareMaven to have a 2nd opinion.
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.
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?
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.
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.
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.
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.)
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/
.
I've opened PRs at #18 and jandecaluwe/urubu-quickstart#2 adding a base URL feature. It's working great for me.
Works fine. With bash extended blogging, the _build fix can be done with mv !(prefix) prefix
.
Just add some documentation (copied from the PR) so this should be ready to go.
:+1: Thanks!
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.
Could be interesting to add the prefix question + possible local solutions (i.e. patching _build
or tservice) as an anticipated FAQ. PR welcome :-)