1 Commits

Author SHA1 Message Date
Alex Schroeder
ce6af76f69 Switch to Markdown, rewrite README 2025-06-07 22:37:10 +02:00
6 changed files with 47 additions and 29 deletions

View File

@@ -1,15 +1,22 @@
# Oddµ: A Small Wiki Written in Go
I'm the maintainer of [Oddmuse](http://oddmuse.org/), a wiki written
in Perl 5. As we wait for Perl 6 to come around, I wanted to
experiment with [Go](https://golang.org/). The article
[Writing Web Applications](https://golang.org/doc/articles/wiki/)
provided the initial code. [Cajun](https://github.com/m4tty/cajun)
provides the rendering engine for
[Wiki Creole](http://www.wikicreole.org/), the "standard" markup for
wikis.
This is a minimal wiki in the spirit of [Shortest Wiki Contest](https://wiki.c2.com/?ShortestWikiContest)
and [Wiki Principles](https://wiki.c2.com/?WikiPrinciples).
The article [Writing Web Applications](https://golang.org/doc/articles/wiki/)
provided the initial code. It's how I learned Go.
## Plans
To get started, use `go run .` to compile and run it; then use your browser to visit
`http://localhost:8080/edit/index`.
## Some context
Initially, this wiki used [Cajun](https://github.com/m4tty/cajun) to render Wiki Creole
but I switched it to [Markdown](https://github.com/gomarkdown/markdown).
At the time, I planned to use [git2go](https://github.com/libgit2/git2go) to implement
history pages, recent changes, reverting to old versions. None of that ever came about,
however.
Many years later I did use it as the basis for [Oddμ](https://alexschroeder.ch/view/oddmu/index),
however.
Add [git2go](https://github.com/libgit2/git2go) with all that entails:
history pages, recent changes, reverting to old versions.

View File

@@ -1,6 +1,10 @@
<!DOCTYPE html>
<html>
<body>
<h1>Editing {{.Title}}</h1>
<form action="/save/{{.Title}}" method="POST">
<div><textarea name="body" rows="20" cols="80">{{printf "%s" .Body}}</textarea></div>
<div><input type="submit" value="Save"></div>
</form>
</body>
</html>

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module alexschroeder.ch/cgit/oddmu
go 1.22.3
require github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b // indirect

4
go.sum Normal file
View File

@@ -0,0 +1,4 @@
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/m4tty/cajun v0.0.0-20150303030909-35de273cc87b h1:aY3LtSBlkQahoWaPTytHcIFsDbeXFYMc4noRQ/N5Q+A=
github.com/m4tty/cajun v0.0.0-20150303030909-35de273cc87b/go.mod h1:zFXkL7I5vIwKg4dxEA9025SLdIHu9qFX/cYTdUcusHc=

View File

@@ -1,5 +1,7 @@
<h1>{{.Title}}</h1>
<p>[<a href="/edit/{{.Title}}">edit</a>]</p>
<div>{{.Html}}</div>
<!DOCTYPE html>
<html>
<body>
{{.Html}}
<nav><hr><a href="/edit/{{.Title}}">edit</a></nav>
</body>
</html>

20
wiki.go
View File

@@ -2,10 +2,10 @@ package main
import (
"html/template"
"io/ioutil"
"net/http"
"os"
"regexp"
"github.com/m4tty/cajun"
"github.com/gomarkdown/markdown"
)
var templates = template.Must(template.ParseFiles("edit.html", "view.html"))
@@ -19,13 +19,13 @@ type Page struct {
}
func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
filename := p.Title + ".md"
return os.WriteFile(filename, p.Body, 0600)
}
func loadPage(title string) (*Page, error) {
filename := title + ".txt"
body, err := ioutil.ReadFile(filename)
filename := title + ".md"
body, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
@@ -47,12 +47,8 @@ func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
http.Redirect(w, r, "/edit/"+title, http.StatusFound)
return
}
html, err := cajun.Transform(string(p.Body))
if err != nil {
// not sure what to do?
} else {
p.Html = template.HTML(html);
}
html := markdown.ToHTML([]byte(p.Body), nil, nil)
p.Html = template.HTML(html);
renderTemplate(w, "view", p)
}