1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-11 21:10:26 +00:00

Add /about page, remove -title option, add -name and -icon options

This commit is contained in:
bouncepaw 2021-01-23 18:45:17 +05:00
parent 355fd4b1b0
commit e72ca863e3
8 changed files with 237 additions and 75 deletions

View File

@ -24,10 +24,12 @@ Options:
Used when -auth-method=fixed. Path to file with user credentials. (default "mycocredentials.json")
-home string
The home page (default "home")
-icon string
What to show in the navititle in the beginning, before the colon (default "🍄")
-name string
What is the name of your wiki (default "wiki")
-port string
Port to serve the wiki at (default "1737")
-title string
How to call your wiki in the navititle (default "🍄")
-url string
URL at which your wiki can be found. Used to generate feeds (default "http://0.0.0.0:$port")
-user-tree string

View File

@ -13,7 +13,8 @@ func init() {
flag.StringVar(&util.URL, "url", "http://0.0.0.0:$port", "URL at which your wiki can be found. Used to generate feeds and social media previews")
flag.StringVar(&util.ServerPort, "port", "1737", "Port to serve the wiki at using HTTP")
flag.StringVar(&util.HomePage, "home", "home", "The home page name")
flag.StringVar(&util.SiteTitle, "title", "🍄", "How to call your wiki in the navititle")
flag.StringVar(&util.SiteNavIcon, "icon", "🍄", "What to show in the navititle in the beginning, before the colon")
flag.StringVar(&util.SiteName, "name", "wiki", "What is the name of your wiki")
flag.StringVar(&util.UserTree, "user-tree", "u", "Hypha which is a superhypha of all user pages")
flag.StringVar(&util.AuthMethod, "auth-method", "none", "What auth method to use. Variants: \"none\", \"fixed\"")
flag.StringVar(&util.FixedCredentialsPath, "fixed-credentials-path", "mycocredentials.json", "Used when -auth-method=fixed. Path to file with user credentials.")

View File

@ -129,6 +129,12 @@ func handlerIcon(w http.ResponseWriter, rq *http.Request) {
}
}
func handlerAbout(w http.ResponseWriter, rq *http.Request) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(base("About "+util.SiteName, templates.AboutHTML())))
}
func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
@ -160,6 +166,7 @@ func main() {
http.HandleFunc("/list", handlerList)
http.HandleFunc("/reindex", handlerReindex)
http.HandleFunc("/random", handlerRandom)
http.HandleFunc("/about", handlerAbout)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(WikiDir+"/static"))))
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")

View File

