miki

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

commit 6e70eb2a5289e0e2d1a6b7e4bc7ad30d7c1279fe
parent bf7340b4ea4a2d445f20bc7ab568fb283fa48b5c
Author: weetat <wtenison@protonmail.com>
Date:   Mon, 24 Feb 2025 04:08:14 +0000

Add edit page with a shared page handler

Pull the /home handler out into pageHandler and register it for /edit
as well.

Diffstat:
Msrc/filesystem/filesystem.go | 4++--
Msrc/network/network.go | 73++++++++++++++++++++++++++++++++++++++-----------------------------------
Aweb/edit/index.html | 29+++++++++++++++++++++++++++++
Mweb/global/header.tmpl.html | 5+++--
Mweb/global/styles.css | 28+++++++++++++++-------------
Mweb/home/index.html | 4++--
6 files changed, 89 insertions(+), 54 deletions(-)

diff --git a/src/filesystem/filesystem.go b/src/filesystem/filesystem.go @@ -104,10 +104,10 @@ func GetYamlContent(yamlObjectId string, dataContainerReference any) { 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.Panicln("__PANIC\tGetYamlContent:" + _err.Error()) } - log.Printf("DONE\tmain:GetYamlContent:%v\n", dataContainerReference) + log.Printf("DONE\tGetYamlContent:%v\n", dataContainerReference) } func Init() { diff --git a/src/network/network.go b/src/network/network.go @@ -20,6 +20,42 @@ var serverInfo struct { var mux *http.ServeMux +func pageHandler(w http.ResponseWriter, r *http.Request) { + + // Produce URL path to directory relation. + _r, _err := mfs.MakeDirectorySig(filepath.Join(mfs.Paths.WebDirectory, r.URL.String()), 0, mfs.FilePatternHTML) + if _err != nil { + log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourceSig():%s\n", _err) + http.NotFound(w, r) + return + } + + // Collect HTML template files from directory. + _rPkg, _err := mfs.MakeDirectoryPkg(_r) + if _err != nil { + log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + http.NotFound(w, r) + return + } + + _rPkg.DependencyFiles = append(_rPkg.DependencyFiles, mfs.GlobalPkg.DependencyFiles...) + + _tmpl, _err := template.ParseFiles(_rPkg.DependencyFiles...) + if _err != nil { + log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ParseFiles()", 500) + return + } + + if _err = _tmpl.ExecuteTemplate(w, "index.html", _rPkg.DependencyData); _err != nil { + log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) + http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ExecuteTemplate()", 500) + return + } + + log.Printf("DONE\tHandleFunc:%s\n", r.URL) +} + func Init() { //// GET SERVER INFO @@ -62,41 +98,8 @@ func Init() { // log.Printf("DONE\tmain:mux.HandleFunc:%s\n", r.URL) }) - mux.HandleFunc("/home", func(w http.ResponseWriter, r *http.Request) { - - // Produce URL path to directory relation. - _r, _err := mfs.MakeDirectorySig(filepath.Join(mfs.Paths.WebDirectory, "/home"), 0, mfs.FilePatternHTML) - if _err != nil { - log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourceSig():%s\n", _err) - http.NotFound(w, r) - return - } - - // Collect HTML template files from directory. - _rPkg, _err := mfs.MakeDirectoryPkg(_r) - if _err != nil { - log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) - http.NotFound(w, r) - return - } - - _rPkg.DependencyFiles = append(_rPkg.DependencyFiles, mfs.GlobalPkg.DependencyFiles...) - - _tmpl, _err := template.ParseFiles(_rPkg.DependencyFiles...) - if _err != nil { - log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) - http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ParseFiles()", 500) - return - } - - if _err = _tmpl.ExecuteTemplate(w, "index.html", _rPkg.DependencyData); _err != nil { - log.Printf("_ERROR\tHandleFunc(\"/\"):MakeResourcePkg():%s\n", _err) - http.Error(w, "_ERROR:HandleFunc(\"/\"):template.ExecuteTemplate()", 500) - return - } - - log.Printf("DONE\tHandleFunc:%s\n", r.URL) - }) + mux.HandleFunc("/home", pageHandler) + mux.HandleFunc("/edit", pageHandler) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // log.Printf("CALL\tmain:mux.HandleFunc:%s\n", r.URL) diff --git a/web/edit/index.html b/web/edit/index.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<html> + +<head> + <title>Miki/Edit</title> + <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0" /> + <link rel="stylesheet" type="text/css" href="/web/global/styles.css" /> + <script src="/web/global/script.js" defer></script> +</head> + +<body> + + {{template "header" "EDIT"}} + + <section class="_content"> + + <section id="left"></section> + + <section id=""> + + </section> + + <section id="right"></section> + + </section> +</body> + +</html> +\ No newline at end of file diff --git a/web/global/header.tmpl.html b/web/global/header.tmpl.html @@ -5,11 +5,12 @@ <div id="left" class="collapsible_"> <div class="_button">MENU</div> <div class="_content"> - <p>TEST MENU</p> + <a href="https://test.wtenison.com/home">HOME</a> + <a href="https://test.wtenison.com/edit">EDIT</a> </div> </div> - <div id="title">TEST</div> + <div id="title">{{.}}</div> <div id="right" class="collapsible_"> <div class="_button">SEARCH</div> diff --git a/web/global/styles.css b/web/global/styles.css @@ -89,19 +89,21 @@ } } - header { - position: fixed; - width: 100%; - height: var(--miki_header__height); - z-index: 1; - top: 0; - left: 0; + @scope(header) { + :scope { + position: fixed; + width: 100%; + height: var(--miki_header__height); + z-index: 1; + top: 0; + left: 0; - display: grid; - justify-content: center; + display: grid; + justify-content: center; - color: var(--color__ff); - background-color: var(--color__bf); + color: var(--color__ff); + background-color: var(--color__bf); + } >._content { width: min(100vw, var(--miki_page__max-width)); @@ -133,7 +135,7 @@ >._content { position: fixed; - width: 100%; + width: 100vw; z-index: 1; top: calc(var(--miki_header__height)); left: 0; @@ -207,7 +209,7 @@ /* Collapsible container */ > :nth-child(2) { - width: 98%; + /* width: 98%; */ height: 0; overflow: hidden; transition: 0.33s; diff --git a/web/home/index.html b/web/home/index.html @@ -2,7 +2,7 @@ <html> <head> - <title>Miki</title> + <title>Miki/Home</title> <meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="/web/global/styles.css" /> <script src="/web/global/script.js" defer></script> @@ -10,7 +10,7 @@ <body> - {{template "header"}} + {{template "header" "HOME"}} <section class="_content">