diff --git a/flag.go b/flag.go index f3add19..47a2134 100644 --- a/flag.go +++ b/flag.go @@ -18,6 +18,7 @@ func init() { flag.StringVar(&util.UserHypha, "user-hypha", "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.") + flag.StringVar(&util.HeaderLinksHypha, "header-links-hypha", "", "Optional hypha that overrides the header links") } // Do the things related to cli args and die maybe @@ -40,13 +41,9 @@ func parseCliArgs() { util.URL = "http://0.0.0.0:" + util.ServerPort } - if !isCanonicalName(util.HomePage) { - log.Fatal("Error: you must use a proper name for the homepage") - } - - if !isCanonicalName(util.UserHypha) { - log.Fatal("Error: you must use a proper name for user hypha") - } + util.HomePage = CanonicalName(util.HomePage) + util.UserHypha = CanonicalName(util.UserHypha) + util.HeaderLinksHypha = CanonicalName(util.HeaderLinksHypha) switch util.AuthMethod { case "none": diff --git a/hypha.go b/hypha.go index 6e59cbe..be7fef4 100644 --- a/hypha.go +++ b/hypha.go @@ -313,3 +313,17 @@ func FetchTextPart(d *HyphaData) (string, error) { } return string(text), nil } + +func setHeaderLinks() { + if userLinksHypha, ok := GetHyphaData(util.HeaderLinksHypha); !ok { + util.SetDefaultHeaderLinks() + } else { + contents, err := ioutil.ReadFile(userLinksHypha.textPath) + if err != nil || len(contents) == 0 { + util.SetDefaultHeaderLinks() + } else { + text := string(contents) + util.ParseHeaderLinks(text, markup.Rocketlink) + } + } +} diff --git a/main.go b/main.go index 700adad..9daa2cd 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,19 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) { log.Println("Start indexing hyphae...") Index(WikiDir) log.Println("Indexed", hyphae.Count(), "hyphae") + http.Redirect(w, rq, "/", http.StatusSeeOther) +} + +// Update header links by reading the configured hypha, if there is any, or resorting to default values. +func handlerUpdateHeaderLinks(w http.ResponseWriter, rq *http.Request) { + log.Println(rq.URL) + if ok := user.CanProceed(rq, "update-header-links"); !ok { + HttpErr(w, http.StatusForbidden, util.HomePage, "Not enough rights", "You must be a moderator to update header links.") + log.Println("Rejected", rq.URL) + return + } + setHeaderLinks() + http.Redirect(w, rq, "/", http.StatusSeeOther) } // Redirect to a random hypha. @@ -153,11 +166,11 @@ func main() { log.Fatal(err) } log.Println("Wiki storage directory is", WikiDir) - log.Println("Start indexing hyphae...") Index(WikiDir) log.Println("Indexed", hyphae.Count(), "hyphae") history.Start(WikiDir) + setHeaderLinks() // See http_readers.go for /page/, /text/, /binary/ // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/, /unattach-ask/, /unattach-confirm/ @@ -165,6 +178,7 @@ func main() { // See http_history.go for /history/, /recent-changes http.HandleFunc("/list", handlerList) http.HandleFunc("/reindex", handlerReindex) + http.HandleFunc("/update-header-links", handlerUpdateHeaderLinks) http.HandleFunc("/random", handlerRandom) http.HandleFunc("/about", handlerAbout) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(WikiDir+"/static")))) diff --git a/templates/asset.qtpl.go b/templates/asset.qtpl.go index ae76899..7f405cb 100644 --- a/templates/asset.qtpl.go +++ b/templates/asset.qtpl.go @@ -27,13 +27,18 @@ func StreamDefaultCSS(qw422016 *qt422016.Writer) { @media screen and (min-width: 800px) { main { padding:1rem 2rem; margin: 0 auto; width: 800px; } .hypha-tabs { padding: 1rem 2rem; margin: 0 auto; width: 800px; } + header { margin: 0 auto; width: 800px; } + .header-links__entry { margin-right: 1.5rem; } + .header-links__entry:nth-of-type(1), .hypha-tabs__tab:nth-of-type(1) { margin-left: 2rem; } .hypha-tabs__tab { margin-right: 1.5rem; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2); border-bottom: 2px #ddd solid; padding: 0 .5rem; } } @media screen and (max-width: 800px) { main { padding: 1rem; margin: 0; width: 100%; } - .hypha-tabs { padding: 1rem; margin: 0; width: 100%; } + .hypha-tabs{ padding: 1rem; margin: 0; width: 100%; } .hypha-tabs__tab { box-shadow: none; margin-right: .5rem; padding: .25rem .5rem; } + header { width: 100%; } + .header-links__entry { margin-right: .5rem; } } *, *::before, *::after {box-sizing: border-box;} html { height:100%; padding:0; } @@ -88,9 +93,11 @@ figcaption { padding-bottom: .5rem; } #new-name {width:100%;} +header { margin-bottom: .5rem; } +.header-links__link { text-decoration: none; display: block; width: 100%; height: 100%; padding: .25rem; } .hypha-tabs { padding: 0; } -.hypha-tabs__flex { margin: 0; padding: 0; display: flex; flex-wrap: wrap; } -.hypha-tabs__tab { list-style-type: none; } +.header-links__list, .hypha-tabs__flex { margin: 0; padding: 0; display: flex; flex-wrap: wrap; } +.header-links__entry, .hypha-tabs__tab { list-style-type: none; } .hypha-tabs__tab a { text-decoration: none; } .hypha-tabs__tab_active { font-weight: bold; } .hypha-tabs__user { font-style:italic; } @@ -137,6 +144,9 @@ table { background-color: #eee; } html { background-color: #ddd; background-image: url("data:image/svg+xml,%3Csvg width='42' height='44' viewBox='0 0 42 44' xmlns='http://www.w3.org/2000/svg'%3E%3Cg id='Page-1' fill='none' fill-rule='evenodd'%3E%3Cg id='brick-wall' fill='%23bbbbbb' fill-opacity='0.4'%3E%3Cpath d='M0 0h42v44H0V0zm1 1h40v20H1V1zM0 23h20v20H0V23zm22 0h20v20H22V23z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); } /* heropatterns.com */ +header { background-color: #bbb; } +.header-links__link { color: black; } +.header-links__link:hover { background-color: #eee; } main, .hypha-tabs__tab { background-color: white; } .hypha-tabs__tab { clip-path: inset(-20px -20px 0 -20px); } @@ -155,12 +165,15 @@ td { border: #ddd 1px solid; } /* Dark theme! */ @media (prefers-color-scheme: dark) { html { background: #222; color: #ddd; } -main, article, .hypha-tabs__tab { background-color: #343434; } +main, article, .hypha-tabs__tab, header { background-color: #343434; color: #ddd; } a, .wikilink_external { color: #f1fa8c; } a:visited, .wikilink_external:visited { color: #ffb86c; } .wikilink_new, .wikilink_new:visited { color: #dd4444; } + +.header-links__link, .header-links__link:visited, .prevnext__el, .prevnext__el:visited { color: #ddd; } +.header-links__link:hover { background-color: #444; } .hypha-tabs__tab a, .hypha-tabs__tab { color: #ddd; background-color: #232323; border: 0; } .hypha-tabs__tab_active { background-color: #343434; } diff --git a/templates/default.css b/templates/default.css index c55f4ea..ffbcc82 100644 --- a/templates/default.css +++ b/templates/default.css @@ -2,13 +2,18 @@ @media screen and (min-width: 800px) { main { padding:1rem 2rem; margin: 0 auto; width: 800px; } .hypha-tabs { padding: 1rem 2rem; margin: 0 auto; width: 800px; } + header { margin: 0 auto; width: 800px; } + .header-links__entry { margin-right: 1.5rem; } + .header-links__entry:nth-of-type(1), .hypha-tabs__tab:nth-of-type(1) { margin-left: 2rem; } .hypha-tabs__tab { margin-right: 1.5rem; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2); border-bottom: 2px #ddd solid; padding: 0 .5rem; } } @media screen and (max-width: 800px) { main { padding: 1rem; margin: 0; width: 100%; } - .hypha-tabs { padding: 1rem; margin: 0; width: 100%; } + .hypha-tabs{ padding: 1rem; margin: 0; width: 100%; } .hypha-tabs__tab { box-shadow: none; margin-right: .5rem; padding: .25rem .5rem; } + header { width: 100%; } + .header-links__entry { margin-right: .5rem; } } *, *::before, *::after {box-sizing: border-box;} html { height:100%; padding:0; } @@ -63,9 +68,11 @@ figcaption { padding-bottom: .5rem; } #new-name {width:100%;} +header { margin-bottom: .5rem; } +.header-links__link { text-decoration: none; display: block; width: 100%; height: 100%; padding: .25rem; } .hypha-tabs { padding: 0; } -.hypha-tabs__flex { margin: 0; padding: 0; display: flex; flex-wrap: wrap; } -.hypha-tabs__tab { list-style-type: none; } +.header-links__list, .hypha-tabs__flex { margin: 0; padding: 0; display: flex; flex-wrap: wrap; } +.header-links__entry, .hypha-tabs__tab { list-style-type: none; } .hypha-tabs__tab a { text-decoration: none; } .hypha-tabs__tab_active { font-weight: bold; } .hypha-tabs__user { font-style:italic; } @@ -112,6 +119,9 @@ table { background-color: #eee; } html { background-color: #ddd; background-image: url("data:image/svg+xml,%3Csvg width='42' height='44' viewBox='0 0 42 44' xmlns='http://www.w3.org/2000/svg'%3E%3Cg id='Page-1' fill='none' fill-rule='evenodd'%3E%3Cg id='brick-wall' fill='%23bbbbbb' fill-opacity='0.4'%3E%3Cpath d='M0 0h42v44H0V0zm1 1h40v20H1V1zM0 23h20v20H0V23zm22 0h20v20H22V23z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); } /* heropatterns.com */ +header { background-color: #bbb; } +.header-links__link { color: black; } +.header-links__link:hover { background-color: #eee; } main, .hypha-tabs__tab { background-color: white; } .hypha-tabs__tab { clip-path: inset(-20px -20px 0 -20px); } @@ -130,12 +140,15 @@ td { border: #ddd 1px solid; } /* Dark theme! */ @media (prefers-color-scheme: dark) { html { background: #222; color: #ddd; } -main, article, .hypha-tabs__tab { background-color: #343434; } +main, article, .hypha-tabs__tab, header { background-color: #343434; color: #ddd; } a, .wikilink_external { color: #f1fa8c; } a:visited, .wikilink_external:visited { color: #ffb86c; } .wikilink_new, .wikilink_new:visited { color: #dd4444; } + +.header-links__link, .header-links__link:visited, .prevnext__el, .prevnext__el:visited { color: #ddd; } +.header-links__link:hover { background-color: #444; } .hypha-tabs__tab a, .hypha-tabs__tab { color: #ddd; background-color: #232323; border: 0; } .hypha-tabs__tab_active { background-color: #343434; } diff --git a/templates/http_stuff.qtpl b/templates/http_stuff.qtpl index d5dacad..c65c0f9 100644 --- a/templates/http_stuff.qtpl +++ b/templates/http_stuff.qtpl @@ -11,6 +11,15 @@ {% for _, el := range headElements %}{%s= el %}{% endfor %}
+