Skip to content

Commit

Permalink
Using garyburd's newest oauth, updated to publish archive file.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoneill committed Apr 9, 2012
1 parent 58d2533 commit 232a244
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions publisher.go
Expand Up @@ -5,6 +5,7 @@ import (
"time"
"io/ioutil"
"net/http"
"html"
"encoding/json"
"encoding/xml"
"strings"
Expand All @@ -13,7 +14,7 @@ import (
"os"
"os/exec"
"regexp"
"github.com/garyburd/go-oauth"
"github.com/garyburd/go-oauth/oauth"
"github.com/nickoneill/go-dropbox"
"launchpad.net/goyaml"
"github.com/drhodes/mustache.go"
Expand Down Expand Up @@ -60,6 +61,7 @@ type Post struct {
Date string
RFC3339Date string
Content string
Excerpt string
Filename string
Atomid string
}
Expand Down Expand Up @@ -269,6 +271,7 @@ func rebuildSite() {
posttemplate, _ := db.GetFile("templates/post.mustache")
hometemplate, _ := db.GetFile("templates/home.mustache")
feedtemplate, _ := db.GetFile("templates/feed.mustache")
archivetemplate, _ := db.GetFile("templates/archive.mustache")

tmppath, err := ioutil.TempDir("","gopub")
if err != nil {
Expand All @@ -293,6 +296,7 @@ func rebuildSite() {

goyaml.Unmarshal([]byte(parts[1]), &p)
p.Content = string(blackfriday.MarkdownCommon([]byte(parts[2])))
p.Excerpt = html.EscapeString(p.Content[0:200])
p.Filename = slugify(p.Title)+".html"
// TODO: check for partial yaml and fill it

Expand Down Expand Up @@ -327,10 +331,10 @@ func rebuildSite() {

// build the home file
homeposts := []Post{}
if len(pc.Posts) < 10 {
if len(pc.Posts) < 12 {
homeposts = pc.Posts[:]
} else {
homeposts = pc.Posts[:10]
homeposts = pc.Posts[:12]
}

home := mustache.Render(hometemplate, map[string]interface{}{"posts": homeposts})
Expand All @@ -340,14 +344,21 @@ func rebuildSite() {

// build the feed file
feedposts := []Post{}
if len(pc.Posts) < 10 {
if len(pc.Posts) < 12 {
feedposts = pc.Posts[:]
} else {
feedposts = pc.Posts[:10]
feedposts = pc.Posts[:12]
}

feed := mustache.Render(feedtemplate, map[string]interface{}{"posts": feedposts, "updated": time.Now().Format(time.RFC3339)})
ioutil.WriteFile(tmppath+"/atom.xml", []byte(feed), 0644)

// build the archive file
archiveposts := []Post{}
archiveposts = pc.Posts[:]

archive := mustache.Render(archivetemplate, map[string]interface{}{"posts": archiveposts})
ioutil.WriteFile(tmppath+"/archive.html", []byte(archive), 0644)

fmt.Printf("Done site generation at %v\n",tmppath)

Expand Down

0 comments on commit 232a244

Please sign in to comment.