From 1923ad0bc88ec0c3353196903d8fa2ebb6f807fd Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Fri, 15 Mar 2024 20:20:33 +0300 Subject: [PATCH] Switch to ISO 8601 --- README.md | 12 +++++++++--- log.go | 2 +- pages.go | 18 +++++++++++------- pages/index.html | 15 +++++++++++++-- serve.go | 7 ++++--- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index da83ba8..1b7c395 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,13 @@ Simple plaintext diary. +This project is *very* highly opinionated and minimal. + ## Features: -* Lack of features. No, really. -* Does one thing and does it... decently? -* Intention to eventually go dependency-less. Sorry chi, I still like you! \ No newline at end of file +* Each day, you get a txt file. You have until 23:59 of that very day to finalise it. +* At any moment, you can log a single line to the log file +* You can save named notes to document milestones, big events, or just a nice game you played this month +* You can export everything in a zip file. Emergency export code for other people will be supported + +* No extra features. No encryption, OAuth, or anything fancy. Even the password is plain te- wait is this a feature? +* Intention to eventually *Go* dependency-less (get it?). Sorry chi, I still like you! \ No newline at end of file diff --git a/log.go b/log.go index 94550e3..4403e71 100644 --- a/log.go +++ b/log.go @@ -11,7 +11,7 @@ import ( // AppendLog adds the input string to the end of the log file with a timestamp func appendLog(input string) error { - t := time.Now().Format("02-01-2006 15:04") // dd-mm-yyyy HH:MM + t := time.Now().Format("2006-01-02 15:04") // yyyy-mm-dd HH:MM f, err := os.OpenFile("./data/log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { diff --git a/pages.go b/pages.go index 2081889..38eb797 100644 --- a/pages.go +++ b/pages.go @@ -12,28 +12,32 @@ func NotFound(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./pages/error/404.html") } -// GetDay gets... a day... page func GetDay(w http.ResponseWriter, r *http.Request) { // TODO: This will be *very* different, `today` func will be needed dayString := chi.URLParam(r, "day") if dayString == "" { - dayString = time.Now().Format("02-01-2006") // By default, use today + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("day not specified")) + return } GetFile("day/"+dayString, w, r) } -// GetNote gets... a day... page func GetNote(w http.ResponseWriter, r *http.Request) { // TODO: This will be *very* different, `today` func will be needed noteString := chi.URLParam(r, "note") if noteString == "" { - w.WriteHeader(http.StatusNotFound) // TODO: maybe different status fits better? - w.Write([]byte("note name not given")) + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("note not specified")) return } GetFile("notes/"+noteString, w, r) } -func PostDayPage(w http.ResponseWriter, r *http.Request) { - +func GetToday(w http.ResponseWriter, r *http.Request) { + GetFile("day/"+time.Now().Format("2006-01-02"), w, r) +} + +func PostToday(w http.ResponseWriter, r *http.Request) { + PostFile("day/"+time.Now().Format("2006-01-02"), w, r) } diff --git a/pages/index.html b/pages/index.html index f56e789..eb2679d 100644 --- a/pages/index.html +++ b/pages/index.html @@ -10,8 +10,8 @@
-

Hibiscus.txt

-

Today is 14/03/2024

+

🌺 Hibiscus.txt

+

Today is 14/03/2024

@@ -26,4 +26,15 @@

v0.0.1 | PoC using PicoCSS

+ + \ No newline at end of file diff --git a/serve.go b/serve.go index 0fa5448..87e7211 100644 --- a/serve.go +++ b/serve.go @@ -24,9 +24,9 @@ func Serve() { apiRouter := chi.NewRouter() apiRouter.Get("/readme", func(w http.ResponseWriter, r *http.Request) { GetFile("readme", w, r) }) - apiRouter.Get("/log", func(w http.ResponseWriter, r *http.Request) { GetFile("log", w, r) }) - apiRouter.Post("/readme", func(w http.ResponseWriter, r *http.Request) { PostFile("readme", w, r) }) + apiRouter.Get("/log", func(w http.ResponseWriter, r *http.Request) { GetFile("log", w, r) }) + apiRouter.Post("/log", func(w http.ResponseWriter, r *http.Request) { PostLog(w, r) }) apiRouter.Get("/day", func(w http.ResponseWriter, r *http.Request) { ListFiles("day", w, r) }) apiRouter.Get("/day/{day}", func(w http.ResponseWriter, r *http.Request) { GetDay(w, r) }) @@ -34,7 +34,8 @@ func Serve() { apiRouter.Get("/notes", func(w http.ResponseWriter, r *http.Request) { ListFiles("notes", w, r) }) apiRouter.Get("/notes/{note}", func(w http.ResponseWriter, r *http.Request) { GetNote(w, r) }) - apiRouter.Post("/log", func(w http.ResponseWriter, r *http.Request) { PostLog(w, r) }) + apiRouter.Get("/today", func(w http.ResponseWriter, r *http.Request) { GetToday(w, r) }) + apiRouter.Post("/today", func(w http.ResponseWriter, r *http.Request) { PostToday(w, r) }) r.Mount("/api", apiRouter)