Skip to content
This repository was archived by the owner on Apr 24, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package main

import (
"io/ioutil"
"launchpad.net/goyaml"

"gopkg.in/yaml.v1"
)

// Config represents the key-value pairs in a _config.yml file.
Expand Down Expand Up @@ -42,8 +43,8 @@ func ParseConfig(path string) (Config, error) {
}

func parseConfig(data []byte) (Config, error) {
conf := map[string] interface{} { }
err := goyaml.Unmarshal(data, &conf)
conf := map[string]interface{}{}
err := yaml.Unmarshal(data, &conf)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,7 +72,7 @@ func ParseDeployConfig(path string) (*DeployConfig, error) {

func parseDeployConfig(data []byte) (*DeployConfig, error) {
conf := DeployConfig{}
err := goyaml.Unmarshal(data, &conf)
err := yaml.Unmarshal(data, &conf)
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/bazil/jkl

go 1.13

require (
github.com/crowdmob/goamz v0.0.0-20150128194925-3a06871fe9fc
github.com/howeyc/fsnotify v0.9.0
github.com/kr/pretty v0.1.0 // indirect
github.com/russross/blackfriday v1.5.2
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/crowdmob/goamz v0.0.0-20150128194925-3a06871fe9fc h1:Gn/roShKxUNtNYEEH+ZeGxMJ+RsCBZdIdb8pKOesTaA=
github.com/crowdmob/goamz v0.0.0-20150128194925-3a06871fe9fc/go.mod h1:4zrXGiIhmCfgVUO6nJpSa9QVXylPKBYkLa179m59HzE=
github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY=
github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
7 changes: 4 additions & 3 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"bytes"
"github.com/russross/blackfriday"
"io"
"io/ioutil"
"launchpad.net/goyaml"
"path/filepath"
"strings"

"github.com/russross/blackfriday"
"gopkg.in/yaml.v1"
)

// A Page represents the key-value pairs in a page or posts front-end YAML as
Expand Down Expand Up @@ -72,7 +73,7 @@ func parsePage(fn string, c []byte) (Page, error) {
// Helper function to parse the front-end yaml matter.
func parseMatter(content []byte) (Page, error) {
page := map[string]interface{}{}
err := goyaml.Unmarshal(content, &page)
err := yaml.Unmarshal(content, &page)
return page, err
}

Expand Down
4 changes: 2 additions & 2 deletions post.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ParsePost(fn string) (Page, error) {
}

// parse the Date and Title from the post's file name
_,f := filepath.Split(fn)
_, f := filepath.Split(fn)
t, d, err := parsePostName(f)
if err != nil {
return nil, err
Expand All @@ -40,7 +40,7 @@ func ParsePost(fn string) (Page, error) {
year := fmt.Sprintf("%02d", d.Year())
name := replaceExt(f, ".html")
post["id"] = filepath.Join(year, mon, day, f) // TODO try to remember why I need this field
post["url"]= filepath.Join(year, mon, day, name[11:])
post["url"] = filepath.Join(year, mon, day, name[11:])

return post, nil
}
Expand Down
9 changes: 5 additions & 4 deletions site.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"fmt"
"io/ioutil"
"launchpad.net/goamz/aws"
"launchpad.net/goamz/s3"
"mime"
"os"
"path/filepath"
"text/template"
"time"

"github.com/crowdmob/goamz/aws"
"github.com/crowdmob/goamz/s3"
)

var (
Expand Down Expand Up @@ -120,9 +121,9 @@ func (s *Site) Deploy(user, pass, url string) error {

// try to upload the file ... sometimes this fails due to amazon
// issues. If so, we'll re-try
if err := b.Put(rel, content, typ, s3.PublicRead); err != nil {
if err := b.Put(rel, content, typ, s3.PublicRead, s3.Options{}); err != nil {
time.Sleep(100 * time.Millisecond) // sleep so that we don't immediately retry
return b.Put(rel, content, typ, s3.PublicRead)
return b.Put(rel, content, typ, s3.PublicRead, s3.Options{})
}

// file upload was a success, return nil
Expand Down
52 changes: 28 additions & 24 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import (
)

// Additional functions available in Jekyll templates
var funcMap = map[string]interface{} {

"capitalize" : capitalize,
"date_to_string" : dateToString,
"date_to_xmlschema" : dateToXmlSchema,
"downcase" : lower,
"eq" : eq,
"newline_to_br" : newlineToBreak,
"replace" : replace,
"replace_first" : replaceFirst,
"remove" : remove,
"remove_first" : removeFirst,
"split" : split,
"strip_newlines" : stripNewlines,
"truncate" : truncate,
"truncatewords" : truncateWords,
"upcase" : upper,
var funcMap = map[string]interface{}{

"capitalize": capitalize,
"date_to_string": dateToString,
"date_to_xmlschema": dateToXmlSchema,
"downcase": lower,
"eq": eq,
"newline_to_br": newlineToBreak,
"replace": replace,
"replace_first": replaceFirst,
"remove": remove,
"remove_first": removeFirst,
"split": split,
"strip_newlines": stripNewlines,
"truncate": truncate,
"truncatewords": truncateWords,
"upcase": upper,
}

// Capitalize words in the input sentence
Expand All @@ -31,17 +31,17 @@ func capitalize(s string) string {
}

// Checks if two values are equal
func eq(v1 interface{}, v2 interface{}) bool {
func eq(v1 interface{}, v2 interface{}) bool {
return v1 == v2
}

// Converts a date to a string
func dateToString(date time.Time) string {
func dateToString(date time.Time) string {
return date.Format("2006-01-02")
}

// Converts a date to a string
func dateToXmlSchema(date time.Time) string {
func dateToXmlSchema(date time.Time) string {
return date.Format(time.RFC3339)
}

Expand Down Expand Up @@ -86,15 +86,19 @@ func stripNewlines(s string) string {
}

// Truncate a string down to x characters
func truncate(s string, x int) (string) {
if len(s) > x { return s[0:x] }
func truncate(s string, x int) string {
if len(s) > x {
return s[0:x]
}
return s
}

// Truncate a string down to x words
func truncateWords(s string, x int) (string) {
func truncateWords(s string, x int) string {
words := strings.Split(s, " ")
if len(words) <= x { return s }
if len(words) <= x {
return s
}
return strings.Join(words[0:x], " ")
}

Expand Down
1 change: 1 addition & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func isHiddenOrTemp(fn string) bool {
base := filepath.Base(fn)
return strings.HasPrefix(base, ".") ||
strings.HasPrefix(fn, ".") ||
strings.HasPrefix(base, "#") ||
strings.HasSuffix(base, "~") ||
fn == "README.md"
}
Expand Down
62 changes: 31 additions & 31 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

func TestAppendExt(t *testing.T) {
if ext := appendExt("/test.html", ".html"); ext != "/test.html" {
t.Errorf("Expected appended extension [/test.html] got [%s]", ext)
t.Errorf("Expected appended extension [/test.html] got [%s]", ext)
}
if ext := appendExt("/test", ".html"); ext != "/test.html" {
t.Errorf("Expected appended extension [/test.html] got [%s]", ext)
t.Errorf("Expected appended extension [/test.html] got [%s]", ext)
}
}

Expand All @@ -18,11 +18,11 @@ func TestHasMatter(t *testing.T) {
}

func TestIsHiddenOrTemp(t *testing.T) {
tests := map[string]bool {
".tmp" : true,
"tmp~" : true,
"tmp" : false,
".git" : true }
tests := map[string]bool{
".tmp": true,
"tmp~": true,
"tmp": false,
".git": true}

for key, val := range tests {
if result := isHiddenOrTemp(key); result != val {
Expand All @@ -32,12 +32,12 @@ func TestIsHiddenOrTemp(t *testing.T) {
}

func TestIsTemplate(t *testing.T) {
tests := map[string]bool {
"_layouts/page.html" : true,
"_includes/page.html" : true,
"_includes/page.html~" : false,
"static/js/script.js" : false,
"index.html" : false }
tests := map[string]bool{
"_layouts/page.html": true,
"_includes/page.html": true,
"_includes/page.html~": false,
"static/js/script.js": false,
"index.html": false}

for key, val := range tests {
if result := isTemplate(key); result != val {
Expand All @@ -47,12 +47,12 @@ func TestIsTemplate(t *testing.T) {
}

func TestIsHtml(t *testing.T) {
tests := map[string]bool {
"page.html" : true,
"page.xml" : true,
"page.html~" : false,
"page.rss" : true,
"page.atom" : true }
tests := map[string]bool{
"page.html": true,
"page.xml": true,
"page.html~": false,
"page.rss": true,
"page.atom": true}

for key, val := range tests {
if result := isHtml(key); result != val {
Expand All @@ -62,10 +62,10 @@ func TestIsHtml(t *testing.T) {
}

func TestIsMarkdown(t *testing.T) {
tests := map[string]bool {
"page.md" : true,
"page.markdown" : true,
"page.md~" : false }
tests := map[string]bool{
"page.md": true,
"page.markdown": true,
"page.md~": false}

for key, val := range tests {
if result := isMarkdown(key); result != val {
Expand All @@ -83,10 +83,10 @@ func TestIsPost(t *testing.T) {
}

func TestIsStatic(t *testing.T) {
tests := map[string]bool {
"_site" : false,
"_site/index.html" : false,
"img/logo.png" : true }
tests := map[string]bool{
"_site": false,
"_site/index.html": false,
"img/logo.png": true}

for key, val := range tests {
if result := isStatic(key); result != val {
Expand All @@ -97,18 +97,18 @@ func TestIsStatic(t *testing.T) {

func TestRemoveExt(t *testing.T) {
if ext := removeExt("/test"); ext != "/test" {
t.Errorf("Expected removed extension [/test] got [%s]", ext)
t.Errorf("Expected removed extension [/test] got [%s]", ext)
}
if ext := removeExt("/test.html"); ext != "/test" {
t.Errorf("Expected removed extension [/test] got [%s]", ext)
t.Errorf("Expected removed extension [/test] got [%s]", ext)
}
}

func TestReplaceExt(t *testing.T) {
if ext := replaceExt("/test", ".html"); ext != "/test.html" {
t.Errorf("Expected replaced extension [/test.html] got [%s]", ext)
t.Errorf("Expected replaced extension [/test.html] got [%s]", ext)
}
if ext := replaceExt("/test.markdown", ".html"); ext != "/test.html" {
t.Errorf("Expected replaced extension [/test.html] got [%s]", ext)
t.Errorf("Expected replaced extension [/test.html] got [%s]", ext)
}
}