Browse code

now Octopress uses partials

B Mathis authored on 10/03/2010 at 18:23:30
Showing 17 changed files
... ...
@@ -1,11 +1,12 @@
1 1
 require 'active_support'
2 2
 
3
-site_url  = "http://yoursite.com"   # deployed site url for sitemap.xml generator
4
-port      = "4000"     # preview project port eg. http://localhost:4000
5
-site      = "site"     # compiled site directory
6
-source    = "source" # source file directory
7
-stash     = "_stash"
8
-posts     = "_posts"
3
+site_url    = "http://yoursite.com"   # deployed site url for sitemap.xml generator
4
+port        = "4000"      # preview project port eg. http://localhost:4000
5
+site        = "site"      # compiled site directory
6
+source      = "source"    # source file directory
7
+stash       = "_stash"    # directory to stash posts for speedy generation
8
+posts       = "_posts"    # directory for blog files
9
+post_format = "markdown"  # file format for new posts when using the post rake task
9 10
 
10 11
 ## -- Rsync Deploy config -- ##
11 12
 ssh_user      = "user@host.com"    # for rsync deployment
... ...
@@ -29,11 +30,15 @@ end
29 29
 
30 30
 ## if you're deploying with github, change the default deploy to deploy_github
31 31
 desc "default deploy task"
32
-task :deploy => :deploy_rsync do
32
+task :deploy => [:deploy_rsync] do
33
+end
34
+
35
+desc "Generate and deploy task"
36
+task :generate_deploy => [:integrate, :generate, :clean_debug, :deploy] do
33 37
 end
34 38
 
35 39
 desc "generate website in output directory"
36
-task :default => [:generate_site, :generate_style] do
40
+task :generate => [:generate_site, :generate_style] do
37 41
   puts ">>> Site Generating Complete! <<<\n\n"
38 42
 end
39 43
 
... ...
@@ -41,8 +46,7 @@ end
41 41
 desc "Begin a new post in #{source}/_posts"
42 42
 task :post, :filename do |t, args|
43 43
   args.with_defaults(:filename => 'new-post')
44
-  #system "touch #{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename}.markdown"
45
-  open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename.gsub(/[ _]/, '-')}.markdown", 'w') do |post|
44
+  open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename.downcase.gsub(/[ _]/, '-')}.#{post_format}", 'w') do |post|
46 45
     post.puts "---"
47 46
     post.puts "title: \"#{args.filename.gsub(/[-_]/, ' ').titlecase}\""
48 47
     post.puts "---"
... ...
@@ -126,13 +130,13 @@ task :watch do
126 126
 end
127 127
 
128 128
 desc "generate and deploy website via rsync"
129
-multitask :deploy_rsync => [:integrate, :default, :clean_debug] do
129
+multitask :deploy_rsync do
130 130
   puts ">>> Deploying website to #{site_url} <<<"
131 131
   ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
132 132
 end
133 133
 
134 134
 desc "generate and deploy website to github user pages"
135
-multitask :deploy_github => [:integrate, :default, :clean_debug] do
135
+multitask :deploy_github do
136 136
   puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
137 137
   require 'git'
138 138
   repo = Git.open('.')
... ...
@@ -173,13 +177,13 @@ task :stop_serve do
173 173
 end
174 174
 
175 175
 desc "preview the site in a web browser"
176
-multitask :preview => [:default, :start_serve] do
176
+multitask :preview => [:start_serve] do
177 177
   system "open http://localhost:#{port}"
178 178
 end
179 179
 
180 180
 
181 181
 desc "Build an XML sitemap of all html files."
182
-task :sitemap => :default do
182
+task :sitemap do
183 183
   html_files = FileList.new("#{site}/**/*.html").map{|f| f[("#{site}".size)..-1]}.map do |f|
184 184
     if f.ends_with?("index.html")
185 185
       f[0..(-("index.html".size + 1))]
... ...
@@ -194,14 +198,14 @@ task :sitemap => :default do
194 194
       priority = case f
195 195
       when %r{^/$}
196 196
         1.0
197
-      when %r{^/blog}
197
+      when %r{^/articles}
198 198
         0.9
199 199
       else
200 200
         0.8
201 201
       end
202 202
       sitemap.puts %Q{  <url>}