@ -23,7 +23,7 @@ func CanonicalName(name string) string {
func naviTitle(canonicalName string) string {
var (
html = fmt.Sprintf(`<h1 class="navi-title" id="navi-title">
<a href="/page/%s">%s</a><span aria-hidden="true" class="navi-title__colon">:</span>`, util.HomePage, util.SiteTitle)
<a href="/page/%s">%s</a><span aria-hidden="true" class="navi-title__colon">:</span>`, util.HomePage, util.SiteNavIcon)
prevAcc = `/page/`
parts = strings.Split(canonicalName, "/")
rel = "up"

View File

@ -1,3 +1,6 @@
{% import "github.com/bouncepaw/mycorrhiza/util" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% func BaseHTML(title, body string, headElements ...string) %}
<!doctype html>
<html>
@ -41,3 +44,25 @@
{% endif %}
</tr>
{% endfunc %}
{% func AboutHTML() %}
<main>
<section>
<h1>About {%s util.SiteName %}</h1>
<ul>
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> β 0.12 indev</li>
{%- if user.AuthUsed -%}
<li><b>User count:</b> {%d user.Count() %}</li>
<li><b>Home page:</b> <a href="/">{%s util.HomePage %}</a></li>
<li><b>Administrators:</b> {%- for i, username := range user.ListUsersWithGroup("admin") -%}
{%- if i > 0 -%}<span aria-hidden="true">, </span>
{%- endif -%}
<a href="/page/{%s util.UserTree %}/{%s username %}">{%s username %}</a>{%- endfor -%}</li>
{%- else -%}
<li>This wiki does not use authorization</li>
{%- endif -%}
</ul>
<p>See <a href="/list">/list</a> for information about hyphae on this wiki.</p>
</section>
</main>
{% endfunc %}

View File

@ -5,21 +5,27 @@
package templates
//line templates/http_stuff.qtpl:1
import "github.com/bouncepaw/mycorrhiza/util"
//line templates/http_stuff.qtpl:2
import "github.com/bouncepaw/mycorrhiza/user"
//line templates/http_stuff.qtpl:4
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line templates/http_stuff.qtpl:1
//line templates/http_stuff.qtpl:4
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line templates/http_stuff.qtpl:1
//line templates/http_stuff.qtpl:4
func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string, headElements ...string) {
//line templates/http_stuff.qtpl:1
//line templates/http_stuff.qtpl:4
qw422016.N().S(`
<!doctype html>
<html>
@ -27,68 +33,68 @@ func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string, headElements
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/static/common.css">
<title>`)
//line templates/http_stuff.qtpl:7
//line templates/http_stuff.qtpl:10
qw422016.E().S(title)
//line templates/http_stuff.qtpl:7
//line templates/http_stuff.qtpl:10
qw422016.N().S(`</title>
`)
//line templates/http_stuff.qtpl:8
//line templates/http_stuff.qtpl:11
for _, el := range headElements {
//line templates/http_stuff.qtpl:8
//line templates/http_stuff.qtpl:11
qw422016.N().S(el)
//line templates/http_stuff.qtpl:8
//line templates/http_stuff.qtpl:11
}
//line templates/http_stuff.qtpl:8
//line templates/http_stuff.qtpl:11
qw422016.N().S(`
</head>
<body>
`)
//line templates/http_stuff.qtpl:11
//line templates/http_stuff.qtpl:14
qw422016.N().S(body)
//line templates/http_stuff.qtpl:11
//line templates/http_stuff.qtpl:14
qw422016.N().S(`
</body>
</html>
`)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
}
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
func WriteBaseHTML(qq422016 qtio422016.Writer, title, body string, headElements ...string) {
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
StreamBaseHTML(qw422016, title, body, headElements...)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
}
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
func BaseHTML(title, body string, headElements ...string) string {
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
WriteBaseHTML(qb422016, title, body, headElements...)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
return qs422016
//line templates/http_stuff.qtpl:14
//line templates/http_stuff.qtpl:17
}
//line templates/http_stuff.qtpl:16
//line templates/http_stuff.qtpl:19
func StreamHyphaListHTML(qw422016 *qt422016.Writer, tbody string, pageCount int) {
//line templates/http_stuff.qtpl:16
//line templates/http_stuff.qtpl:19
qw422016.N().S(`
<main>
<h1>List of hyphae</h1>
<p>This wiki has `)
//line templates/http_stuff.qtpl:19
//line templates/http_stuff.qtpl:22
qw422016.N().D(pageCount)
//line templates/http_stuff.qtpl:19
//line templates/http_stuff.qtpl:22
qw422016.N().S(` hyphae.</p>
<table>
<thead>
@ -99,105 +105,203 @@ func StreamHyphaListHTML(qw422016 *qt422016.Writer, tbody string, pageCount int)
</thead>
<tbody>
`)
//line templates/http_stuff.qtpl:28
//line templates/http_stuff.qtpl:31
qw422016.N().S(tbody)
//line templates/http_stuff.qtpl:28
//line templates/http_stuff.qtpl:31
qw422016.N().S(`
</tbody>
</table>
</main>
`)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
}
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
func WriteHyphaListHTML(qq422016 qtio422016.Writer, tbody string, pageCount int) {
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
StreamHyphaListHTML(qw422016, tbody, pageCount)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
}
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
func HyphaListHTML(tbody string, pageCount int) string {
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
WriteHyphaListHTML(qb422016, tbody, pageCount)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
return qs422016
//line templates/http_stuff.qtpl:32
//line templates/http_stuff.qtpl:35
}
//line templates/http_stuff.qtpl:34
//line templates/http_stuff.qtpl:37
func StreamHyphaListRowHTML(qw422016 *qt422016.Writer, hyphaName, binaryMime string, binaryPresent bool) {
//line templates/http_stuff.qtpl:34
//line templates/http_stuff.qtpl:37
qw422016.N().S(`
<tr>
<td><a href="/page/`)
//line templates/http_stuff.qtpl:36
//line templates/http_stuff.qtpl:39
qw422016.E().S(hyphaName)
//line templates/http_stuff.qtpl:36
//line templates/http_stuff.qtpl:39
qw422016.N().S(`">`)
//line templates/http_stuff.qtpl:36
//line templates/http_stuff.qtpl:39
qw422016.E().S(hyphaName)
//line templates/http_stuff.qtpl:36
//line templates/http_stuff.qtpl:39
qw422016.N().S(`</a></td>
`)
//line templates/http_stuff.qtpl:37
//line templates/http_stuff.qtpl:40
if binaryPresent {
//line templates/http_stuff.qtpl:37
//line templates/http_stuff.qtpl:40
qw422016.N().S(`
<td>`)
//line templates/http_stuff.qtpl:38
//line templates/http_stuff.qtpl:41
qw422016.E().S(binaryMime)
//line templates/http_stuff.qtpl:38
//line templates/http_stuff.qtpl:41
qw422016.N().S(`</td>
`)
//line templates/http_stuff.qtpl:39
//line templates/http_stuff.qtpl:42
} else {
//line templates/http_stuff.qtpl:39
//line templates/http_stuff.qtpl:42
qw422016.N().S(`
<td></td>
`)
//line templates/http_stuff.qtpl:41
//line templates/http_stuff.qtpl:44
}
//line templates/http_stuff.qtpl:41
//line templates/http_stuff.qtpl:44
qw422016.N().S(`
</tr>
`)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
}
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
func WriteHyphaListRowHTML(qq422016 qtio422016.Writer, hyphaName, binaryMime string, binaryPresent bool) {
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
StreamHyphaListRowHTML(qw422016, hyphaName, binaryMime, binaryPresent)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
}
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
func HyphaListRowHTML(hyphaName, binaryMime string, binaryPresent bool) string {
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
WriteHyphaListRowHTML(qb422016, hyphaName, binaryMime, binaryPresent)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
return qs422016
//line templates/http_stuff.qtpl:43
//line templates/http_stuff.qtpl:46
}
//line templates/http_stuff.qtpl:48
func StreamAboutHTML(qw422016 *qt422016.Writer) {
//line templates/http_stuff.qtpl:48
qw422016.N().S(`
<main>
<section>
<h1>About `)
//line templates/http_stuff.qtpl:51
qw422016.E().S(util.SiteName)
//line templates/http_stuff.qtpl:51
qw422016.N().S(`</h1>
<ul>
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> β 0.12 indev</li>
`)
//line templates/http_stuff.qtpl:54
if user.AuthUsed {
//line templates/http_stuff.qtpl:54
qw422016.N().S(` <li><b>User count:</b> `)
//line templates/http_stuff.qtpl:55
qw422016.N().D(user.Count())
//line templates/http_stuff.qtpl:55
qw422016.N().S(`</li>
<li><b>Home page:</b> <a href="/">`)
//line templates/http_stuff.qtpl:56
qw422016.E().S(util.HomePage)
//line templates/http_stuff.qtpl:56
qw422016.N().S(`</a></li>
<li><b>Administrators:</b>`)
//line templates/http_stuff.qtpl:57
for i, username := range user.ListUsersWithGroup("admin") {
//line templates/http_stuff.qtpl:58
if i > 0 {
//line templates/http_stuff.qtpl:58
qw422016.N().S(`<span aria-hidden="true">, </span>
`)
//line templates/http_stuff.qtpl:59
}
//line templates/http_stuff.qtpl:59
qw422016.N().S(` <a href="/page/`)
//line templates/http_stuff.qtpl:60
qw422016.E().S(util.UserTree)
//line templates/http_stuff.qtpl:60
qw422016.N().S(`/`)
//line templates/http_stuff.qtpl:60
qw422016.E().S(username)
//line templates/http_stuff.qtpl:60
qw422016.N().S(`">`)
//line templates/http_stuff.qtpl:60
qw422016.E().S(username)
//line templates/http_stuff.qtpl:60
qw422016.N().S(`</a>`)
//line templates/http_stuff.qtpl:60
}
//line templates/http_stuff.qtpl:60
qw422016.N().S(`</li>
`)
//line templates/http_stuff.qtpl:61
} else {
//line templates/http_stuff.qtpl:61
qw422016.N().S(` <li>This wiki does not use authorization</li>
`)
//line templates/http_stuff.qtpl:63
}
//line templates/http_stuff.qtpl:63
qw422016.N().S(` </ul>
<p>See <a href="/list">/list</a> for information about hyphae on this wiki.</p>
</section>
</main>
`)
//line templates/http_stuff.qtpl:68
}
//line templates/http_stuff.qtpl:68
func WriteAboutHTML(qq422016 qtio422016.Writer) {
//line templates/http_stuff.qtpl:68
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/http_stuff.qtpl:68
StreamAboutHTML(qw422016)
//line templates/http_stuff.qtpl:68
qt422016.ReleaseWriter(qw422016)
//line templates/http_stuff.qtpl:68
}
//line templates/http_stuff.qtpl:68
func AboutHTML() string {
//line templates/http_stuff.qtpl:68
qb422016 := qt422016.AcquireByteBuffer()
//line templates/http_stuff.qtpl:68
WriteAboutHTML(qb422016)
//line templates/http_stuff.qtpl:68
qs422016 := string(qb422016.B)
//line templates/http_stuff.qtpl:68
qt422016.ReleaseByteBuffer(qb422016)
//line templates/http_stuff.qtpl:68
return qs422016
//line templates/http_stuff.qtpl:68
}

View File

@ -8,6 +8,28 @@ var AuthUsed bool
var users sync.Map
var tokens sync.Map
func ListUsersWithGroup(group string) []string {
usersWithTheGroup := []string{}
users.Range(func(_, v interface{}) bool {
userobj := v.(*User)
if userobj.Group == group {
usersWithTheGroup = append(usersWithTheGroup, userobj.Name)
}
return true
})
return usersWithTheGroup
}
func Count() int {
i := 0
users.Range(func(k, v interface{}) bool {
i++
return true
})
return i
}
func HasUsername(username string) bool {
_, has := users.Load(username)
return has

View File

@ -11,7 +11,8 @@ var (
URL string
ServerPort string
HomePage string
SiteTitle string
SiteNavIcon string
SiteName string
WikiDir string
UserTree string
AuthMethod string