diff --git a/file.go b/file.go index c8bb9c8..a01e594 100644 --- a/file.go +++ b/file.go @@ -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 } diff --git a/main.go b/main.go index 6b50030..c79889c 100644 --- a/main.go +++ b/main.go @@ -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