Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added date to the articles #19

Merged
merged 1 commit into from

2 participants

Chris O'Sullivan Steve Klabnik
Chris O'Sullivan

Hi Steve,

I've added a very basic date to the articles. This uses the 'date' metadata, which not all of the articles have (in which case it will just be blank).

The format I've chosen for dates is "%-d %B %Y" - you can change this if you want in the formatted_date helper in blog.rb.

Also, it's 'barely' styled. You can set the style for the date in layout.css

-Chris

Chris O'Sullivan thechrisoshow Added a date to articles. This uses the 'date' metadata, which not al…
…l of the articles have (although the latest ones seem to)
2276fb7
Steve Klabnik steveklabnik merged commit 62b80ea into from
Steve Klabnik

You are awesome. I love merging pull requests from my phone when I'm on the bus. Thank you! :heart:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. Chris O'Sullivan

    Added a date to articles. This uses the 'date' metadata, which not al…

    thechrisoshow authored
    …l of the articles have (although the latest ones seem to)
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +6 −1 blog.rb
  2. +3 −0  public/stylesheets/layout.css
  3. +1 −0  views/post.haml
7 blog.rb
View
@@ -17,6 +17,10 @@ def title
"#{title}Literate Programming"
end
+ def formatted_date
+ @date && Date.parse(@date).strftime("%-d %B %Y")
+ end
+
def format_outline(outline)
prev_level = 2
@@ -77,10 +81,11 @@ def format_outline(outline)
@title_hidden = source.metadata['title-hidden']
@content = source.content
@outline = source.outline
+ @date = source.metadata['date']
haml :post
rescue Errno::ENOENT # we couldn't find the file on disk.
- pass
+ pass
end
end
3  public/stylesheets/layout.css
View
@@ -22,6 +22,9 @@ div.container {
pre.prettyprint {
margin-bottom: 2em;
}
+div.date {
+ text-align: right;
+}
/* #Page Styles
1  views/post.haml
View
@@ -1,5 +1,6 @@
- unless @title_hidden
%h1= @title
+ .date= formatted_date
:preserve
#{@content}
- content_for :sidebar do
Something went wrong with that request. Please try again.