Create page for new editor when missing
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Peter Stuifzand 2020-05-12 16:12:33 +02:00
parent 574d7b41a3
commit 8f653778ee
2 changed files with 21 additions and 6 deletions

View File

@ -100,14 +100,14 @@ func saveWithGit(fp *FilePages, p string, summary, author string) error {
cmd.Dir = fp.dirname
err := cmd.Run()
if err != nil {
return fmt.Errorf("while adding page %s: %s", p, err)
return fmt.Errorf("while adding page %s: %w", p, err)
}
cmd = exec.Command("git", "commit", "-m", "Changes to "+p+" by "+author+"\n\n"+summary)
cmd.Dir = fp.dirname
err = cmd.Run()
if err != nil {
return fmt.Errorf("while commiting page %s: %s", p, err)
return fmt.Errorf("while commiting page %s: %w", p, err)
}
return nil
}

23
main.go
View File

@ -18,6 +18,10 @@ import (
"p83.nl/go/indieauth"
)
func init() {
log.SetFlags(log.Lshortfile)
}
var (
mp PagesRepository
)
@ -348,7 +352,13 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mpPage := mp.Get(page)
pageText := mpPage.Content
jsonEditor := pageText != "" && (pageText[0] == '{' || pageText[0] == '[')
if pageText == "" {
pageText = "[]"
}
var rawMsg json.RawMessage
err = json.NewDecoder(strings.NewReader(pageText)).Decode(&rawMsg)
jsonEditor := pageText != "" && err == nil
var editor template.HTML
if jsonEditor {
@ -419,10 +429,15 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jsonPage := pageText != "" && (pageText[0] == '[' || pageText[0] == '{')
if jsonPage {
//pageText, err = renderJSON(pageText)
if pageText == "" {
pageText = "[]"
}
var rawMsg json.RawMessage
err = json.NewDecoder(strings.NewReader(pageText)).Decode(&rawMsg)
jsonPage := pageText != "" && err == nil
if jsonPage {
var listItems []struct {
Id int
Indented int