203 203
       sitemap.puts %Q{    <loc>#{site_url}#{f}</loc>}
204
-      sitemap.puts %Q{    <lastmod>#{Time.now.to_s('%Y-%m-%d')}</lastmod>}
204
+      sitemap.puts %Q{    <lastmod>#{Time.now.strftime('%Y-%m-%d')}</lastmod>}
205 205
       sitemap.puts %Q{    <changefreq>weekly</changefreq>}
206 206
       sitemap.puts %Q{    <priority>#{priority}</priority>}
207 207
       sitemap.puts %Q{  </url>}
... ...
@@ -111,8 +111,6 @@ module Helpers
111 111
   end
112 112
   include TagHelper
113 113
   
114
-  # My added helpers
115
-  
116 114
   def to_html_email(address)
117 115
     email = string_to_html(address)
118 116
     "<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>"
... ...
@@ -165,7 +163,7 @@ module Helpers
165 165
     # A very hackish way to handle partials.  We'll go with it till it breaks...
166 166
     def include(partial_name)
167 167
       file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length]
168
-      contents = IO.read("_includes/#{partial_name}")
168
+      contents = IO.read("source/_includes/#{partial_name}")
169 169
       case file_ext
170 170
       when 'haml'
171 171
         Haml::Engine.new(contents).render(binding)
... ...
@@ -180,6 +178,7 @@ module Helpers
180 180
   end
181 181
   
182 182
   include PartialsHelper
183
+  
183 184
 end
184 185
 
185 186
 class String
186 187
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+---
1
+blog_title: My Octopress Blog
2
+
3
+twitter_user: 
4
+tweet_count: 3
5
+show_replies: false
6
+
7
+delicious_user: 
8
+delicious_count: 3
9
+
10
+full_url: 
11
+disqus_short_name: 
12
+
13
+google_custom_search_id:
14
+google_analytics_tracking_id:
15
+
16
+---
0 17
\ No newline at end of file
1 18
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+%h4 My Delicious <a class="small" href="http://delicious.com/#{page.delicious_user}">more &rarr;</a>
1
+#delicious
2
+  %script(type="text/javascript" src="http://feeds.delicious.com/v2/js/#{page.delicious_user}?title=&count=#{page.delicious_count}&sort=date&extended")
0 3
\ No newline at end of file
1 4
new file mode 100644
... ...
@@ -0,0 +1,11 @@
0
+:javascript
1
+  (function() {
2
+      var links = document.getElementsByTagName('a');
3
+      var query = '?';
4
+      for(var i = 0; i < links.length; i++) {
5
+        if(links[i].href.indexOf('#disqus_thread') >= 0) {
6
+          query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
7
+        }
8
+      }
9
+      document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/get_num_replies.js' + query + '"></' + 'script>');
10
+    })();
0 11
\ No newline at end of file
1 12
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+:javascript
1
+  var disqus_url = "#{page.full_url}#{page.url}";
2
+%noscript
3
+  %a(href="http://#{page.disqus_short_name}.disqus.com/?url=ref") View the discussion thread
4
+%script(type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/embed.js")
0 5
\ No newline at end of file
1 6
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+#footer
1
+  .page_width
2
+    Copyright &copy; #{Time.now.strftime('%Y')} - #{page.blog_title} -
3
+    %span.credit Powered by <a href="http://octopress.org">Octopress</a>
4
+
5
+= include "disqus_hook.haml" if page.respond_to?(:disqus_short_name) && page.disqus_short_name
6
+= include "google_analytics.haml" if page.respond_to?(:google_analytics_tracking_id) && page.google_analytics_tracking_id
0 7
\ No newline at end of file
1 8
new file mode 100644
... ...
@@ -0,0 +1,10 @@
0
+:javascript
1
+  var _gaq = _gaq || [];
2
+  _gaq.push(['_setAccount', '#{page.google_analytics_tracking_id}']);
3
+  _gaq.push(['_trackPageview']);
4
+
5
+  (function() {
6
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
7
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
8
+    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
9
+  })();
0 10
\ No newline at end of file
1 11
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+%head
1
+  %title #{page.blog_title} :: #{page.title}
2
+  - if page.respond_to? :description
3
+    %meta(name="description" content="#{page.description}")/
4
+  - if page.respond_to? :keywords
5
+    %meta(name="keywords" content="#{page.keywords}")/
6
+  %link(href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css")
7
+  %script(src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js" type="text/javascript")
8
+  %script(src="/javascripts/mootools-1.2.4.2-more.js" type="text/javascript")
9
+  - if page.respond_to? :twitter_user
10
+    :javascript
11
+      var twitter_user = "#{page.twitter_user}"
12
+      var show_replies = #{page.show_replies};
13
+      var tweet_count = #{page.tweet_count};
14
+    %script(src="/javascripts/octopress.js" type="text/javascript")
15
+    %script(src="/javascripts/twitter.js" type="text/javascript")
16
+  - if page.respond_to? :google_analytics
17
+    %script(src="http://www.google-analytics.com/ga.js" type="text/javascript")
18
+
19
+  - # RSS Feed  
20
+  %link(href="/atom.xml" rel="alternate" title="#{page.blog_title}" type="application/atom+xml")
0 21
\ No newline at end of file
1 22
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+.page_width
1
+  %a.title(href="/")=page.blog_title
2
+  - if page.respond_to? :google_custom_search_id
3
+    #search
4
+      %form(action="http://www.google.com/cse" id="cse-search-box")
5
+        %input(type="hidden" name="cx" value="#{page.google_custom_search_id}")
6
+        %input(type="hidden" name="ie" value="UTF-8")
7
+        %input#q(type="text" name="q")
0 8
\ No newline at end of file
1 9
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+.page_width
1
+  %ul
2
+    %li.alpha
3
+      %a(href="/") Blog
4
+    %li.omega
5
+      %a(href="/about.html") About
6
+    %li.subscribe
7
+      %a(href="/atom.xml") Subscribe
0 8
\ No newline at end of file
1 9
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+.article
1
+  %h2= page.title
2
+  .meta
3
+    - author = (page.respond_to?(:author) && page.author) ? 'by: ' + page.author + ' |' : ''
4
+    #{author} posted: #{page.date.strftime("%B #{page.date.day.ordinalize}, %Y")}
5
+    = (page.respond_to?(:updated) && page.updated) ? " | upated: #{page.updated}" : ''
6
+  = preserve rp(content)
7
+  #disqus_thread= include "disqus_thread.haml" if page.respond_to?(:disqus_short_name) && page.disqus_short_name
0 8
\ No newline at end of file
1 9
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+= include "twitter.haml" if page.respond_to?(:twitter_user) && page.twitter_user
1
+= include "delicious.haml" if page.respond_to?(:delicious_user) && page.delicious_user
0 2
\ No newline at end of file
1 3
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+%h4 Twitter <a class="small" href="http://twitter.com/#{page.twitter_user}">@#{page.twitter_user}</a>
1
+#twitter
2
+  %ul#twitter_status
3
+    Status updating...
0 4
\ No newline at end of file
1 5
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+---
1
+blog_title: My Octopress Blog
2
+author: 
3
+
4
+twitter_user: 
5
+tweet_count: 3
6
+show_replies: false
7
+
8
+delicious_user: 
9
+delicious_count: 3
10
+
11
+full_url: 
12
+disqus_short_name: 
13
+
14
+google_custom_search_id:
15
+google_analytics_tracking_id:
16
+
17
+---
18
+
19
+!!! 1.1 Transitional
20
+%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
21
+
22
+  = include "head.haml"
23
+  %body(id="#{(page.respond_to?(:body_id) ? page.body_id : nil)}")
24
+    #header= include "header.haml"
25
+    #nav= include "navigation.haml"
26
+    #page
27
+      .page_width
28
+        #main
29
+          .blog= include "post.haml"
30
+        #sidebar= include "sidebar.haml"
31
+    = include "footer.haml"
0 32
\ No newline at end of file
... ...
@@ -1,5 +1,6 @@
1 1
 ---
2 2
 blog_title: My Octopress Blog
3
+author: 
3 4
 
4 5
 twitter_user: 
5 6
 tweet_count: 3
... ...
@@ -18,95 +19,13 @@ google_analytics_tracking_id:
18 18
 
19 19
 !!! 1.1 Transitional
20 20
 %html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
21
-  %head
22
-    %title #{page.blog_title} :: #{page.title}
23
-    - if page.respond_to? :description
24
-      %meta(name="description" content="#{page.description}")/
25
-    - if page.respond_to? :keywords
26
-      %meta(name="keywords" content="#{page.keywords}")/
27
-    %link(href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css")
28
-    %link(href="/atom.xml" rel="alternate" title="#{page.blog_title}" type="application/atom+xml")
29
-    - if page.respond_to? :twitter_user
30
-      :javascript
31
-        var twitter_user = "#{page.twitter_user}"
32
-        var show_replies = #{page.show_replies};
33
-        var tweet_count = #{page.tweet_count};
34
-      %script(src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js" type="text/javascript")
35
-      %script(src="/javascripts/mootools-1.2.4.2-more.js" type="text/javascript")
36
-      %script(src="/javascripts/octopress.js" type="text/javascript")
37
-      %script(src="/javascripts/twitter.js" type="text/javascript")
38
-    - if page.respond_to? :google_analytics
39
-      %script(src="http://www.google-analytics.com/ga.js" type="text/javascript")
21
+
22
+  = include "head.haml"
40 23
   %body(id="#{(page.respond_to?(:body_id) ? page.body_id : nil)}")
41
-    #header
42
-      .page_width
43
-        %a.title(href="/")=page.blog_title
44
-        - if page.respond_to? :google_custom_search_id
45
-          #search
46
-            %form(action="http://www.google.com/cse" id="cse-search-box")
47
-              %input(type="hidden" name="cx" value="#{page.google_custom_search_id}")
48
-              %input(type="hidden" name="ie" value="UTF-8")
49
-              %input#q(type="text" name="q")
50
-    #nav
51
-      .page_width
52
-        %ul
53
-          %li.alpha
54
-            %a(href="/") Blog
55
-          %li.omega
56
-            %a(href="/about.html") About
57
-          %li.subscribe
58
-            %a(href="/atom.xml") Subscribe
24
+    #header= include "header.haml"
25
+    #nav= include "navigation.haml"
59 26
     #page
60 27
       .page_width
61
-        #main
62
-          - if page.respond_to? :date
63
-            .blog
64
-              .article
65
-                %h2= page.title
66
-                = preserve rp(content)
67
-              %p.pubdate
68
-                Published:
69
-                =page.date.strftime("%d %b, %Y")
70
-              - if page.respond_to? :disqus_short_name
71
-                #disqus_thread
72
-                :javascript
73
-                  var disqus_url = "#{page.full_url}#{page.url}";
74
-                %noscript
75
-                  %a(href="http://#{page.disqus_short_name}.disqus.com/?url=ref") View the discussion thread
76
-                %script(type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/embed.js")
77
-          - else
78
-            = preserve rp(content)
79
-        #sidebar
80
-          - if page.respond_to? :twitter_user
81
-            %h4 Twitter <a class="small" href="http://twitter.com/#{page.twitter_user}">@#{page.twitter_user}</a>
82
-            #twitter
83
-              %ul#twitter_status
84
-                Status updating...
85
-          - if page.respond_to? :delicious_user
86
-            %h4 My Delicious <a class="small" href="http://delicious.com/#{page.delicious_user}">more &rarr;</a>
87
-            #delicious
88
-              %script(type="text/javascript" src="http://feeds.delicious.com/v2/js/#{page.delicious_user}?title=&count=#{page.delicious_count}&sort=date&extended")
89
-    #footer
90
-      .page_width
91
-        Copyright &copy; #{Time.now.strftime('%Y')} - #{page.blog_title} -
92
-        %span.credit Powered by <a href="http://octopress.org">Octopress</a>
93
-    - if page.respond_to? :disqus_short_name
94
-      //Disqus Comments code
95
-      :javascript
96
-        (function() {
97
-            var links = document.getElementsByTagName('a');
98
-            var query = '?';
99
-            for(var i = 0; i < links.length; i++) {
100
-              if(links[i].href.indexOf('#disqus_thread') >= 0) {
101
-                query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
102
-              }
103
-            }
104
-            document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/get_num_replies.js' + query + '"></' + 'script>');
105
-          })();
106
-    - if page.respond_to? :google_analytics_tracking_id
107
-      //Google Analytics code
108
-      :javascript
109
-        try {
110
-        var pageTracker = _gat._getTracker("#{page.google_analytics_tracking_id}");
111
-        pageTracker._trackPageview();
112
-        } catch(err) {}
113 28
\ No newline at end of file
29
+        #main= preserve rp(content)
30
+        #sidebar= include "sidebar.haml"
31
+    = include "footer.haml"
114 32
\ No newline at end of file
... ...
@@ -1,17 +1,21 @@
1 1
 ---
2 2
 layout: default
3 3
 title: Blog
4
+author: 
5
+disqus: 
4 6
 ---
5 7
 .blog
6 8
   - site.posts.sort_by(&:date).reverse[0..9].each_with_index do |post,index|
7 9
     .article
8 10
       %h2= link_to(post.title, post.url, {:class=>"title"})
11
+      .meta
12
+        - author = (page.respond_to?(:author) && page.author) ? 'by: ' + page.author + ' |' : ''
13
+        #{author} posted: #{post.date.strftime("%B #{post.date.day.ordinalize}, %Y")} 
9 14
       = preserve rp(post.content)
10
-      - if page.respond_to? :disqus_short_name
11
-        .footer
12
-          - if post.data["comments_off"]
13
-            %em.comments_off Comments disabled
14
-          - else
15
-            %a(href="#{post.url}/#disqus_thread")Comments
15
+      - if page.respond_to?(:disqus) && page.disqus
16
+        - if post.data["comments_off"]
17
+          %em.comments_off Comments disabled
18
+        - else
19
+          %a(href="#{post.url}/#disqus_thread")Comments
16 20
   .footer
17 21
     %a(href="/archives.html" title="archives") &laquo; Blog Archives
18 22
\ No newline at end of file