now Octopress uses partials

This commit is contained in:
B Mathis 2010-03-10 12:23:30 -06:00
parent 1957c12499
commit eefe29e5d0
17 changed files with 176 additions and 114 deletions

View File

@ -1,11 +1,12 @@
require 'active_support'
site_url = "http://yoursite.com" # deployed site url for sitemap.xml generator
port = "4000" # preview project port eg. http://localhost:4000
site = "site" # compiled site directory
source = "source" # source file directory
stash = "_stash"
posts = "_posts"
site_url = "http://yoursite.com" # deployed site url for sitemap.xml generator
port = "4000" # preview project port eg. http://localhost:4000
site = "site" # compiled site directory
source = "source" # source file directory
stash = "_stash" # directory to stash posts for speedy generation
posts = "_posts" # directory for blog files
post_format = "markdown" # file format for new posts when using the post rake task
## -- Rsync Deploy config -- ##
ssh_user = "user@host.com" # for rsync deployment
@ -29,11 +30,15 @@ end
## if you're deploying with github, change the default deploy to deploy_github
desc "default deploy task"
task :deploy => :deploy_rsync do
task :deploy => [:deploy_rsync] do
end
desc "Generate and deploy task"
task :generate_deploy => [:integrate, :generate, :clean_debug, :deploy] do
end
desc "generate website in output directory"
task :default => [:generate_site, :generate_style] do
task :generate => [:generate_site, :generate_style] do
puts ">>> Site Generating Complete! <<<\n\n"
end
@ -41,8 +46,7 @@ end
desc "Begin a new post in #{source}/_posts"
task :post, :filename do |t, args|
args.with_defaults(:filename => 'new-post')
#system "touch #{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename}.markdown"
open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename.gsub(/[ _]/, '-')}.markdown", 'w') do |post|
open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename.downcase.gsub(/[ _]/, '-')}.#{post_format}", 'w') do |post|
post.puts "---"
post.puts "title: \"#{args.filename.gsub(/[-_]/, ' ').titlecase}\""
post.puts "---"
@ -126,13 +130,13 @@ task :watch do
end
desc "generate and deploy website via rsync"
multitask :deploy_rsync => [:integrate, :default, :clean_debug] do
multitask :deploy_rsync do
puts ">>> Deploying website to #{site_url} <<<"
ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
end
desc "generate and deploy website to github user pages"
multitask :deploy_github => [:integrate, :default, :clean_debug] do
multitask :deploy_github do
puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
require 'git'
repo = Git.open('.')
@ -173,13 +177,13 @@ task :stop_serve do
end
desc "preview the site in a web browser"
multitask :preview => [:default, :start_serve] do
multitask :preview => [:start_serve] do
system "open http://localhost:#{port}"
end
desc "Build an XML sitemap of all html files."
task :sitemap => :default do
task :sitemap do
html_files = FileList.new("#{site}/**/*.html").map{|f| f[("#{site}".size)..-1]}.map do |f|
if f.ends_with?("index.html")
f[0..(-("index.html".size + 1))]
@ -194,14 +198,14 @@ task :sitemap => :default do
priority = case f
when %r{^/$}
1.0
when %r{^/blog}
when %r{^/articles}
0.9
else
0.8
end
sitemap.puts %Q{ <url>}
sitemap.puts %Q{ <loc>#{site_url}#{f}</loc>}
sitemap.puts %Q{ <lastmod>#{Time.now.to_s('%Y-%m-%d')}</lastmod>}
sitemap.puts %Q{ <lastmod>#{Time.now.strftime('%Y-%m-%d')}</lastmod>}
sitemap.puts %Q{ <changefreq>weekly</changefreq>}
sitemap.puts %Q{ <priority>#{priority}</priority>}
sitemap.puts %Q{ </url>}

View File

@ -111,8 +111,6 @@ module Helpers
end
include TagHelper
# My added helpers
def to_html_email(address)
email = string_to_html(address)
"<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>"
@ -165,7 +163,7 @@ module Helpers
# A very hackish way to handle partials. We'll go with it till it breaks...
def include(partial_name)
file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length]
contents = IO.read("_includes/#{partial_name}")
contents = IO.read("source/_includes/#{partial_name}")
case file_ext
when 'haml'
Haml::Engine.new(contents).render(binding)
@ -180,6 +178,7 @@ module Helpers
end
include PartialsHelper
end
class String

View File

@ -0,0 +1,17 @@
---
blog_title: My Octopress Blog
twitter_user:
tweet_count: 3
show_replies: false
delicious_user:
delicious_count: 3
full_url:
disqus_short_name:
google_custom_search_id:
google_analytics_tracking_id:
---

View File

@ -0,0 +1,3 @@
%h4 My Delicious <a class="small" href="http://delicious.com/#{page.delicious_user}">more &rarr;</a>
#delicious
%script(type="text/javascript" src="http://feeds.delicious.com/v2/js/#{page.delicious_user}?title=&count=#{page.delicious_count}&sort=date&extended")

View File

@ -0,0 +1,11 @@
:javascript
(function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/get_num_replies.js' + query + '"></' + 'script>');
})();

View File

@ -0,0 +1,5 @@
:javascript
var disqus_url = "#{page.full_url}#{page.url}";
%noscript
%a(href="http://#{page.disqus_short_name}.disqus.com/?url=ref") View the discussion thread
%script(type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/embed.js")

View File

@ -0,0 +1,7 @@
#footer
.page_width
Copyright &copy; #{Time.now.strftime('%Y')} - #{page.blog_title} -
%span.credit Powered by <a href="http://octopress.org">Octopress</a>
= include "disqus_hook.haml" if page.respond_to?(:disqus_short_name) && page.disqus_short_name
= include "google_analytics.haml" if page.respond_to?(:google_analytics_tracking_id) && page.google_analytics_tracking_id

View File

@ -0,0 +1,10 @@
:javascript
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{page.google_analytics_tracking_id}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();

View File

@ -0,0 +1,21 @@
%head
%title #{page.blog_title} :: #{page.title}
- if page.respond_to? :description
%meta(name="description" content="#{page.description}")/
- if page.respond_to? :keywords
%meta(name="keywords" content="#{page.keywords}")/
%link(href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css")
%script(src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js" type="text/javascript")
%script(src="/javascripts/mootools-1.2.4.2-more.js" type="text/javascript")
- if page.respond_to? :twitter_user
:javascript
var twitter_user = "#{page.twitter_user}"
var show_replies = #{page.show_replies};
var tweet_count = #{page.tweet_count};
%script(src="/javascripts/octopress.js" type="text/javascript")
%script(src="/javascripts/twitter.js" type="text/javascript")
- if page.respond_to? :google_analytics
%script(src="http://www.google-analytics.com/ga.js" type="text/javascript")
- # RSS Feed
%link(href="/atom.xml" rel="alternate" title="#{page.blog_title}" type="application/atom+xml")

View File

@ -0,0 +1,8 @@
.page_width
%a.title(href="/")=page.blog_title
- if page.respond_to? :google_custom_search_id
#search
%form(action="http://www.google.com/cse" id="cse-search-box")
%input(type="hidden" name="cx" value="#{page.google_custom_search_id}")
%input(type="hidden" name="ie" value="UTF-8")
%input#q(type="text" name="q")

View File

@ -0,0 +1,8 @@
.page_width
%ul
%li.alpha
%a(href="/") Blog
%li.omega
%a(href="/about.html") About
%li.subscribe
%a(href="/atom.xml") Subscribe

View File

@ -0,0 +1,8 @@
.article
%h2= page.title
.meta
- author = (page.respond_to?(:author) && page.author) ? 'by: ' + page.author + ' |' : ''
#{author} posted: #{page.date.strftime("%B #{page.date.day.ordinalize}, %Y")}
= (page.respond_to?(:updated) && page.updated) ? " | upated: #{page.updated}" : ''
= preserve rp(content)
#disqus_thread= include "disqus_thread.haml" if page.respond_to?(:disqus_short_name) && page.disqus_short_name

View File

@ -0,0 +1,2 @@
= include "twitter.haml" if page.respond_to?(:twitter_user) && page.twitter_user
= include "delicious.haml" if page.respond_to?(:delicious_user) && page.delicious_user

View File

@ -0,0 +1,4 @@
%h4 Twitter <a class="small" href="http://twitter.com/#{page.twitter_user}">@#{page.twitter_user}</a>
#twitter
%ul#twitter_status
Status updating...

View File

@ -0,0 +1,32 @@
---
blog_title: My Octopress Blog
author:
twitter_user:
tweet_count: 3
show_replies: false
delicious_user:
delicious_count: 3
full_url:
disqus_short_name:
google_custom_search_id:
google_analytics_tracking_id:
---
!!! 1.1 Transitional
%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
= include "head.haml"
%body(id="#{(page.respond_to?(:body_id) ? page.body_id : nil)}")
#header= include "header.haml"
#nav= include "navigation.haml"
#page
.page_width
#main
.blog= include "post.haml"
#sidebar= include "sidebar.haml"
= include "footer.haml"

View File

@ -1,5 +1,6 @@
---
blog_title: My Octopress Blog
author:
twitter_user:
tweet_count: 3
@ -18,95 +19,13 @@ google_analytics_tracking_id:
!!! 1.1 Transitional
%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
%head
%title #{page.blog_title} :: #{page.title}
- if page.respond_to? :description
%meta(name="description" content="#{page.description}")/
- if page.respond_to? :keywords
%meta(name="keywords" content="#{page.keywords}")/
%link(href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css")
%link(href="/atom.xml" rel="alternate" title="#{page.blog_title}" type="application/atom+xml")
- if page.respond_to? :twitter_user
:javascript
var twitter_user = "#{page.twitter_user}"
var show_replies = #{page.show_replies};
var tweet_count = #{page.tweet_count};
%script(src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js" type="text/javascript")
%script(src="/javascripts/mootools-1.2.4.2-more.js" type="text/javascript")
%script(src="/javascripts/octopress.js" type="text/javascript")
%script(src="/javascripts/twitter.js" type="text/javascript")
- if page.respond_to? :google_analytics
%script(src="http://www.google-analytics.com/ga.js" type="text/javascript")
= include "head.haml"
%body(id="#{(page.respond_to?(:body_id) ? page.body_id : nil)}")
#header
.page_width
%a.title(href="/")=page.blog_title
- if page.respond_to? :google_custom_search_id
#search
%form(action="http://www.google.com/cse" id="cse-search-box")
%input(type="hidden" name="cx" value="#{page.google_custom_search_id}")
%input(type="hidden" name="ie" value="UTF-8")
%input#q(type="text" name="q")
#nav
.page_width
%ul
%li.alpha
%a(href="/") Blog
%li.omega
%a(href="/about.html") About
%li.subscribe
%a(href="/atom.xml") Subscribe
#header= include "header.haml"
#nav= include "navigation.haml"
#page
.page_width
#main
- if page.respond_to? :date
.blog
.article
%h2= page.title
= preserve rp(content)
%p.pubdate
Published:
=page.date.strftime("%d %b, %Y")
- if page.respond_to? :disqus_short_name
#disqus_thread
:javascript
var disqus_url = "#{page.full_url}#{page.url}";
%noscript
%a(href="http://#{page.disqus_short_name}.disqus.com/?url=ref") View the discussion thread
%script(type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/embed.js")
- else
= preserve rp(content)
#sidebar
- if page.respond_to? :twitter_user
%h4 Twitter <a class="small" href="http://twitter.com/#{page.twitter_user}">@#{page.twitter_user}</a>
#twitter
%ul#twitter_status
Status updating...
- if page.respond_to? :delicious_user
%h4 My Delicious <a class="small" href="http://delicious.com/#{page.delicious_user}">more &rarr;</a>
#delicious
%script(type="text/javascript" src="http://feeds.delicious.com/v2/js/#{page.delicious_user}?title=&count=#{page.delicious_count}&sort=date&extended")
#footer
.page_width
Copyright &copy; #{Time.now.strftime('%Y')} - #{page.blog_title} -
%span.credit Powered by <a href="http://octopress.org">Octopress</a>
- if page.respond_to? :disqus_short_name
//Disqus Comments code
:javascript
(function() {
var links = document.getElementsByTagName('a');
var query = '?';
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf('#disqus_thread') >= 0) {
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
}
}
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/#{page.disqus_short_name}/get_num_replies.js' + query + '"></' + 'script>');
})();
- if page.respond_to? :google_analytics_tracking_id
//Google Analytics code
:javascript
try {
var pageTracker = _gat._getTracker("#{page.google_analytics_tracking_id}");
pageTracker._trackPageview();
} catch(err) {}
#main= preserve rp(content)
#sidebar= include "sidebar.haml"
= include "footer.haml"

View File

@ -1,17 +1,21 @@
---
layout: default
title: Blog
author:
disqus:
---
.blog
- site.posts.sort_by(&:date).reverse[0..9].each_with_index do |post,index|
.article
%h2= link_to(post.title, post.url, {:class=>"title"})
.meta
- author = (page.respond_to?(:author) && page.author) ? 'by: ' + page.author + ' |' : ''
#{author} posted: #{post.date.strftime("%B #{post.date.day.ordinalize}, %Y")}
= preserve rp(post.content)
- if page.respond_to? :disqus_short_name
.footer
- if post.data["comments_off"]
%em.comments_off Comments disabled
- else
%a(href="#{post.url}/#disqus_thread")Comments
- if page.respond_to?(:disqus) && page.disqus
- if post.data["comments_off"]
%em.comments_off Comments disabled
- else
%a(href="#{post.url}/#disqus_thread")Comments
.footer
%a(href="/archives.html" title="archives") &laquo; Blog Archives