Skip to content

Commit 1f9b596

Browse files
committed
1. Added rake task for simple configuration of subdirectory deployment.
2. Updated READEME documentation regarding deploying to subdirectories. 3. Fixed related mistake in pagination and header links
1 parent f81bdbc commit 1f9b596

File tree

5 files changed

+78
-18
lines changed

5 files changed

+78
-18
lines changed

.themes/classic/source/_includes/head.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
<meta name="keywords" content="{{page.keywords}}"/>
2020
{% endif %}
2121

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>
22+
<link href="{{ site.root }}/images/favicon.png" rel="shortcut icon" />
23+
<link href="{{ site.root }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
24+
<script src="{{ site.root }}/javascripts/modernizr-2.0.js"></script>
2525
<script src="http://s3.amazonaws.com/ender-js/jeesh.min.js"></script>
26-
<script src="{{ site.url }}/javascripts/octopress.js" type="text/javascript"></script>
26+
<script src="{{ site.root }}/javascripts/octopress.js" type="text/javascript"></script>
2727
<link href='http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
2828
<link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css'>
29-
<link href="{{ site.url }}/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
29+
<link href="{{ site.root }}/atom.xml" rel="alternate" title="{{site.title}}" type="application/atom+xml"/>
3030
{% include google_analytics.html %}
3131
{% include google_plus_one.html %}
3232
{% include twitter_sharing.html %}

.themes/classic/source/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
<nav role="pagination">
1414
<div>
1515
{% if paginator.next_page %}
16-
<a class="prev" href="/page{{paginator.next_page}}/">&larr; Older</a>
16+
<a class="prev" href="{{ site.root }}/page{{paginator.next_page}}/">&larr; Older</a>
1717
{% endif %}
18-
<a href="/blog/archives">Blog Archives</a>
18+
<a href="{{ site.root }}/blog/archives">Blog Archives</a>
1919
{% if paginator.previous_page and paginator.previous_page > 1 %}
20-
<a class="next" href="/page{{paginator.previous_page}}/">Newer &rarr;</a>
20+
<a class="next" href="{{ site.root }}/page{{paginator.previous_page}}/">Newer &rarr;</a>
2121
{% elsif paginator.previous_page %}
22-
<a class="next" href="/">Newer &rarr;</a>
22+
<a class="next" href="{{ site.root }}/">Newer &rarr;</a>
2323
{% endif %}
2424
</div>
2525
</nav>

README.markdown

+29-5
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,46 @@ The `config_deploy` rake task takes a branch name as an argument and creates a [
118118
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.
119119
Github will queue your site for publishing (which usually occurs instantly or within minutes if it's your first commit).
120120

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.
122121

123-
For Octopress my cofigs would be set up like this:
122+
### Deploying to a Subdirectory (Github Project Pages does this)
124123

125-
# _config.yaml
124+
If you're deploying to a subdirectory on your site, or if you're using Github's project pages, make sure you set up your urls correctly in your configs.
125+
You can do this automatically:
126+
127+
rake set_root_dir[your/path]
128+
129+
# To go back to publishing to the document root
130+
rake set_root_dir[/]
131+
132+
Then update your `_config.yml` and `Rakefile` as follows:
133+
134+
# Change the url in _config.yml
135+
url: http://yoursite.com/your/path
136+
137+
# If deploying with rsync, update your Rakefile path
138+
document_root = "~/yoursite.com/your/path"
139+
140+
To manually configure deployment to a subdirectory, you'll change `_config.yml`, `config.rb` and `Rakefile`
141+
142+
# Example for deploying to Octopress's Github Pages
143+
144+
# _config.yml
126145
destination: public/octopress
127146
url: http://imathis.github.com/octopress
128147
subscribe_rss: /octopress/atom.xml
129148
root: /octopress
130149

131-
# config.rb
150+
# config.rb - for Compass & Sass
132151
http_path = "/octopress"
152+
http_images_path = "/octopress/images"
153+
http_fonts_path = "/octopress/fonts"
154+
css_dir = "public/octopress/stylesheets"
155+
133156

134157
# Rakefile
135158
public_dir = "public/octopress"
136-
159+
# If deploying with rsync, update your Rakefile path
160+
document_root = "~/yoursite.com/your/path"
137161

138162
## License
139163
(The MIT License)

Rakefile

+34-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,40 @@ task :push do
124124
end
125125
end
126126

127-
desc "setup _deploy folder and deploy branch"
127+
desc "Update configurations to support publishing to root or sub directory"
128+
task :set_root_dir, :dir do |t, args|
129+
puts ">>> !! Please provide a directory, eg. rake config_dir[publishing/subdirectory]" unless args.dir
130+
if args.dir
131+
if args.dir == "/"
132+
dir = ""
133+
else
134+
dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, '');
135+
end
136+
rakefile = IO.read(__FILE__)
137+
rakefile.sub!(/public_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "public_dir\\1=\\2\\3public#{dir}\\3")
138+
File.open(__FILE__, 'w') do |f|
139+
f.write rakefile
140+
end
141+
compass_config = IO.read('config.rb')
142+
compass_config.sub!(/http_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_path\\1=\\2\\3#{dir}/\\3")
143+
compass_config.sub!(/http_images_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_images_path\\1=\\2\\3#{dir}/images\\3")
144+
compass_config.sub!(/http_fonts_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_fonts_path\\1=\\2\\3#{dir}/fonts\\3")
145+
compass_config.sub!(/css_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "css_dir\\1=\\2\\3public#{dir}/stylesheets\\3")
146+
File.open('config.rb', 'w') do |f|
147+
f.write compass_config
148+
end
149+
jekyll_config = IO.read('_config.yml')
150+
jekyll_config.sub!(/^destination:.+$/, "destination: public#{dir}")
151+
jekyll_config.sub!(/^subscribe_rss:.+$/, "subscribe_rss: #{dir}/atom.xml")
152+
jekyll_config.sub!(/^root:.*$/, "root: #{dir}")
153+
File.open('_config.yml', 'w') do |f|
154+
f.write jekyll_config
155+
end
156+
mkdir_p "public#{dir}"
157+
end
158+
end
159+
160+
desc "Setup _deploy folder and deploy branch"
128161
task :config_deploy, :branch do |t, args|
129162
puts "!! Please provide a deploy branch, eg. rake init_deploy[gh-pages] !!" unless args.branch
130163
puts "## Creating a clean #{args.branch} branch in ./#{deploy_dir} for Github pages deployment"

config.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Require any additional compass plugins here.
22
project_type = :stand_alone
3-
# Set this to the root of your project when deployed:
3+
4+
# Publishing paths
45
http_path = "/"
6+
http_images_path = "/images"
7+
http_fonts_path = "/fonts"
58
css_dir = "public/stylesheets"
9+
10+
# Local development paths
611
sass_dir = "sass"
712
images_dir = "source/images"
8-
http_images_dir = "images"
913
fonts_dir = "source/fonts"
10-
http_fonts_dir = "fonts"
1114

1215
line_comments = false
1316
output_style = :compressed

0 commit comments

Comments
 (0)