1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 05:50:27 +00:00

Several improvements

This commit is contained in:
Timur Ismagilov 2020-07-17 20:18:03 +05:00
parent 28585171bd
commit 3a04f7e80a
5 changed files with 19 additions and 18 deletions

View File

@ -28,13 +28,15 @@ var (
configJsonPath string
// Default values that can be overriden in config.json
Address = "0.0.0.0:80"
TitleEditTemplate = `Edit %s`
TitleTemplate = `%s`
GenericErrorMsg = `<b>Sorry, something went wrong</b>`
SiteTitle = `MycorrhizaWiki`
Theme = `default-light`
Mycelia = []MyceliumConfig{
Address = "0.0.0.0:80"
TitleEditTemplate = `Edit %s`
TitleTemplate = `%s`
GenericErrorMsg = `<b>Sorry, something went wrong</b>`
SiteTitle = `MycorrhizaWiki`
Theme = `default-light`
HomePage = `/Home`
BinaryLimit int64 = 10 << 20
Mycelia = []MyceliumConfig{
{[]string{"main"}, "main"},
{[]string{"sys", "system"}, "system"},
}
@ -64,6 +66,8 @@ func readConfig() bool {
Address string `json:"address"`
Theme string `json:"theme"`
SiteTitle string `json:"site-title"`
HomePage string `json:"home-page"`
BinaryLimitMB int64 `json:"binary-limit-mb"`
Mycelia []MyceliumConfig `json:"mycelia"`
TitleTemplates struct {
EditHypha string `json:"edit-hypha"`
@ -82,6 +86,8 @@ func readConfig() bool {
SiteTitle = cfg.SiteTitle
TitleEditTemplate = cfg.TitleTemplates.EditHypha
TitleTemplate = cfg.TitleTemplates.ViewHypha
HomePage = "/" + cfg.HomePage
BinaryLimit = 1024 * cfg.BinaryLimitMB
Mycelia = cfg.Mycelia
return true

View File

@ -15,6 +15,7 @@ func (h *Hypha) asHtml() (string, error) {
<h1 class="page__title">` + rev.FullName + `</h1>
`
// What about using <figure>?
// TODO: support other things
if h.hasBinaryData() {
ret += fmt.Sprintf(`<img src="/:%s?action=binary&rev=%d" class="page__amnt"/>`, util.DisplayToCanonical(rev.FullName), rev.Id)
}

View File

@ -12,6 +12,7 @@ import (
"strings"
"time"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/mycelium"
"github.com/bouncepaw/mycorrhiza/util"
)
@ -275,7 +276,7 @@ func (h *Hypha) WriteBinaryFileFromHttpData(rq *http.Request) *Hypha {
return h
}
// 10 MB file size limit
rq.ParseMultipartForm(10 << 20)
rq.ParseMultipartForm(cfg.BinaryLimit)
// Read file
file, handler, err := rq.FormFile("binary")
if file != nil {

11
main.go
View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
@ -82,16 +81,8 @@ func main() {
r.HandleFunc(cfg.MyceliumUrl+cfg.HyphaUrl, HandlerView)
r.HandleFunc(cfg.HyphaUrl, HandlerView)
// Debug page that renders all hyphae.
// TODO: make it redirect to home page.
// TODO: make a home page.
r.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `
<p>Check out <a href="/Fruit">Fruit</a> maybe.</p>
<p><strong>TODO:</strong> make this page usable</p>
`)
http.Redirect(w, rq, cfg.HomePage, http.StatusSeeOther)
})
http.Handle("/", r)

View File

@ -2,6 +2,8 @@
"address": "0.0.0.0:1737",
"theme": "default-light",
"site-title": "🍄 MycorrhizaWiki",
"home-page": "Home",
"binary-limit-mb": 10,
"title-templates": {
"edit-hypha": "Edit %s at MycorrhizaWiki",
"view-hypha": "%s at MycorrhizaWiki"