Switch to ISO 8601

This commit is contained in:
Andrew-71 2024-03-15 20:20:33 +03:00
parent 6ad28b714b
commit 1923ad0bc8
5 changed files with 38 additions and 16 deletions

View file

@ -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!
* 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!

2
log.go
View file

@ -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 {

View file

@ -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)
}

View file

@ -10,8 +10,8 @@
</head>
<body>
<header class="container">
<h1 style="margin-bottom:0;">Hibiscus.txt</h1>
<p id="status" style="margin-top:0;">Today is 14/03/2024</p>
<h1 style="margin-bottom:0;">🌺 Hibiscus.txt</h1>
<p id="status" style="margin-top:0;">Today is <span id="today-date">14/03/2024</span></p>
</header>
<main class="container">
<h2 style="margin-bottom:0;"><label for="day">Your day so far:</label></h2>
@ -26,4 +26,15 @@
<p><a href="/page/sitemap" class="no-accent"></a> v0.0.1 | PoC using <a href="https://picocss.com">PicoCSS</a></p>
</footer>
</body>
<script defer>
function updateTime() {
let todayDate = new Date()
let timeField = document.getElementById("today-date")
timeField.innerText = todayDate.toISOString().split('T')[0]
}
updateTime()
</script>
</html>

View file

@ -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)