copying theme addition files onto the hugo directories. fixes #6

pull/16/head
Stephen Searles 7 years ago
parent ab06bed6ec
commit ff1033dfb4
  1. 4
      client.go
  2. 69
      http.go
  3. 42
      hugo.go
  4. 12
      setup.go
  5. 3
      theme-additions/assets.go
  6. 337
      theme-additions/bindata.go

@ -38,11 +38,13 @@ func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
return nil, err
}
tmpfs := afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs())
es := &editSession{
docname: docName,
filename: filename,
doc: acedoc.NewString(string(contents)),
tmpfs: afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs()),
tmpfs: tmpfs,
}
err = es.doc.LogToFile(path.Join(ch.Dir, "logs", docName))

@ -3,6 +3,7 @@ package caddyhugo
import (
"encoding/base64"
"fmt"
"io"
"net"
"net/http"
"os"
@ -88,6 +89,10 @@ func (ch *CaddyHugo) ServeHTTPWithNext(next httpserver.Handler, w http.ResponseW
if strings.HasPrefix(r.URL.Path, "/media/") {
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)
}
@ -244,6 +249,70 @@ func (ch *CaddyHugo) serveDraft(w http.ResponseWriter, r *http.Request) (int, er
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 {
afero.Fs
}

@ -2,13 +2,18 @@ package caddyhugo
import (
"fmt"
"os"
"path"
"path/filepath"
"time"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugolib"
"github.com/spf13/afero"
"github.com/spf13/viper"
"git.stephensearles.com/stephen/caddy-hugo2/theme-additions"
"git.stephensearles.com/stephen/idleshut"
)
@ -41,9 +46,42 @@ func buildSite(sites *hugolib.HugoSites) error {
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) {
var err error
cfg := &deps.DepsCfg{}
hfs := hugofs.NewFrom(fs, &viper.Viper{})
cfg := &deps.DepsCfg{Fs: hfs}
cfgPath := path.Join(ch.Dir, "config.toml")
cfg.Cfg, err = hugolib.LoadConfig(fs, "", cfgPath)
if err != nil {
@ -90,7 +128,7 @@ func HugoInternalProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (
return err
}
err = hugoSites.Build(hugolib.BuildCfg{ResetState: true})
err = buildSite(hugoSites)
if err != nil {
return err
}

@ -5,6 +5,7 @@ import (
"html/template"
"os"
"path"
"path/filepath"
"git.stephensearles.com/stephen/caddy-hugo2/comments"
"git.stephensearles.com/stephen/caddy-hugo2/media"
@ -20,7 +21,11 @@ func SetupCaddy(c *caddy.Controller) error {
ch := &CaddyHugo{}
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 {
return ch.persistAllEdits()
@ -89,6 +94,11 @@ func (ch *CaddyHugo) Setup(dir string) error {
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()
if err != nil {
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
Loading…
Cancel
Save