Switch to ISO 8601
This commit is contained in:
parent
6ad28b714b
commit
1923ad0bc8
5 changed files with 38 additions and 16 deletions
12
README.md
12
README.md
|
@ -2,7 +2,13 @@
|
||||||
|
|
||||||
Simple plaintext diary.
|
Simple plaintext diary.
|
||||||
|
|
||||||
|
This project is *very* highly opinionated and minimal.
|
||||||
|
|
||||||
## Features:
|
## Features:
|
||||||
* Lack of features. No, really.
|
* Each day, you get a txt file. You have until 23:59 of that very day to finalise it.
|
||||||
* Does one thing and does it... decently?
|
* At any moment, you can log a single line to the log file
|
||||||
* Intention to eventually go dependency-less. Sorry chi, I still like you!
|
* 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
2
log.go
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// AppendLog adds the input string to the end of the log file with a timestamp
|
// AppendLog adds the input string to the end of the log file with a timestamp
|
||||||
func appendLog(input string) error {
|
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)
|
f, err := os.OpenFile("./data/log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
18
pages.go
18
pages.go
|
@ -12,28 +12,32 @@ func NotFound(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./pages/error/404.html")
|
http.ServeFile(w, r, "./pages/error/404.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDay gets... a day... page
|
|
||||||
func GetDay(w http.ResponseWriter, r *http.Request) {
|
func GetDay(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO: This will be *very* different, `today` func will be needed
|
// TODO: This will be *very* different, `today` func will be needed
|
||||||
dayString := chi.URLParam(r, "day")
|
dayString := chi.URLParam(r, "day")
|
||||||
if dayString == "" {
|
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)
|
GetFile("day/"+dayString, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNote gets... a day... page
|
|
||||||
func GetNote(w http.ResponseWriter, r *http.Request) {
|
func GetNote(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO: This will be *very* different, `today` func will be needed
|
// TODO: This will be *very* different, `today` func will be needed
|
||||||
noteString := chi.URLParam(r, "note")
|
noteString := chi.URLParam(r, "note")
|
||||||
if noteString == "" {
|
if noteString == "" {
|
||||||
w.WriteHeader(http.StatusNotFound) // TODO: maybe different status fits better?
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte("note name not given"))
|
w.Write([]byte("note not specified"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
GetFile("notes/"+noteString, w, r)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="container">
|
<header class="container">
|
||||||
<h1 style="margin-bottom:0;">Hibiscus.txt</h1>
|
<h1 style="margin-bottom:0;">🌺 Hibiscus.txt</h1>
|
||||||
<p id="status" style="margin-top:0;">Today is 14/03/2024</p>
|
<p id="status" style="margin-top:0;">Today is <span id="today-date">14/03/2024</span></p>
|
||||||
</header>
|
</header>
|
||||||
<main class="container">
|
<main class="container">
|
||||||
<h2 style="margin-bottom:0;"><label for="day">Your day so far:</label></h2>
|
<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>
|
<p><a href="/page/sitemap" class="no-accent"></a> v0.0.1 | PoC using <a href="https://picocss.com">PicoCSS</a></p>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</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>
|
</html>
|
7
serve.go
7
serve.go
|
@ -24,9 +24,9 @@ func Serve() {
|
||||||
apiRouter := chi.NewRouter()
|
apiRouter := chi.NewRouter()
|
||||||
|
|
||||||
apiRouter.Get("/readme", func(w http.ResponseWriter, r *http.Request) { GetFile("readme", w, r) })
|
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.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", 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) })
|
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", 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.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)
|
r.Mount("/api", apiRouter)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue