miki

Miki: personal wiki with the fmd markup format
git clone https://wtenison.com/repo/miki.git
Log | Files | Refs | README | LICENSE

commit 98c8a4169eb29606ae480fc68b9ae4435f35eb7c
parent d1e841318bf3a6e0a6cd3fbf71bfca33152204d1
Author: weetat <wtenison@protonmail.com>
Date:   Sat, 22 Feb 2025 19:25:57 +0000

Move home page to web/home and redirect / there

Add a /home handler that renders web/home and make / redirect to it.
Handler errors now go through log instead of fmt.

Diffstat:
Msrc/miki/miki.go | 34++++++++++++++++++++--------------
Aweb/home/index.html | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rweb/script.js -> web/home/script.js | 0
Rweb/styles.css -> web/home/styles.css | 0
Dweb/index.html | 57---------------------------------------------------------
5 files changed, 77 insertions(+), 71 deletions(-)

diff --git a/src/miki/miki.go b/src/miki/miki.go @@ -25,7 +25,7 @@ type DirectorySignature struct { func MakeDirectorySig(dir string, depth int, pattern *regexp.Regexp) (DirectorySignature, error) { if dir == "" || depth < -1 || pattern == nil { - return DirectorySignature{}, fmt.Errorf("__ERROR:\tResource:Make(%s, %d, %s)", dir, depth, pattern) + return DirectorySignature{}, fmt.Errorf("_ERROR:\tResource:Make(%s, %d, %s)", dir, depth, pattern) } if _, _err := os.Stat(dir); _err != nil { @@ -41,6 +41,9 @@ type DirectoryPackage struct { dependencyData IDirectoryData // Any relevant resource data. } +type IDirectoryData interface { +} + func MakeDirectoryPkg(resSig DirectorySignature) (DirectoryPackage, error) { // Check and collect resource signature directory files. @@ -93,15 +96,14 @@ func GetYamlContent(yamlObjectId string, dataContainerReference any) { _decoder := yaml.NewDecoder(_byteBuffer, yaml.ReferenceDirs("sys")) if _err := _decoder.Decode(dataContainerReference); _err != nil { + // NOTE: Not a sustainable solution for error handling long-term. + // TODO: Implement error handling to gracefully exit during runtime. log.Panicln("__PANIC\tmain:GetYamlContent:" + _err.Error()) } log.Printf("DONE\tmain:GetYamlContent:%v\n", dataContainerReference) } -type IDirectoryData interface { -} - func main() { ////////// PULL SYSTEM INFO FROM YAML ////////// @@ -141,52 +143,56 @@ func main() { _mux := http.NewServeMux() _mux.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir(_mfilesys.FileSystemInfo.WebDir)))) _mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/home", http.StatusMovedPermanently) + // log.Println("DONE\tmain:mux.HandleFunc(\"/\"):redirect(\"/home\")") + }) + _mux.HandleFunc("/home", func(w http.ResponseWriter, r *http.Request) { - _r, _err := MakeDirectorySig(_mfilesys.FileSystemInfo.WebDir+"/", -1, regexp.MustCompile("^([a-zA-Z0-9.]+).html$")) + _r, _err := MakeDirectorySig(_mfilesys.FileSystemInfo.WebDir+"/home", 0, regexp.MustCompile("^([a-zA-Z0-9.]+).html$")) if _err != nil { - fmt.Printf("_ERROR\tmain():HandleFunc(\"/\"):MakeResourceSig():%s\n", _err) + log.Printf("_ERROR\tmain:HandleFunc(\"/\"):MakeResourceSig():%s\n", _err) http.NotFound(w, r) return } _rPkg, _err := MakeDirectoryPkg(_r) if _err != nil { - fmt.Printf("_ERROR\tmain():HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + log.Printf("_ERROR\tmain:HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) http.NotFound(w, r) return } _tmpl, _err := template.ParseFiles(_rPkg.dependencyFiles...) if _err != nil { - fmt.Printf("_ERROR\tmain():HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + log.Printf("_ERROR\tmain:HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ParseFiles()", 500) return } if _err = _tmpl.ExecuteTemplate(w, "index.html", _rPkg.dependencyData); _err != nil { - fmt.Printf("_ERROR\tmain():HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + log.Printf("_ERROR\tmain:HandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ExecuteTemplate()", 500) return } - // fmt.Printf("INFO:\tmain():mux:Resource(%+v)\n", _rPkg) + log.Printf("DONE\tmain:mux.HandleFunc:%s\n", _rPkg.root) }) ////////// CONNTECT NoSQL ////////// - mdb, _err := mongo.Connect(options.Client().ApplyURI("mongodb://localhost:27017")) + _mdb, _err := mongo.Connect(options.Client().ApplyURI("mongodb://localhost:27017")) if _err != nil { log.Panicf("_ERROR\tmain():mongo.Connect():%s\n", _err) } defer func() { - if _err = mdb.Disconnect(context.Background()); _err != nil { - log.Panicf("_ERROR\tmain():mongo.Disconnect():%s\n", _err) + if _err = _mdb.Disconnect(context.Background()); _err != nil { + log.Panicf("_ERROR\tmain():mongo.Disconnect:%s\n", _err) } }() ////////// RUN SERVERS ////////// if _err := http.ListenAndServeTLS(":"+_msrvinfo.ServerInfo.Port, _tls_cert_path, _tls_key_path, _mux); _err != nil { - fmt.Printf("_ERROR\tmain():ListenAndServeTLS():%s\n", _err) + fmt.Printf("_ERROR\tmain():ListenAndServeTLS:%s\n", _err) } } diff --git a/web/home/index.html b/web/home/index.html @@ -0,0 +1,56 @@ +<!DOCTYPE html> +<html> + +<head> + <title>Miki</title> + <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0" /> + <link rel="stylesheet" type="text/css" href="/web/home/styles.css" /> + <script src="/web/home/script.js" defer></script> +</head> + +<body> + + <header> + <section class="_content"> + + <div id="left" class="collapsible_"> + <div class="_button">MENU</div> + <div class="_content"> + <p>TEST MENU</p> + </div> + </div> + + <div id="title">TEST</div> + + <div id="right" class="collapsible_"> + <div class="_button">SEARCH</div> + <div class="_content"> + <p>TEST SEARCH</p> + </div> + </div> + + </section> + </header> + + <section class="_content"> + + <section id="left"></section> + + <section id="subject_"> + + <section id="_card" class="__container_bg-1"> + + </section> + + <section id="_body"> + + </section> + + </section> + + <section id="right"></section> + + </section> +</body> + +</html> +\ No newline at end of file diff --git a/web/script.js b/web/home/script.js diff --git a/web/styles.css b/web/home/styles.css diff --git a/web/index.html b/web/index.html @@ -1,56 +0,0 @@ -<!DOCTYPE html> -<html> - -<head> - <title>Miki</title> - <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0" /> - <link rel="stylesheet" type="text/css" href="/web/styles.css" /> - <script src="/web/script.js" defer></script> -</head> - -<body> - - <header> - <section class="_content"> - - <div id="left" class="collapsible_"> - <div class="_button">MENU</div> - <div class="_content"> - <p>TEST MENU</p> - </div> - </div> - - <div id="title">TEST</div> - - <div id="right" class="collapsible_"> - <div class="_button">SEARCH</div> - <div class="_content"> - <p>TEST SEARCH</p> - </div> - </div> - - </section> - </header> - - <section class="_content"> - - <section id="left"></section> - - <section id="subject_"> - - <section id="_card" class="__container_bg-1"> - - </section> - - <section id="_body"> - - </section> - - </section> - - <section id="right"></section> - - </section> -</body> - -</html> -\ No newline at end of file