copying theme addition files onto the hugo directories. fixes #6
This commit is contained in:
@@ -38,11 +38,13 @@ func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmpfs := afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs())
|
||||||
|
|
||||||
es := &editSession{
|
es := &editSession{
|
||||||
docname: docName,
|
docname: docName,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
doc: acedoc.NewString(string(contents)),
|
doc: acedoc.NewString(string(contents)),
|
||||||
tmpfs: afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs()),
|
tmpfs: tmpfs,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = es.doc.LogToFile(path.Join(ch.Dir, "logs", docName))
|
err = es.doc.LogToFile(path.Join(ch.Dir, "logs", docName))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package caddyhugo
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -88,6 +89,10 @@ func (ch *CaddyHugo) ServeHTTPWithNext(next httpserver.Handler, w http.ResponseW
|
|||||||
if strings.HasPrefix(r.URL.Path, "/media/") {
|
if strings.HasPrefix(r.URL.Path, "/media/") {
|
||||||
return ch.serveMedia(w, r)
|
return ch.serveMedia(w, r)
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(r.URL.Path, "/hugo/fs/") {
|
||||||
|
printTree(afero.NewOsFs(), w, ch.Dir)
|
||||||
|
return 200, nil
|
||||||
|
}
|
||||||
|
|
||||||
return next.ServeHTTP(w, r)
|
return next.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
@@ -244,6 +249,70 @@ func (ch *CaddyHugo) serveDraft(w http.ResponseWriter, r *http.Request) (int, er
|
|||||||
return 200, nil
|
return 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printTree(fs afero.Fs, w io.Writer, dir string) {
|
||||||
|
const (
|
||||||
|
Line = " │ "
|
||||||
|
Tab = " "
|
||||||
|
Elbow = " └─"
|
||||||
|
Tee = " ├─"
|
||||||
|
)
|
||||||
|
|
||||||
|
wd, _ := os.Getwd()
|
||||||
|
fmt.Fprintln(w, wd)
|
||||||
|
|
||||||
|
if dir == "" {
|
||||||
|
dir = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
openDirs := map[string]bool{}
|
||||||
|
lastFiles := map[string]string{}
|
||||||
|
|
||||||
|
afero.Walk(fs, dir, filepath.WalkFunc(func(p string, info os.FileInfo, err error) error {
|
||||||
|
if strings.HasPrefix(p, "./") {
|
||||||
|
p = p[2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
openDirs[filepath.Dir(p)] = true
|
||||||
|
lastFiles[filepath.Dir(p)] = filepath.Base(p)
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
|
||||||
|
afero.Walk(fs, dir, filepath.WalkFunc(func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(p, "./") {
|
||||||
|
p = p[2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Base(p)[0] == '.' && info.IsDir() {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := Tee
|
||||||
|
|
||||||
|
if lastFiles[filepath.Dir(p)] == filepath.Base(p) {
|
||||||
|
openDirs[filepath.Dir(p)] = false
|
||||||
|
entry = Elbow
|
||||||
|
}
|
||||||
|
|
||||||
|
indent := ""
|
||||||
|
dirs := strings.Split(p, string(filepath.Separator))
|
||||||
|
dirs = dirs[:len(dirs)-1]
|
||||||
|
for i := range dirs {
|
||||||
|
if openDirs[filepath.Join(dirs[:i]...)] {
|
||||||
|
indent += Line
|
||||||
|
} else {
|
||||||
|
indent += Tab
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "%s%s %s (%s)\n", indent, entry, filepath.Base(p), p)
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
type aferoHTTP struct {
|
type aferoHTTP struct {
|
||||||
afero.Fs
|
afero.Fs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,18 @@ package caddyhugo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/deps"
|
"github.com/gohugoio/hugo/deps"
|
||||||
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"git.stephensearles.com/stephen/caddy-hugo2/theme-additions"
|
||||||
"git.stephensearles.com/stephen/idleshut"
|
"git.stephensearles.com/stephen/idleshut"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,9 +46,42 @@ func buildSite(sites *hugolib.HugoSites) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeThemeFiles(dir string) error {
|
||||||
|
for _, asset := range themeadditions.AssetNames() {
|
||||||
|
err := os.MkdirAll(path.Join(dir, filepath.Dir(asset)), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("writing", path.Join(dir, asset))
|
||||||
|
f, err := os.Create(path.Join(dir, asset))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b, err := themeadditions.Asset(asset)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = f.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ch *CaddyHugo) configWithFs(fs afero.Fs) (*hugolib.HugoSites, *deps.DepsCfg, error) {
|
func (ch *CaddyHugo) configWithFs(fs afero.Fs) (*hugolib.HugoSites, *deps.DepsCfg, error) {
|
||||||
var err error
|
var err error
|
||||||
cfg := &deps.DepsCfg{}
|
|
||||||
|
hfs := hugofs.NewFrom(fs, &viper.Viper{})
|
||||||
|
cfg := &deps.DepsCfg{Fs: hfs}
|
||||||
|
|
||||||
cfgPath := path.Join(ch.Dir, "config.toml")
|
cfgPath := path.Join(ch.Dir, "config.toml")
|
||||||
cfg.Cfg, err = hugolib.LoadConfig(fs, "", cfgPath)
|
cfg.Cfg, err = hugolib.LoadConfig(fs, "", cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,7 +128,7 @@ func HugoInternalProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = hugoSites.Build(hugolib.BuildCfg{ResetState: true})
|
err = buildSite(hugoSites)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"git.stephensearles.com/stephen/caddy-hugo2/comments"
|
"git.stephensearles.com/stephen/caddy-hugo2/comments"
|
||||||
"git.stephensearles.com/stephen/caddy-hugo2/media"
|
"git.stephensearles.com/stephen/caddy-hugo2/media"
|
||||||
@@ -20,7 +21,11 @@ func SetupCaddy(c *caddy.Controller) error {
|
|||||||
ch := &CaddyHugo{}
|
ch := &CaddyHugo{}
|
||||||
|
|
||||||
ch.Site = httpserver.GetConfig(c)
|
ch.Site = httpserver.GetConfig(c)
|
||||||
err := ch.Setup(ch.Site.Root)
|
root, err := filepath.Abs(ch.Site.Root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ch.Setup(root)
|
||||||
|
|
||||||
c.OnShutdown(func() error {
|
c.OnShutdown(func() error {
|
||||||
return ch.persistAllEdits()
|
return ch.persistAllEdits()
|
||||||
@@ -89,6 +94,11 @@ func (ch *CaddyHugo) Setup(dir string) error {
|
|||||||
return fmt.Errorf("couldn't initialize media: %v", err)
|
return fmt.Errorf("couldn't initialize media: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = writeThemeFiles(ch.Dir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error installing theme files:", err)
|
||||||
|
}
|
||||||
|
|
||||||
err = ch.Publish()
|
err = ch.Publish()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error with initial publish of hugo site:", err)
|
fmt.Println("error with initial publish of hugo site:", err)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
//go:generate go-bindata -ignore .go -pkg themeadditions ./...
|
||||||
|
|
||||||
|
package themeadditions
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user