GithubHelp home page GithubHelp logo

octopress / date-format Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 13.0 294 KB

Automatically adds variables with nicely formated dates and time tags to Jekyll posts and pages.

License: MIT License

Ruby 44.62% HTML 55.38%

date-format's Introduction

Octopress Date Format

Put nicely formatted dates on any post or page.

Build Status Gem Version License

Installation

Add this line to your application's Gemfile:

gem 'octopress-date-format'

And then execute:

$ bundle

Or install it yourself as:

$ gem install octopress-date-format

Next add it to your gems list in Jekyll's _config.yml

gems:
  - octopress-date-format

Usage

Any post (or page with a date) will automatically have some new date attributes.

  • date - The date, 2014-07-03 14:08:00 +0000
  • date_text - The formatted date, Jul 3rd, 2014
  • time_text - The formatted time, 2:08 pm
  • date_xml - The XML schema formatted date, 2014-07-03T14:08:00+00:00
  • date_html - The formatted date in a <time> tag.
  • date_time_html - The formatted date and time in a <time> tag.

Here's an example of what would be rendered with {{ post.date_time_html }}.

<time class='entry-date' datetime='2014-07-03T14:08:00+00:00'>
  <span class='date'>
    <span class='date-month'>Jul</span>
    <span class='date-day'>3</span><span class='date-suffix'>rd</span>,
    <span class='date-year'>2014</span>
  </span>
  <span class='time'>2:08 pm</span>
</time>

If you update a post or page and want to display this in a template, add this to YAML front-matter, date_updated: 2014-07-03 15:03:15 and your post will have updated date attributes as well.

  • updated - The date, 2014-07-03 15:03:15 +0000
  • date_updated_text - The formatted date, Jul 3rd, 2014
  • time_updated_text - The formatted time, 3:03 pm
  • date_updated_xml - The XML schema formatted date, 2014-07-03T15:03:15+00:00
  • date_updated_html - The formatted date in a <time> tag.
  • date_time_updated_html - The formatted date and time in a <time> tag.

Of course you can use Liquid conditionals when outputting an updated date.

{% if post.updated %}Updated: {{ post.date_time_updated_html }}{% endif %}

Configuration

You may change the formatting of the dates and times in Jekyll's configuration file. Here are the defaults:

date_format: 'ordinal'     # July 3rd, 2014
time_format: '%-I:%M %P'   # 2:08 pm

To choose a different format, use a Ruby strftime compatible string. For example:

date_format: "%Y-%m-%d"  # e.g. 2014-07-03
time_format: "%H:%M"     # 24 hour time

Contributing

  1. Fork it ( https://github.com/octopress/date-format/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Copyright (c) 2013 Brandon Mathis

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

date-format's People

Contributors

imathis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

date-format's Issues

No longer allows specifying timezone?

I'm trying out Octopress 3.0, and it seems like the timezone config is no longer respected. All my generated times are now e.g.

<time datetime="2015-03-15T20:00:00-04:00" itemprop="datePublished">Mar 15, 2015</time>

instead of their previous

<time datetime="2015-03-16T00:00:00Z" itemprop="datePublished">Mar 16, 2015</time>

Is there any way to fix this, short of setting my computer to UTC before running Octopress/Jekyll? I have tried adding timezone: UTC to my _config.yaml with no success.

Exception when running octopress ink list with date-format installed

I get this exception

$ bundle exec octopress ink list -t
/Library/Ruby/Gems/2.0.0/gems/octopress-date-format-3.0.2/lib/octopress-date-format.rb:78:in `format_date': undefined method `[]' for nil:NilClass (NoMethodError)

Looks like it can't find the date_format key in the config, which is weird because it is in my _confg.yml

date_format: "ordinal"

Ideas?

Example for date_time_html is a bit misleading

The example for date_time_html suggests that whatever format I specify in date_format, this octopress plugin will parse that format and create a html with a correctly classed span for each element.

That isn't the case however. As soon as I define in _octopress.yml

date_format: "%d-%b-%Y"

the generated code looks like this

<time class='entry-date' datetime='2014-08-13T00:17:32+02:00'>
  <span class='date'>13-Aug-2014</span> 
  <span class='time'>12:17 am</span>
</time>

I actually prefer it that way, but others might be surprised by this.

Can't Get Plugin to Function

Jekyll 2.5.3, Octopress 3.0.9, date-format 3.0.3

I've added the gem to my jekyll_plugins group in my Gemfile, and other plugins I've added there work fine. I can see the gem is installed, but upon building the site, neither the {{ post.date }} I've added to the post layout or the example conditional to show the post updated time display. I did add the date_updated setting in the YAML front matter of the post, but nothing ever renders after I build the site. What might I be doing wrong?

date_updated won't work

while the date parameter seems to be working fine again, I can't get my website to display the "updated" date. I have tried both specifying updated and date_updated.

This happens both with whitespace and with the classic theme.

Sorry for reporting issues all over the place, but this is the best guess I could come up with given the current documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.