I've been trying to load my octopress site (based on jekyll) to my local network. There is no server, I just want it available locally on a shared folder.
Every time i deploy it to a local folder the css and js and background image links are broken.
The available options such as rsync, github and heroku all require ssh's and passwords. This can be found here: http://octopress.org/docs/deploying/
Is there a rake option that helps with this?
SOLVED:
Kikito, Thank you very much for the guidance.
I just implemented it and forked a git repository. There is one problem, though. I have used this technique to host the same site on Dropbox Public, a local directory and a web host. I had to add an extra / and the slashes add up as links are clicked. Here is the repo and dropbox link:
https://github.com/originalsurfmex/jekyll-relative-bootstrap
Everything works as you say, but I think that if you or others glance at the partials and links in the layouts you will have a better idea.
Alternate Answer -
I had a similar requirement of a locally hosted static html so that I could distribute it to other computers without a web server and have it read from the filesystem by a regular browser.
Rather than fiddle with arcane path syntax in various places -- although it can be done evidenced by other answers in this thread -- I instead chose a workaround by publishing the site to my localhost:4000 served up by Jekyll as per usual, and then used the
wget
utility to download a static copy of the static website which could then be opened and navigated from the filesystem with a standard web browser.wget
will do the hard work of making the paths relative for you.This is the
wget
command I use -The problem is that you are using absolute paths to get to some of your resources. If you want to deploy the site anywhere in the network, then you need to make those relative.
In my case, what I do is to define an (optional) setting called
root
in the pages/posts that need it, pointing to the "relative root" of the project. For example, on a page located inabout/index.html
, the root will be../
, since there is only one level "up":Pages further away in the directories will need more dots:
../../
,../../../
, and so on. Pages in the root folder (like index.html) don't need a root.Then I use that setting to generate all the paths.
If I'm on the page or post itself, and I need to refer to a local image or another page, use
page.root
orpost.root
:It's possible to make the reference directly (
../images/happy.png
) but this works better when you are creating the site, and you are still unsure about the definitive paths of each page.I have all the css and js included in one partial file inside _includes. It creates a variable called
root
to make sure it works with both pages and posts:That's pretty much it.
If you can live with having to generate your site for a specific folder, using the html
<base />
tag may be more straightforward. With all asset paths relative to your root folder, add the following to your default layout:Then use the
jekyll --base-url <folder> <folder>
to deploy your jekyll site to<folder>
with thebaseurl
set up correctly.Note that this also works without changes with the built-in WEBrick server. Start with
jekyll --server
and do not specify a custom--base-url
.Update: as gimpf points out in the comment, this will not work as expected with anchor links. Those will point to the base URL instead of the current page. There are workarounds using JavaScript, e.g. rewrite anchor hrefs with jQuery:
There is an issue on the Jekyll's github that deals with this. Putting
_config.yml
:and then using
{{ site.url }}
will return the url. So for example, to refer to the/css/styles.css
file from a page's header:Sounds like the path to your images/JS/CSS will need a slight adjustment. Try using a path that points to the generated folder.
For example:
Automatic way:
for css/js file:
for other files:
in _config.yml set
add canonical link element:
in one of your js file, add:
for other aspects, use jQuery to manipulate them.