Browse code

Added support and documentation for deploying to subdirectories (like with gh-pages)

Brandon Mathis authored on 16/07/2011 at 13:29:09
Showing 11 changed files
... ...
@@ -129,8 +129,10 @@ module Jekyll
129 129
     # Returns string
130 130
     #
131 131
     def category_links(categories)
132
+      dir = @context.registers[:site].config['category_dir']
133
+      root_url = @context.registers[:site].config['root']
132 134
       categories = categories.sort!.map do |item|
133
-        "<a class='category' href='/#{@context.registers[:site].config['category_dir']}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>"
135
+        "<a class='category' href='#{root_url}/#{dir}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>"
134 136
       end
135 137
 
136 138
       case categories.length
... ...
@@ -1,5 +1,5 @@
1 1
 {% capture category %}{{ post.categories | size }}{% endcapture %}
2
-<h1><a href="{{ post.url }}">{{post.title}}</a></h1>
2
+<h1><a href="{{ site.root }}{{ post.url }}">{{post.title}}</a></h1>
3 3
 <time datetime="{{ post.date | datetime }}" pubdate>{{ post.date | date: "<span class='month'>%b</span> <span class='day'>%d</span> <span class='year'>%Y</span>"}}</time>
4 4
 {% if category != '0' %}
5 5
 <footer>
... ...
@@ -1,7 +1,7 @@
1 1
 {% unless page.no_header %}
2 2
   <header>
3 3
     {% if index %}
4
-      <h1 class="entry-title"><a href="{{ post.url }}">{{ post.title | titlecase }}</a></h1>
4
+      <h1 class="entry-title"><a href="{{ site.root }}{{ post.url }}">{{ post.title | titlecase }}</a></h1>
5 5
     {% else %}
6 6
       <h1 class="entry-title">{{ page.title | titlecase }}</h1>
7 7
     {% endif %}
... ...
@@ -13,7 +13,7 @@
13 13
 {% if index %}
14 14
   <div class="entry-content">{{ content | exerpt | smart_quotes }}</div>
15 15
   <footer>
16
-    <a rel="full-article" href="{{ post.url }}">Read on &rarr;</a>
16
+    <a rel="full-article" href="{{ site.root }}{{ post.url }}">Read on &rarr;</a>
17 17
   </footer>
18 18
 {% else %}
19 19
 <div class="entry-content">{{ content | smart_quotes }}</div>
... ...
@@ -12,7 +12,7 @@
12 12
     var pinboardInit = document.createElement('script');
13 13
     pinboardInit.type = 'text/javascript';
14 14
     pinboardInit.async = true;
15
-    pinboardInit.src = '/javascripts/pinboard.js';
15
+    pinboardInit.src = '{{ site.root }}/javascripts/pinboard.js';
16 16
     document.getElementsByTagName('head')[0].appendChild(pinboardInit);
17 17
   })();
18 18
 </script>
... ...
@@ -3,7 +3,7 @@
3 3
   <ul id="recent_posts">
4 4
     {% for post in site.posts limit: site.recent_posts %}
5 5
       <li class="post">
6
-        <a href="{{ post.url }}">{{ post.title }}</a>
6
+        <a href="{{ site.root }}{{ post.url }}">{{ post.title }}</a>
7 7
       </li>
8 8
     {% endfor %}
9 9
   </ul>
... ...
@@ -9,7 +9,7 @@
9 9
       getTwitterFeed("{{site.twitter_user}}", {{site.twitter_tweet_count}}, {{site.twitter_show_replies}});
10 10
     });
11 11
   </script>
12
-  <script src="/javascripts/twitter.js" type="text/javascript"> </script>
12
+  <script src="{{ site.root }}/javascripts/twitter.js" type="text/javascript"> </script>
13 13
   {% if site.twitter_follow_button %}
14 14
     <a href="http://twitter.com/{{ site.twitter_user }}" class="twitter-follow-button" data-width="208px" data-show-count="{{ site.twitter_show_follower_count }}">Follow @{{ site.twitter_user }}</a>
15 15
   {% else %}
... ...
@@ -19,14 +19,14 @@
19 19
     <meta name="keywords" content="{{page.keywords}}"/>
20 20
   {% endif %}
21 21
 
22
-  <link href="/images/favicon.png" rel="shortcut icon" />
23
-  <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
24
-  <script src="/javascripts/modernizr-2.0.js"></script>
22
+  <link href="{{ site.url }}/images/favicon.png" rel="shortcut icon" />
23
+  <link href="{{ site.url }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
24
+  <script src="{{ site.url }}/javascripts/modernizr-2.0.js"></script>
25 25
   <script src="http://s3.amazonaws.com/ender-js/jeesh.min.js"></script>
26
-  <script src="/javascripts/octopress.js" type="text/javascript"></script>
26
+  <script src="{{ site.url }}/javascripts/octopress.js" type="text/javascript"></script>
27 27
   <link href='http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
28 28
   <link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
29
-  <link href="/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
29
+  <link href="{{ site.url }}/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
30 30
   {% include google_analytics.html %}
31 31
   {% include google_plus_one.html %}
32 32
   {% include twitter_sharing.html %}
... ...
@@ -1,5 +1,5 @@
1 1
 <hgroup>
2
-  <h1><a href="/">{{ site.title }}</a></h1>
2
+  <h1><a href="{{ site.root }}">{{ site.title }}</a></h1>
3 3
   {% if site.subtitle %}
4 4
     <h2>{{ site.subtitle }}</h2>
5 5
   {% endif %}
... ...
@@ -11,6 +11,6 @@
11 11
   </fieldset>
12 12
 </form>
13 13
 <ul role="main-nav">
14
-  <li><a href="/">Blog</a></li>
15
-  <li><a href="/blog/archives">Archives</a></li>
14
+  <li><a href="{{ site.root }}/">Blog</a></li>
15
+  <li><a href="{{ site.root }}/blog/archives">Archives</a></li>
16 16
 </ul>
... ...
@@ -118,6 +118,23 @@ The `config_deploy` rake task takes a branch name as an argument and creates a [
118 118
 This prepares your branch for easy deployment. The `rake deploy` task copies the generated blog from the `public` directory to the `_deploy` directory, adds new files, removes old files, sets a commit message, and pushes to Github.
119 119
 Github will queue your site for publishing (which usually occurs instantly or within minutes if it's your first commit).
120 120
 
121
+**Please note,** Github's project pages will be published to a subdirectory and you'll have to make sure you set up your urls correctly in your configs.
122
+
123
+For Octopress my cofigs would be set up like this:
124
+
125
+    # _config.yaml
126
+    destination: public/octopress
127
+    url: http://imathis.github.com/octopress
128
+    subscribe_rss: /octopress/atom.xml
129
+    root: /octopress
130
+
131
+    # config.rb
132
+    http_path = "/octopress"
133
+
134
+    # Rakefile
135
+    public_dir = "public/octopress"
136
+
137
+
121 138
 ## License
122 139
 (The MIT License)
123 140
 
... ...
@@ -22,7 +22,14 @@ recent_posts: 5
22 22
 category_dir: blog/categories
23 23
 simple_search: http://google.com/search
24 24
 
25
-# Optional configurations
25
+# ----------------------- #
26
+# Optional configurations #
27
+# ----------------------- #
28
+
29
+# If publishing to a subdirectory as in http://site.com/project set this:
30
+# root: /project
31
+# If left blank, urls will be mapped to '/'
32
+root:
26 33
 
27 34
 # RSS feeds can list your email address if you like
28 35
 email: