summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Johnson <[email protected]>2025-02-10 02:19:21 -0500
committerSamuel Johnson <[email protected]>2025-02-10 02:19:21 -0500
commit9de239a9badbbc075f1cc8079a6435f0780e5d26 (patch)
tree559f29f7c3a0213a4fd712f4f325f5f820e6ca79
But it was a beginningtrunk
-rw-r--r--.gitignore29
-rw-r--r--LICENSE11
-rw-r--r--cmd/parser/main.go7
-rw-r--r--cmd/web/handlers/blog.go32
-rw-r--r--cmd/web/handlers/context.go5
-rw-r--r--cmd/web/handlers/routes.go14
-rw-r--r--cmd/web/main.go19
-rw-r--r--go.mod5
-rw-r--r--go.sum2
-rw-r--r--ui/html/base.tmpl.html17
-rw-r--r--ui/html/pages/index.tmpl.html6
11 files changed, 147 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..88753d0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
+# If you prefer the allow list template instead of the deny list, see community template:
+# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
+#
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, built with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
+
+# Dependency directories (remove the comment below to include it)
+# vendor/
+
+# Go workspace file
+go.work
+go.work.sum
+
+# env file
+.env
+
+*.swp
+
+build/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d722c4d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,11 @@
+Copyright 2025 Samuel Johnson
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/cmd/parser/main.go b/cmd/parser/main.go
new file mode 100644
index 0000000..cc0602a
--- /dev/null
+++ b/cmd/parser/main.go
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Printf("Markdown compiler app\n")
+}
diff --git a/cmd/web/handlers/blog.go b/cmd/web/handlers/blog.go
new file mode 100644
index 0000000..5a874f4
--- /dev/null
+++ b/cmd/web/handlers/blog.go
@@ -0,0 +1,32 @@
+package handlers
+
+import (
+ "html/template"
+ "log"
+ "net/http"
+)
+
+func (ctx *HandlerContext) blogIndex(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/" {
+ http.NotFound(w, r)
+ return
+ }
+
+ files := []string{
+ "./ui/html/base.tmpl.html",
+ "./ui/html/pages/index.tmpl.html",
+ }
+
+ compiled, err := template.ParseFiles(files...)
+ if err != nil {
+ log.Println(err.Error())
+ http.Error(w, "Internal Server Error", 500)
+ return
+ }
+
+ err = compiled.ExecuteTemplate(w, "base", ctx)
+ if err != nil {
+ log.Println(err.Error())
+ http.Error(w, "Internal Server Error", 500)
+ }
+}
diff --git a/cmd/web/handlers/context.go b/cmd/web/handlers/context.go
new file mode 100644
index 0000000..7df2915
--- /dev/null
+++ b/cmd/web/handlers/context.go
@@ -0,0 +1,5 @@
+package handlers
+
+type HandlerContext struct {
+ Webmaster string
+}
diff --git a/cmd/web/handlers/routes.go b/cmd/web/handlers/routes.go
new file mode 100644
index 0000000..5a57440
--- /dev/null
+++ b/cmd/web/handlers/routes.go
@@ -0,0 +1,14 @@
+package handlers
+
+import (
+ "github.com/gorilla/mux"
+)
+
+func RegisterEndpoints(webmaster string) *mux.Router {
+ ctx := HandlerContext{webmaster}
+
+ blogRouter := mux.NewRouter()
+ blogRouter.HandleFunc("/", ctx.blogIndex)
+
+ return blogRouter
+}
diff --git a/cmd/web/main.go b/cmd/web/main.go
new file mode 100644
index 0000000..748e4bb
--- /dev/null
+++ b/cmd/web/main.go
@@ -0,0 +1,19 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "net/http"
+
+ "paterissa.net/mblog/cmd/web/handlers"
+)
+
+func main() {
+ webmaster := flag.String("webmaster", "", "host of the website")
+ port := flag.Int("port", 5050, "the hosting port")
+ flag.Parse()
+
+ router := handlers.RegisterEndpoints(*webmaster)
+ log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), router))
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..3dff8f8
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module paterissa.net/mblog
+
+go 1.23.5
+
+require github.com/gorilla/mux v1.8.1 // indirect
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..7128337
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
+github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
diff --git a/ui/html/base.tmpl.html b/ui/html/base.tmpl.html
new file mode 100644
index 0000000..6b05b70
--- /dev/null
+++ b/ui/html/base.tmpl.html
@@ -0,0 +1,17 @@
+{{define "base"}}
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>{{template "title" .}} - Paterissa</title>
+</head>
+<body>
+ <header>
+ <h1><a href="/">Paterissa</a></h1>
+ </header>
+ <main>
+ {{template "main" .}}
+ </main>
+</body>
+</html>
+{{end}}
diff --git a/ui/html/pages/index.tmpl.html b/ui/html/pages/index.tmpl.html
new file mode 100644
index 0000000..c252465
--- /dev/null
+++ b/ui/html/pages/index.tmpl.html
@@ -0,0 +1,6 @@
+{{define "title"}}Blog{{end}}
+
+{{define "main"}}
+ <h2>Blog</h2>
+ <p>Home of {{.Webmaster}}</p>
+{{end}}