commit ca00ee623dcf1eda9b3f6b3064be2f936620ce8c Author: Jarkko Toivanen Date: Fri Dec 27 20:16:04 2024 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e329c02 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +doksie diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c802db --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +run: + go run main.go +build: + go build -v -ldflags "-s -w" diff --git a/content/index.md b/content/index.md new file mode 100644 index 0000000..7cba51b --- /dev/null +++ b/content/index.md @@ -0,0 +1,7 @@ +Doksie +======= + +- Will have plain MD files +- Git backup +- Webhook initiated pulling +- Multiple location backings (git-repos) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..deb2b29 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module jakest.us/doksie + +go 1.22.9 + +require github.com/gomarkdown/markdown v0.0.0-20241205020045-f7e15b2f3e62 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..399db93 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gomarkdown/markdown v0.0.0-20241205020045-f7e15b2f3e62 h1:pbAFUZisjG4s6sxvRJvf2N7vhpCvx2Oxb3PmS6pDO1g= +github.com/gomarkdown/markdown v0.0.0-20241205020045-f7e15b2f3e62/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..d80fc28 --- /dev/null +++ b/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "log" + "os" + "text/template" + + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/html" + "github.com/gomarkdown/markdown/parser" + + "fmt" + "net/http" +) + +type Page struct { + Title string + MarkDown []byte + HTML string + Navigation string +} + +const port = 6900 + +func mdToHTML(md []byte) []byte { + // create markdown parser with extensions + extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock + p := parser.NewWithExtensions(extensions) + doc := p.Parse(md) + + // create HTML renderer with extensions + htmlFlags := html.CommonFlags | html.HrefTargetBlank + opts := html.RendererOptions{Flags: htmlFlags} + renderer := html.NewRenderer(opts) + + return markdown.Render(doc, renderer) +} + +func main() { + fmt.Printf("Starting listener on :%v", port) + http.Handle("/static/", http.FileServer(http.Dir("./"))) + http.HandleFunc("/", httpRootHandler) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", port), nil)) +} + +func loadPage(fileUrl string) ([]byte, error) { + var fileContents, err = os.ReadFile(fileUrl) + if err != nil { + return nil, err + } + return fileContents, nil +} +func httpRootHandler(w http.ResponseWriter, r *http.Request) { + var p Page + t, _ := template.ParseFiles("page.html") + markdown, err := loadPage("content/index.md") + p.MarkDown = markdown + if err != nil { + log.Fatal("Can't open file") + } + p.HTML = string(mdToHTML(p.MarkDown)) + p.Navigation = buildNav() + t.Execute(w, p) +} + +func buildNav() string { + + return "Google.com" +} diff --git a/page.html b/page.html new file mode 100644 index 0000000..454d0dc --- /dev/null +++ b/page.html @@ -0,0 +1,17 @@ + + + + + + + {{.Title}} + + + +
+ {{.HTML}} +
+ + diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..19d2a9f --- /dev/null +++ b/static/style.css @@ -0,0 +1,100 @@ +body { + font-family: Tahoma, Verdana, sans-serif; + background-color: #000000; + color: #ffc000; +} + +hr { + border-color: #584200; +} + + +#flexout { + display: flex; + max-width: 75rem; + margin: auto; + justify-content: center; +} +#lpanel { + order: 0; +} +#rpanel { + order: 2; +} +#rpanel, #lpanel, .flexpanel { + width: 15rem; + border-radius: 1rem; + padding: .5rem; + background-color: #271d00; +} + +#loginform { + text-align: center; +} +#titlebox { + font-size: 5em; + text-align: center; +} +#titlebox > img { + height: 1.25em; + vertical-align: sub; +} +#centerbox { + margin-left: 1rem; + margin-right: 1rem; + background-color: #271d00; + border-radius: 1rem; + padding: .5rem; + flex-grow: 1; + order: 1; +} +#postform { + margin-top: 1rem; + margin-bottom: 1rem; +} +#postformtextarea { + box-sizing: border-box; + width: 100%; + border-radius: 1rem; +} +#postformactionrow { + text-align: right; +} + +.post { + position: relative; + border-style: solid; + border-width: 1px; + padding: 1rem; + margin-top: 3rem; + border-radius: 1rem; +} +.postinfo { + position: absolute; + left: -1px; + top: -2em; + height: 3rem; + min-width: 15rem; + background-color: #ffc000; + color: #000000; + border-radius: 3rem; + border-bottom-left-radius: 0; + padding: .25rem; + padding-left: 1rem; + padding-right: 1rem; + text-wrap: nowrap; +} +.postactions { + /*float: right;*/ + position: absolute; + background-color: #ffc000; + padding: .25rem; + border-radius: 2rem; + border-top-right-radius: 0; + right: -1px; + bottom: -1rem; +} +.reactionaction { + height: 2rem; + vertical-align: bottom; +} \ No newline at end of file