Skip to content

Commit

Permalink
support various formats for published date, fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Aug 5, 2013
1 parent efe348d commit 1fbdbbc
Show file tree
Hide file tree
Showing 25 changed files with 163 additions and 42 deletions.
4 changes: 2 additions & 2 deletions examples/amber/public/002-meta-billet
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/003-dependances
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/004-npm-packages
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/005-structurer-express
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/006-dependency-injection
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/007-implement-js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/008-backbone-computed-properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/009-je-men-vais
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/010-demenagement
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
4 changes: 2 additions & 2 deletions examples/amber/public/j-42-preparation
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<div class="header">
<div class="title">
<a href="/">Site Name</a>
<a href="/">Ø value</a>
<br />
<span class="tagline"></span>
<span class="tagline">a wysiwyg hypertext cyberblog</span>
</div>
</div>
<nav>
Expand Down
2 changes: 1 addition & 1 deletion examples/amber/public/rss
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><title>Site Name</title><description></description><link>http://localhost</link><lastBuildDate>22 Jul 13 12:35 EDT</lastBuildDate><generator>trofaf (https://github.com/PuerkitoBio/trofaf)</generator><item><title>Ce blogue a déménagé sur GitHub</title><link>http://localhost/010-demenagement</link><description>Suite à l&#39;annonce de la fermeture de Calepin.co, j&#39;ai déménagé ce blogue sur http://hypermegatop.github.com. Veuillez mettre à jour vos favoris!</description><author>Martin Angers</author><category></category><pubDate>30 Apr 12 00:00 UTC</pubDate></item><item><title>Je suis venu te dire que je m&#39;en vais</title><link>http://localhost/009-je-men-vais</link><description>Ou plutôt, &#34;je suis venu te dire qu&#39;on m&#39;évince&#34;, mais ça &#34;punch&#34; moins... En effet, mon coup de foudre pour le blogiciel Calepin aura finalement été son baiser de la mort. Sur Twitter la semaine dernière, via le canal officiel du site, on apprenait que c&#39;était la fin des haricots.</description><author>Martin Angers</author><category></category><pubDate>23 Apr 12 00:00 UTC</pubDate></item><item><title>Propriétés calculées avec Backbone</title><link>http://localhost/008-backbone-computed-properties</link><description>La beauté de l&#39;univers du code libre est que lorsqu&#39;il manque une fonctionnalité, on peut se retrousser les manches, ouvrir le code et l&#39;ajouter. Voici ma petite histoire des propriétés calculées avec Backbone.</description><author>Martin Angers</author><category></category><pubDate>13 Apr 12 00:00 UTC</pubDate></item><item><title>implement.js: typage fort et Javascript</title><link>http://localhost/007-implement-js</link><description>L&#39;injection de dépendance avec Javascript a comme conséquence de ne pouvoir assumer que les fonctionnalités offertes par l&#39;instance reçue seront celles attendues.</description><author>Martin Angers</author><category></category><pubDate>02 Apr 12 00:00 UTC</pubDate></item><item><title>Expérimentations sur l&#39;injection de dépendance avec node.js</title><link>http://localhost/006-dependency-injection</link><description>L&#39;injection de dépendance permet de découpler les différentes composantes d&#39;une application pour en faciliter l&#39;entretien, la testabilité, circonscrire l&#39;impact des changements, mais aussi pour imposer une façon d&#39;aborder la création de l&#39;application en une aggrégation de pièces simples, à la responsabilité ciblée, et à l&#39;API bien défini.</description><author>Martin Angers</author><category></category><pubDate>27 Mar 12 00:00 UTC</pubDate></item></channel></rss>
<rss version="2.0"><channel><title>Ø value</title><description>a wysiwyg hypertext cyberblog</description><link>http://localhost</link><lastBuildDate>05 Aug 13 18:08 EDT</lastBuildDate><generator>trofaf (https://github.com/PuerkitoBio/trofaf)</generator><item><title>Ce blogue a déménagé sur GitHub</title><link>http://localhost/010-demenagement</link><description>Suite à l&#39;annonce de la fermeture de Calepin.co, j&#39;ai déménagé ce blogue sur http://hypermegatop.github.com. Veuillez mettre à jour vos favoris!</description><author>Martin Angers</author><category></category><pubDate>30 Apr 12 00:00 UTC</pubDate></item><item><title>Je suis venu te dire que je m&#39;en vais</title><link>http://localhost/009-je-men-vais</link><description>Ou plutôt, &#34;je suis venu te dire qu&#39;on m&#39;évince&#34;, mais ça &#34;punch&#34; moins... En effet, mon coup de foudre pour le blogiciel Calepin aura finalement été son baiser de la mort. Sur Twitter la semaine dernière, via le canal officiel du site, on apprenait que c&#39;était la fin des haricots.</description><author>Martin Angers</author><category></category><pubDate>23 Apr 12 00:00 UTC</pubDate></item><item><title>Propriétés calculées avec Backbone</title><link>http://localhost/008-backbone-computed-properties</link><description>La beauté de l&#39;univers du code libre est que lorsqu&#39;il manque une fonctionnalité, on peut se retrousser les manches, ouvrir le code et l&#39;ajouter. Voici ma petite histoire des propriétés calculées avec Backbone.</description><author>Martin Angers</author><category></category><pubDate>13 Apr 12 00:00 UTC</pubDate></item><item><title>implement.js: typage fort et Javascript</title><link>http://localhost/007-implement-js</link><description>L&#39;injection de dépendance avec Javascript a comme conséquence de ne pouvoir assumer que les fonctionnalités offertes par l&#39;instance reçue seront celles attendues.</description><author>Martin Angers</author><category></category><pubDate>02 Apr 12 00:00 UTC</pubDate></item><item><title>Expérimentations sur l&#39;injection de dépendance avec node.js</title><link>http://localhost/006-dependency-injection</link><description>L&#39;injection de dépendance permet de découpler les différentes composantes d&#39;une application pour en faciliter l&#39;entretien, la testabilité, circonscrire l&#39;impact des changements, mais aussi pour imposer une façon d&#39;aborder la création de l&#39;application en une aggrégation de pièces simples, à la responsabilité ciblée, et à l&#39;API bien défini.</description><author>Martin Angers</author><category></category><pubDate>27 Mar 12 00:00 UTC</pubDate></item></channel></rss>
8 changes: 4 additions & 4 deletions examples/native/posts/test.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
Title: This is a test
Title: This is a test 1
Author: Me
Description: Whatever
Date: 2013-07-17
Date: 2013-08-06 17h
---

