From a2e5db444acbf871a3d39ca45f8a474fe9447108 Mon Sep 17 00:00:00 2001
From: Timur Ismagilov
Date: Sun, 9 Jun 2024 00:44:12 +0300
Subject: [PATCH] Fix static not loading and de-qtpl tree
---
history/histweb/view_recent_changes.html | 2 +-
hypview/view_edit.html | 4 +-
main.go | 13 ++-
tree/tree.go | 43 +++++++-
tree/view.qtpl | 32 ------
tree/view.qtpl.go | 126 -----------------------
util/util.go | 2 +
web/newtmpl/base.html | 10 +-
web/static/default.css | 8 +-
web/viewutil/base.html | 10 +-
10 files changed, 66 insertions(+), 184 deletions(-)
delete mode 100644 tree/view.qtpl
delete mode 100644 tree/view.qtpl.go
diff --git a/history/histweb/view_recent_changes.html b/history/histweb/view_recent_changes.html
index b65a262..b744f61 100644
--- a/history/histweb/view_recent_changes.html
+++ b/history/histweb/view_recent_changes.html
@@ -64,7 +64,7 @@
-
+
{{block "subscribe via" .}}Subscribe via RSS, Atom or JSON feed.{{end}}
diff --git a/hypview/view_edit.html b/hypview/view_edit.html
index ae3dc22..1bec2fe 100644
--- a/hypview/view_edit.html
+++ b/hypview/view_edit.html
@@ -39,7 +39,7 @@
{{end}}
-
+
{{end}}
{{define "editing hypha"}}Edit {{beautifulName .}}{{end}}
@@ -98,7 +98,7 @@
{{end}}
{{template "toolbar" .}}
-
+
{{range .EditScripts}}
{{end}}
diff --git a/main.go b/main.go
index 734d2c1..7bd28dd 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,5 @@
// Command mycorrhiza is a program that runs a mycorrhiza wiki.
//
-//go:generate go run github.com/valyala/quicktemplate/qtc -dir=tree
//go:generate go run github.com/valyala/quicktemplate/qtc -dir=history
//go:generate go run github.com/valyala/quicktemplate/qtc -dir=mycoopts
//go:generate go run github.com/valyala/quicktemplate/qtc -dir=auth
@@ -17,9 +16,9 @@ import (
"github.com/bouncepaw/mycorrhiza/internal/cfg"
"github.com/bouncepaw/mycorrhiza/internal/files"
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
- migration2 "github.com/bouncepaw/mycorrhiza/internal/migration"
+ "github.com/bouncepaw/mycorrhiza/internal/migration"
"github.com/bouncepaw/mycorrhiza/internal/shroom"
- user2 "github.com/bouncepaw/mycorrhiza/internal/user"
+ "github.com/bouncepaw/mycorrhiza/internal/user"
"github.com/bouncepaw/mycorrhiza/internal/version"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/web"
@@ -49,11 +48,11 @@ func main() {
hyphae.Index(files.HyphaeDir())
backlinks.IndexBacklinks()
go backlinks.RunBacklinksConveyor()
- user2.InitUserDatabase()
+ user.InitUserDatabase()
history.Start()
history.InitGitRepo()
- migration2.MigrateRocketsMaybe()
- migration2.MigrateHeadingsMaybe()
+ migration.MigrateRocketsMaybe()
+ migration.MigrateHeadingsMaybe()
shroom.SetHeaderLinks()
categories.Init()
interwiki.Init()
@@ -61,7 +60,7 @@ func main() {
// Static files:
static.InitFS(files.StaticFiles())
- if !user2.HasAnyAdmins() {
+ if !user.HasAnyAdmins() {
log.Println("Your wiki has no admin yet. Run Mycorrhiza with -create-admin option to create an admin.")
}
diff --git a/tree/tree.go b/tree/tree.go
index 7597eac..a5aa1b2 100644
--- a/tree/tree.go
+++ b/tree/tree.go
@@ -1,7 +1,10 @@
package tree
import (
+ "fmt"
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
+ "github.com/bouncepaw/mycorrhiza/util"
+ "io"
"path"
"sort"
"strings"
@@ -44,6 +47,41 @@ type child struct {
children []child
}
+/*
+Subhyphae links are recursive. It may end up looking like that if drawn with
+pseudographics:
+╔══════════════╗
+║Foo ║ The presented hyphae are ./foo and ./foo/bar
+║╔════════════╗║
+║║Bar ║║
+║╚════════════╝║
+╚══════════════╝
+*/
+func childHTML(c *child, w io.Writer) {
+ sort.Slice(c.children, func(i, j int) bool {
+ return c.children[i].name < c.children[j].name
+ })
+
+ _, _ = io.WriteString(w, "\n%s\n",
+ c.name,
+ util.BeautifulName(path.Base(c.name)),
+ ))
+
+ if len(c.children) > 0 {
+ _, _ = io.WriteString(w, "\n")
+ for _, child := range c.children {
+ childHTML(&child, w)
+ }
+ _, _ = io.WriteString(w, "
\n")
+ }
+ _, _ = io.WriteString(w, "\n")
+}
+
func addHyphaToChild(hyphaName, subPath string, child *child) {
// when hyphaName = "root/a/b", subPath = "a/b", and child.name = "root"
// addHyphaToChild("root/a/b", "b", child{"root/a"})
@@ -82,8 +120,9 @@ func subhyphaeMatrix(children []child) (html string) {
sort.Slice(children, func(i, j int) bool {
return children[i].name < children[j].name
})
+ var buf strings.Builder
for _, child := range children {
- html += childHTML(&child)
+ childHTML(&child, &buf)
}
- return html
+ return buf.String()
}
diff --git a/tree/view.qtpl b/tree/view.qtpl
deleted file mode 100644
index f6fe3ef..0000000
--- a/tree/view.qtpl
+++ /dev/null
@@ -1,32 +0,0 @@
-{% import "sort" %}
-{% import "path" %}
-{% import "github.com/bouncepaw/mycorrhiza/util" %}
-
-Subhyphae links are recursive. It may end up looking like that if drawn with
-pseudographics:
-╔══════════════╗
-║Foo ║ The presented hyphae are ./foo and ./foo/bar
-║╔════════════╗║
-║║Bar ║║
-║╚════════════╝║
-╚══════════════╝
-{% func childHTML(c *child) %}
-{% code
- sort.Slice(c.children, func(i, j int) bool {
- return c.children[i].name < c.children[j].name
- })
-%}
-
-
- {%s util.BeautifulName(path.Base(c.name)) %}
-
-{% if len(c.children) > 0 %}
-
- {% for _, child := range c.children %}
- {%s= childHTML(&child) %}
- {% endfor %}
-
-{% endif %}
-
-{% endfunc %}
-
diff --git a/tree/view.qtpl.go b/tree/view.qtpl.go
deleted file mode 100644
index 1c1c89a..0000000
--- a/tree/view.qtpl.go
+++ /dev/null
@@ -1,126 +0,0 @@
-// Code generated by qtc from "view.qtpl". DO NOT EDIT.
-// See https://github.com/valyala/quicktemplate for details.
-
-//line tree/view.qtpl:1
-package tree
-
-//line tree/view.qtpl:1
-import "sort"
-
-//line tree/view.qtpl:2
-import "path"
-
-//line tree/view.qtpl:3
-import "github.com/bouncepaw/mycorrhiza/util"
-
-// Subhyphae links are recursive. It may end up looking like that if drawn with
-// pseudographics:
-// ╔══════════════╗
-// ║Foo ║ The presented hyphae are ./foo and ./foo/bar
-// ║╔════════════╗║
-// ║║Bar ║║
-// ║╚════════════╝║
-// ╚══════════════╝
-
-//line tree/view.qtpl:13
-import (
- qtio422016 "io"
-
- qt422016 "github.com/valyala/quicktemplate"
-)
-
-//line tree/view.qtpl:13
-var (
- _ = qtio422016.Copy
- _ = qt422016.AcquireByteBuffer
-)
-
-//line tree/view.qtpl:13
-func streamchildHTML(qw422016 *qt422016.Writer, c *child) {
-//line tree/view.qtpl:13
- qw422016.N().S(`
-`)
-//line tree/view.qtpl:15
- sort.Slice(c.children, func(i, j int) bool {
- return c.children[i].name < c.children[j].name
- })
-
-//line tree/view.qtpl:18
- qw422016.N().S(`
-
-
- `)
-//line tree/view.qtpl:21
- qw422016.E().S(util.BeautifulName(path.Base(c.name)))
-//line tree/view.qtpl:21
- qw422016.N().S(`
-
-`)
-//line tree/view.qtpl:23
- if len(c.children) > 0 {
-//line tree/view.qtpl:23
- qw422016.N().S(`
-
- `)
-//line tree/view.qtpl:25
- for _, child := range c.children {
-//line tree/view.qtpl:25
- qw422016.N().S(`
- `)
-//line tree/view.qtpl:26
- qw422016.N().S(childHTML(&child))
-//line tree/view.qtpl:26
- qw422016.N().S(`
- `)
-//line tree/view.qtpl:27
- }
-//line tree/view.qtpl:27
- qw422016.N().S(`
-
-`)
-//line tree/view.qtpl:29
- }
-//line tree/view.qtpl:29
- qw422016.N().S(`
-
-`)
-//line tree/view.qtpl:31
-}
-
-//line tree/view.qtpl:31
-func writechildHTML(qq422016 qtio422016.Writer, c *child) {
-//line tree/view.qtpl:31
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line tree/view.qtpl:31
- streamchildHTML(qw422016, c)
-//line tree/view.qtpl:31
- qt422016.ReleaseWriter(qw422016)
-//line tree/view.qtpl:31
-}
-
-//line tree/view.qtpl:31
-func childHTML(c *child) string {
-//line tree/view.qtpl:31
- qb422016 := qt422016.AcquireByteBuffer()
-//line tree/view.qtpl:31
- writechildHTML(qb422016, c)
-//line tree/view.qtpl:31
- qs422016 := string(qb422016.B)
-//line tree/view.qtpl:31
- qt422016.ReleaseByteBuffer(qb422016)
-//line tree/view.qtpl:31
- return qs422016
-//line tree/view.qtpl:31
-}
diff --git a/util/util.go b/util/util.go
index bdd155b..499697b 100644
--- a/util/util.go
+++ b/util/util.go
@@ -32,6 +32,7 @@ func ShorterPath(path string) string {
}
// HTTP404Page writes a 404 error in the status, needed when no content is found on the page.
+// TODO: demolish
func HTTP404Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusNotFound)
@@ -39,6 +40,7 @@ func HTTP404Page(w http.ResponseWriter, page string) {
}
// HTTP200Page wraps some frequently used things for successful 200 responses.
+// TODO: demolish
func HTTP200Page(w http.ResponseWriter, page string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusOK)
diff --git a/web/newtmpl/base.html b/web/newtmpl/base.html
index 15a90a4..48ac707 100644
--- a/web/newtmpl/base.html
+++ b/web/newtmpl/base.html
@@ -10,8 +10,8 @@
{{block "title" .}}{{end}}
-
-
+
+
{{range .HeadElements}}{{.}}{{end}}
@@ -45,9 +45,9 @@
{{block "body" .}}{{end}}
-
-
-
+
+
+
{{range .CommonScripts}}
{{end}}
diff --git a/web/static/default.css b/web/static/default.css
index 55731ad..b5b833f 100644
--- a/web/static/default.css
+++ b/web/static/default.css
@@ -108,11 +108,11 @@ main h1:not(.navi-title) {font-size:1.7rem;}
blockquote { margin: 0; padding-left: .75rem; }
.wikilink_external::before { display: inline-block; width: 18px; height: 16px; vertical-align: sub; }
/* .wikilink_external { padding-left: 16px; } */
-.wikilink_gopher::before { content: url("/web/staticatic/icon/gopher-proto.svg"); }
-.wikilink_http::before, .wikilink_https::before { content: url("/web/staticatic/icon/http-proto.svg"); }
+.wikilink_gopher::before { content: url("/staticatic/icon/gopher-proto.svg"); }
+.wikilink_http::before, .wikilink_https::before { content: url("/staticatic/icon/http-proto.svg"); }
/* .wikilink_https { background: transparent url("/static/icon/http-proto.svg") center left no-repeat; } */
-.wikilink_gemini::before { content: url("/web/staticatic/icon/gemini-proto.svg"); }
-.wikilink_mailto::before { content: url("/web/staticatic/icon/mailto-proto.svg"); }
+.wikilink_gemini::before { content: url("/staticatic/icon/gemini-proto.svg"); }
+.wikilink_mailto::before { content: url("/staticatic/icon/mailto-proto.svg"); }
article { overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; line-height: 150%; }
main h1 { margin: .5rem 0 0 0; }
diff --git a/web/viewutil/base.html b/web/viewutil/base.html
index 15a90a4..48ac707 100644
--- a/web/viewutil/base.html
+++ b/web/viewutil/base.html
@@ -10,8 +10,8 @@
{{block "title" .}}{{end}}
-
-
+
+
{{range .HeadElements}}{{.}}{{end}}
@@ -45,9 +45,9 @@
{{block "body" .}}{{end}}
-
-
-
+
+
+
{{range .CommonScripts}}
{{end}}