summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-11-02 23:37:00 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-11-02 23:37:00 -0400
commit9c4b8766cbdc2a4c63a03292b58cf35d981e1321 (patch)
treeaa84619601ff14e7ea86b1147827f24a6fa82fa0
parent85db279e33804c118b019c5f1e7666798df3e1f5 (diff)
simplemde
-rw-r--r--.gitmodules6
-rw-r--r--got/page.html.got2
-rw-r--r--got/view_blob.got11
-rw-r--r--src/edit/main.go5
-rw-r--r--src/edit/util.go7
-rw-r--r--src/edit/views.go11
m---------static/font-awesome0
-rw-r--r--static/mde.js20
m---------static/simplemde0
-rw-r--r--static/style.css38
10 files changed, 86 insertions, 14 deletions
diff --git a/.gitmodules b/.gitmodules
index fe8941b..0ab69ea 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,9 @@
[submodule "src/lukeshu.com/git/go/libsystemd"]
path = src/lukeshu.com/git/go/libsystemd
url = https://lukeshu.com/git/go/libsystemd/
+[submodule "static/simplemde"]
+ path = static/simplemde
+ url = https://github.com/NextStepWebs/simplemde-markdown-editor
+[submodule "static/font-awesome"]
+ path = static/font-awesome
+ url = https://github.com/FortAwesome/Font-Awesome
diff --git a/got/page.html.got b/got/page.html.got
index a0f34f9..c061d50 100644
--- a/got/page.html.got
+++ b/got/page.html.got
@@ -8,7 +8,7 @@
<title>{{.title | html}}</title>
- <link href="/style.css" rel="stylesheet">
+ <link href="/static/style.css" rel="stylesheet">
{{.head}}
</head>
<body>
diff --git a/got/view_blob.got b/got/view_blob.got
index 1a3c4cd..95692b0 100644
--- a/got/view_blob.got
+++ b/got/view_blob.got
@@ -7,7 +7,7 @@
<textarea name="_body">{{.content | html }}</textarea>
<label>
Description of change:
- <input type="text" value="_message" />
+ <input type="text" name="_message" />
</label>
<input type="submit" value="Save">
</form>
@@ -20,15 +20,18 @@
<input type="file" name="_body" required=required>
<label>
Description of change:
- <input type="text" value="_message" />
+ <input type="text" name="_message" />
</label>
<input type="submit" value="Upload">
</form>
<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="_method" value="DELETE">
<label>
- Description of change:
- <input type="text" value="_message" />
+ Reason for deletion:
+ <input type="text" name="_message" />
</label>
<input type="submit" value="Delete">
</form>
+{{if eq .ctype "text/markdown"}}
+<script src="/static/mde.js"></script>
+{{end}}
diff --git a/src/edit/main.go b/src/edit/main.go
index a7ec7bd..66e9a36 100644
--- a/src/edit/main.go
+++ b/src/edit/main.go
@@ -9,6 +9,7 @@ import (
func ServeIndex(out http.ResponseWriter, in *http.Request) {
if in.URL.Path != "/" {
http.NotFound(out, in)
+ return
}
http.Redirect(out, in, "/files/", http.StatusMovedPermanently)
}
@@ -16,9 +17,9 @@ func ServeIndex(out http.ResponseWriter, in *http.Request) {
func main() {
socket, err := util.StreamListener(os.Args[1], os.Args[2])
errcheck(err)
- errcheck(os.Chdir("/srv/http/edit.team4272.com/www.git"))
+ errcheck(os.Setenv("GIT_DIR", "/srv/http/edit.team4272.com/www.git"))
http.Handle("/", util.SaneHTTPHandler{http.HandlerFunc(ServeIndex)})
- http.Handle("/static/", util.SaneHTTPHandler{http.FileServer(http.Dir("static"))})
+ http.Handle("/static/", util.SaneHTTPHandler{http.StripPrefix("/static", http.FileServer(http.Dir("static")))})
http.Handle("/files/", util.SaneHTTPHandler{http.StripPrefix("/files", http.HandlerFunc(ServeGit))})
errcheck(http.Serve(socket, nil))
}
diff --git a/src/edit/util.go b/src/edit/util.go
index 5835b10..b1950ed 100644
--- a/src/edit/util.go
+++ b/src/edit/util.go
@@ -33,15 +33,16 @@ func getctype(name string, content []byte) string {
if ctype == "" {
ctype = http.DetectContentType(content)
}
- return ctype
-}
-func istext(ctype string) bool {
i := strings.Index(ctype, ";")
if i == -1 {
i = len(ctype)
}
ctype = strings.TrimSpace(strings.ToLower(ctype[0:i]))
+ return ctype
+}
+
+func istext(ctype string) bool {
return strings.HasPrefix(ctype, "text/") || strings.HasSuffix(ctype, "+xml")
}
diff --git a/src/edit/views.go b/src/edit/views.go
index 0998d4a..1d3176d 100644
--- a/src/edit/views.go
+++ b/src/edit/views.go
@@ -65,18 +65,25 @@ func renderViewBlob(w io.Writer, upath string, file GitFile) error {
if err != nil {
return err
}
+ ctype := getctype(upath, content)
// Component render
var buf bytes.Buffer
err = tmplViewBlob.Execute(&buf, map[string]string{
"path": upath,
- "ctype": getctype(upath, content),
+ "ctype": ctype,
"content": string(content),
})
if err != nil {
return err
}
+ head := ""
+ if ctype == "text/markdown" {
+ head += "<link rel=\"stylesheet\" href=\"/static/font-awesome/css/font-awesome.min.css\">\n"
+ head += "<link rel=\"stylesheet\" href=\"/static/simplemde/dist/simplemde.min.css\">\n"
+ head += "<script src=\"/static/simplemde/dist/simplemde.min.js\"></script>\n"
+ }
// Page render
- return renderPage(w, upath, "", buf.String())
+ return renderPage(w, upath, head, buf.String())
}
func renderModified(w io.Writer, upath string) error {
diff --git a/static/font-awesome b/static/font-awesome
new file mode 160000
+Subproject a8386aae19e200ddb0f6845b5feeee5eb701368
diff --git a/static/mde.js b/static/mde.js
new file mode 100644
index 0000000..7471110
--- /dev/null
+++ b/static/mde.js
@@ -0,0 +1,20 @@
+(function() {
+ var textarea = document.getElementsByTagName("textarea")[0];
+ var form = textarea.form;
+ var container = document.createElement('div');
+ /*container.innerHTML =
+ "<p>I know it looks funny in the editor, but to set the page "+
+ "title (what appears in the tab name/window bar), put this at "+
+ "the top of the page:</p>\n"+
+ "<pre>---\ntitle: \"Your Title Here\"\n---\n</pre>";*/
+ form.insertBefore(container, textarea);
+ container.appendChild(textarea);
+
+ var simplemde = new SimpleMDE({
+ autoDownloadFontAwesome: false,
+ element: textarea,
+ promptURLs: true,
+ forceSync: true,
+ showIcons: ["code", "table"],
+ });
+})();
diff --git a/static/simplemde b/static/simplemde
new file mode 160000
+Subproject 6abda7ab68cc20f4aca870eb243747951b90ab0
diff --git a/static/style.css b/static/style.css
index 6c63196..cad83c0 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,2 +1,36 @@
-.foo {
-} \ No newline at end of file
+* {
+ box-sizing: border-box;
+}
+body > table {
+ width: 100%;
+}
+body > table tr > td:nth-child(3) {
+ text-align: right;
+}
+body > form {
+ display: block;
+ border: solid 1px black;
+ margin: 1em 0;
+ padding: 0.5em;
+}
+body > form > * {
+ margin: 0.4em 0;
+}
+label {
+ display: block;
+}
+textarea {
+ width: 100%;
+ height: 30em;
+ font-family: monospace;
+}
+input[type=text] {
+ width: 100%;
+}
+input[type=file] {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+ background: #EEEEEE;
+ border-radius: 4px;
+}