# This is a test header
# This is a test header 1

And this is a test content.
And this is a test content 1.
10 changes: 10 additions & 0 deletions examples/native/posts/test2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
Title: This is a test 2
Author: Me
Description: Whatever
Date: 2013-07-17
---

# This is a test header 2

And this is a test content 2.
10 changes: 10 additions & 0 deletions examples/native/posts/test3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
Title: This is a test 3
Author: Me
Description: Whatever
Date: 2013-08-06 17:48
---

# This is a test header 3

And this is a test content 3.
10 changes: 10 additions & 0 deletions examples/native/posts/test4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
Title: This is a test 4
Author: Me
Description: Whatever
Date: 2013-08-06T17:48:01-05:00
---

# This is a test header 4

And this is a test content 4.
14 changes: 9 additions & 5 deletions examples/native/public/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@

<html>
<head>
<title>This is a test</title>
<title>This is a test 4</title>
</head>
<body>

<article>
<h1>This is a test</h1>
<time>2013-07-17</time>
<div><h1>This is a test header</h1>
<h1>This is a test 4</h1>
<time>2013-08-06</time>
<div><h1>This is a test header 4</h1>

<p>And this is a test content.</p>
<p>And this is a test content 4.</p>
</div>

<a href="test3">Next</a>


</article>

</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/native/public/rss
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><title>Site Name</title><description></description><link>http://localhost</link><lastBuildDate>22 Jul 13 12:40 EDT</lastBuildDate><generator>trofaf (https://github.com/PuerkitoBio/trofaf)</generator><item><title>This is a test</title><link>http://localhost/test</link><description>Whatever</description><author>Me</author><category></category><pubDate>17 Jul 13 00:00 UTC</pubDate></item></channel></rss>
<rss version="2.0"><channel><title>Ø value</title><description>a wysiwyg hypertext cyberblog</description><link>http://localhost</link><lastBuildDate>05 Aug 13 18:08 EDT</lastBuildDate><generator>trofaf (https://github.com/PuerkitoBio/trofaf)</generator><item><title>This is a test 4</title><link>http://localhost/test4</link><description>Whatever</description><author>Me</author><category></category><pubDate>06 Aug 13 17:48 -0500</pubDate></item><item><title>This is a test 3</title><link>http://localhost/test3</link><description>Whatever</description><author>Me</author><category></category><pubDate>06 Aug 13 17:48 UTC</pubDate></item><item><title>This is a test 1</title><link>http://localhost/test</link><description>Whatever</description><author>Me</author><category></category><pubDate>06 Aug 13 17:00 UTC</pubDate></item><item><title>This is a test 2</title><link>http://localhost/test2</link><description>Whatever</description><author>Me</author><category></category><pubDate>17 Jul 13 00:00 UTC</pubDate></item></channel></rss>
16 changes: 11 additions & 5 deletions examples/native/public/test
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@

