This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from agonzalezro/bump
Refactor + start using Glide
- Loading branch information
Showing
205 changed files
with
2,101 additions
and
26,857 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,5 @@ _testmain.go | |
|
||
.DS_Store | ||
|
||
# getgb.io | ||
bin/ | ||
pkg/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM golang:1.6.2-alpine | ||
|
||
ENV APP $GOPATH/src/github.com/agonzalezro/polo | ||
RUN mkdir -p $APP | ||
WORKDIR $APP | ||
|
||
ADD glide.yaml $APP/glide.yaml | ||
ADD glide.lock $APP/glide.lock | ||
RUN apk add --no-cache git \ | ||
&& go get -u github.com/Masterminds/glide/... \ | ||
&& go get -u github.com/jteeuwen/go-bindata/... \ | ||
&& glide install \ | ||
&& apk del git | ||
|
||
ADD . $APP | ||
RUN apk add --no-cache make \ | ||
&& make \ | ||
&& apk del make | ||
|
||
ENTRYPOINT ["bin/polo"] | ||
CMD ["--help"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
all: polo | ||
|
||
deps: | ||
mkdir -p bin | ||
|
||
polo: deps | ||
cd cmd/polo&&go generate&&go build&&mv polo ../../bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
machine: | ||
services: | ||
- docker | ||
|
||
dependencies: | ||
override: | ||
- go get github.com/constabulary/gb/... | ||
- docker info | ||
- docker build -t agonzalezro/polo . | ||
|
||
test: | ||
override: | ||
- gb test | ||
- docker run --entrypoint go agonzalezro/polo test $(docker run --entrypoint glide agonzalezro/polo novendor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
//go:generate go-bindata -o ../../templates/assets.go -pkg=assets -ignore=.DS_Store -ignore=assets.go -prefix=../.. ../../templates/... | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
config "github.com/agonzalezro/polo/config" | ||
"github.com/agonzalezro/polo/site" | ||
kingpin "gopkg.in/alecthomas/kingpin.v2" | ||
fsnotify "gopkg.in/fsnotify.v1" | ||
) | ||
|
||
var ( | ||
app = kingpin.New("polo", `Static site generator "compatible" with Jekyll & Pelican content.`) | ||
|
||
startDaemon = app.Flag("start-daemon", "Start a simple HTTP server watching for markdown changes.").Short('d').Bool() | ||
port = app.Flag("port", "Port where to run the server.").Default("8080").Short('p').Int() | ||
configPath = app.Flag("config", "The settings file.").Short('c').Default("config.json").String() | ||
|
||
templatesBasePath = app.Flag("templates-base-path", fmt.Sprintf("Where the '%s/' folder resides (in case it exists).", site.TemplatesRelativePath)).Default(".").ExistingDir() | ||
|
||
verbose = app.Flag("verbose", "Verbose logging.").Short('v').Bool() | ||
|
||
source = app.Arg("source", "Folder where the content resides.").Required().ExistingDir() | ||
output = app.Arg("output", "Where to store the published files.").Required().String() | ||
) | ||
|
||
func main() { | ||
app.HelpFlag.Short('h') | ||
kingpin.MustParse(app.Parse(os.Args[1:])) | ||
|
||
if *verbose { | ||
log.SetLevel(log.DebugLevel) | ||
} | ||
|
||
if !dirExists(*output) { | ||
if err := os.Mkdir(*output, os.ModePerm); err != nil { | ||
app.FatalUsage("The output folder couldn't be created!") | ||
} | ||
} | ||
|
||
s, err := site.New(*source, *output, *configPath, *templatesBasePath) | ||
if err != nil { | ||
switch err.(type) { | ||
case config.ErrorParsingConfigFile: | ||
app.FatalUsage("Malformed JSON config file: ", err) | ||
default: | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
if err := s.Write(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if *startDaemon { | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer watcher.Close() | ||
|
||
go func() { | ||
for { | ||
select { | ||
case event := <-watcher.Events: | ||
if event.Op != fsnotify.Chmod { | ||
log.Info("Rewriting the site") | ||
if err := s.Write(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
case err := <-watcher.Errors: | ||
log.Fatal(err) // TODO: perhaps return err | ||
} | ||
} | ||
}() | ||
|
||
for path := range subdirectories(*source) { | ||
watcher.Add(path) | ||
} | ||
|
||
addr := fmt.Sprintf(":%d", *port) | ||
log.Info("Static server running on ", addr) | ||
log.Fatal(http.ListenAndServe(addr, http.FileServer(http.Dir(*output)))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
) | ||
|
||
func subdirectories(parentPath string) chan string { | ||
paths := make(chan string, 1) | ||
|
||
walkFn := func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
log.Warning(err) | ||
} | ||
if info.IsDir() { | ||
paths <- path | ||
} | ||
return nil | ||
} | ||
|
||
go func() { | ||
filepath.Walk(parentPath, walkFn) | ||
close(paths) | ||
}() | ||
|
||
return paths | ||
} | ||
|
||
func dirExists(p string) bool { | ||
if fi, err := os.Stat(p); err == nil { | ||
return fi.IsDir() | ||
} | ||
return false | ||
} |
File renamed without changes.
Oops, something went wrong.