<html>
<head>
<title>This is a test</title>
<title>This is a test 1</title>
</head>
<body>

<article>
<h1>This is a test</h1>
<time>2013-07-17</time>
<div><h1>This is a test header</h1>
<h1>This is a test 1</h1>
<time>2013-08-06</time>
<div><h1>This is a test header 1</h1>

<p>And this is a test content.</p>
<p>And this is a test content 1.</p>
</div>

<a href="test2">Next</a>


<a href="test3">Prev</a>

</article>

</body>
Expand Down
22 changes: 22 additions & 0 deletions examples/native/public/test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<html>
<head>
<title>This is a test 2</title>
</head>
<body>

<article>
<h1>This is a test 2</h1>
<time>2013-07-17</time>
<div><h1>This is a test header 2</h1>

<p>And this is a test content 2.</p>
</div>


<a href="test">Prev</a>

</article>

</body>
</html>
24 changes: 24 additions & 0 deletions examples/native/public/test3
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<html>
<head>
<title>This is a test 3</title>
</head>
<body>

<article>
<h1>This is a test 3</h1>
<time>2013-08-06</time>
<div><h1>This is a test header 3</h1>

<p>And this is a test content 3.</p>
</div>

<a href="test">Next</a>


<a href="test4">Prev</a>

</article>

</body>
</html>
22 changes: 22 additions & 0 deletions examples/native/public/test4
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<html>
<head>
<title>This is a test 4</title>
</head>
<body>

<article>
<h1>This is a test 4</h1>
<time>2013-08-06</time>
<div><h1>This is a test header 4</h1>

<p>And this is a test content 4.</p>
</div>

<a href="test3">Next</a>


</article>

</body>
</html>
6 changes: 6 additions & 0 deletions examples/native/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
<h1>{{ .Post.ShortPost.Title }}</h1>
<time>{{ fmttime .Post.ShortPost.PubTime "2006-01-02" }}</time>
<div>{{ .Post.Content }}</div>
{{ if .Next }}
<a href="{{ .Next.Slug }}">Next</a>
{{ end }}
{{ if .Prev }}
<a href="{{ .Prev.Slug }}">Prev</a>
{{ end }}
</article>
{{ end }}
3 changes: 1 addition & 2 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var (
postTplNm = "post.amber" // The amber post template file name (native Go are compiled using ParseGlob)

// Special files in the public directory, that must not be deleted
// If value is true, this must match the prefix of the file (HasPrefix())
specFiles = map[string]struct{}{
"favicon.ico": struct{}{},
"robots.txt": struct{}{},
Expand Down Expand Up @@ -91,7 +90,7 @@ func compileTemplates() error {

// Clear the public directory, ignoring special files, subdirectories, and hidden (dot) files.
func clearPublicDir() error {
// Clear the public directory, except subdirs and special files (favicon.ico)
// Clear the public directory, except subdirs and special files (favicon.ico & co.)
fis, err := ioutil.ReadDir(PublicDir)
if err != nil {
return fmt.Errorf("error getting public directory files: %s", err)
Expand Down
12 changes: 10 additions & 2 deletions tpldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ var (
ErrEmptyPost = fmt.Errorf("empty post file")
ErrInvalidFrontMatter = fmt.Errorf("invalid front matter")
ErrMissingFrontMatter = fmt.Errorf("missing front matter")

// Lookup table to find the format based on the length of the date in the front matter
pubDtFmt = map[int]string{
10: "2006-01-02",
14: "2006-01-02 15h",
16: "2006-01-02 15:04",
25: time.RFC3339,
}
)

// The TemplateData structure contains all the relevant information passed to the
Expand Down Expand Up @@ -123,8 +131,8 @@ func newLongPost(fi os.FileInfo) (*LongPost, error) {

slug := getSlug(fi.Name())
pubdt := fi.ModTime()
if dt, ok := m["Date"]; ok {
pubdt, err = time.Parse("2006-01-02", dt)
if dt, ok := m["Date"]; ok && len(dt) > 0 {
pubdt, err = time.Parse(pubDtFmt[len(dt)], dt)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1fbdbbc

Please sign in to comment.