diff --git a/Makefile b/Makefile index 0b9db7e..51525fe 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,9 @@ auth_run: build gemini_run: build ./mycorrhiza -gemini-cert-path "." metarrhiza +config_run: build + ./mycorrhiza -config-path "assets/config.ini" metarrhiza + build: go generate go build . diff --git a/README.md b/README.md index d7269e6..ac4de92 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# 🍄 MycorrhizaWiki 0.13 +# 🍄 MycorrhizaWiki 0.14 A wiki engine. [Main wiki](https://mycorrhiza.lesarbr.es) ## Building -Also see [detailed instructions](https://mycorrhiza.lesarbr.es/page/deploy) on wiki. +Also see [detailed instructions](https://mycorrhiza.lesarbr.es/hypha/deploy) on wiki. ```sh git clone --recurse-submodules https://github.com/bouncepaw/mycorrhiza cd mycorrhiza diff --git a/assets/assets.qtpl.go b/assets/assets.qtpl.go index 160549b..94343bd 100644 --- a/assets/assets.qtpl.go +++ b/assets/assets.qtpl.go @@ -61,7 +61,7 @@ header { width: 100%; margin-bottom: 1rem; } @media screen and (max-width: 800px) { .amnt-grid { grid-template-columns: 1fr; } - .layout { grid-template-column: auto; grid-template-row: auto auto auto; } + .layout { grid-template-columns: auto; grid-template-rows: auto auto auto; } .main-width { width: 100%; } main { padding: 1rem; margin: 0; } } @@ -178,7 +178,7 @@ figcaption { padding-bottom: .5rem; } .rc-entry__links, .rc-entry__msg { grid-column: 1 / span 2; } .rc-entry__author { font-style: italic; } -.prevnext__el { display: block-inline; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; } +.prevnext__el { display: inline-block; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; } .prevnext__prev { float: left; } .prevnext__next { float: right; text-align: right; } diff --git a/assets/config.ini b/assets/config.ini new file mode 100644 index 0000000..0ad67b9 --- /dev/null +++ b/assets/config.ini @@ -0,0 +1,16 @@ +WikiName = My wiki +NaviTitleIcon = 🐑 + +[Hyphae] +HomeHypha = home +UserHypha = u +HeaderLinksHypha = header-links + +[Network] +HTTPPort = 8080 +URL = https://wiki +GeminiCertificatePath = /home/wiki/gemcerts + +[Authorization] +UseFixedAuth = true +FixedAuthCredentialsPath = /home/wiki/mycocredentials.json diff --git a/flag.go b/flag.go index 77a7d05..a26fee1 100644 --- a/flag.go +++ b/flag.go @@ -10,16 +10,17 @@ import ( ) 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.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.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") - flag.StringVar(&util.GeminiCertPath, "gemini-cert-path", "", "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini.") + // 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.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.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") + // flag.StringVar(&util.GeminiCertPath, "gemini-cert-path", "", "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini.") + flag.StringVar(&util.ConfigFilePath, "config-path", "", "Path to a configuration file. Leave empty if you don't want to use it.") } // Do the things related to cli args and die maybe @@ -31,6 +32,10 @@ func parseCliArgs() { log.Fatal("Error: pass a wiki directory") } + if util.ConfigFilePath != "" { + util.ReadConfigFile(util.ConfigFilePath) + } + var err error WikiDir, err = filepath.Abs(args[0]) util.WikiDir = WikiDir @@ -38,20 +43,12 @@ func parseCliArgs() { log.Fatal(err) } - if util.URL == "http://0.0.0.0:$port" { + if util.URL == "" { util.URL = "http://0.0.0.0:" + util.ServerPort } util.HomePage = util.CanonicalName(util.HomePage) util.UserHypha = util.CanonicalName(util.UserHypha) util.HeaderLinksHypha = util.CanonicalName(util.HeaderLinksHypha) - - switch util.AuthMethod { - case "none": - case "fixed": - user.AuthUsed = true - user.ReadUsersFromFilesystem() - default: - log.Fatal("Error: unknown auth method:", util.AuthMethod) - } + user.AuthUsed = util.UseFixedAuth } diff --git a/go.mod b/go.mod index 26dbe9f..060d073 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.14 require ( git.sr.ht/~adnano/go-gemini v0.1.13 github.com/adrg/xdg v0.2.2 + github.com/go-ini/ini v1.62.0 // indirect github.com/gorilla/feeds v1.1.1 github.com/kr/pretty v0.2.1 // indirect github.com/valyala/quicktemplate v1.6.3 - tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512 // indirect ) diff --git a/go.sum b/go.sum index 0aa3df2..544a723 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/adrg/xdg v0.2.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-ini/ini v1.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU= +github.com/go-ini/ini v1.62.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY= github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA= github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= @@ -35,5 +37,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512 h1:reGEt1vmGompn/6FitHdBatILTsK9CYnQOCw3weoW/s= -tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512/go.mod h1:gqBK7AJ5wPR1bpFOuPmlQObYxwXrFdZmNb2vdzquqoA= diff --git a/util/config.go b/util/config.go new file mode 100644 index 0000000..be9e4f3 --- /dev/null +++ b/util/config.go @@ -0,0 +1,70 @@ +package util + +import ( + "log" + "strconv" + + "github.com/go-ini/ini" +) + +type Config struct { + WikiName string + NaviTitleIcon string + Hyphae + Network + Authorization +} + +type Hyphae struct { + HomeHypha string + UserHypha string + HeaderLinksHypha string +} + +type Network struct { + HTTPPort uint64 + URL string + GeminiCertificatePath string +} + +type Authorization struct { + UseFixedAuth bool + FixedAuthCredentialsPath string +} + +func ReadConfigFile(path string) { + log.Println("Loading config at", path) + cfg := &Config{ + WikiName: "MycorrhizaWiki", + NaviTitleIcon: "🍄", + Hyphae: Hyphae{ + HomeHypha: "home", + UserHypha: "u", + HeaderLinksHypha: "", + }, + Network: Network{ + HTTPPort: 1737, + URL: "", + GeminiCertificatePath: "", + }, + Authorization: Authorization{ + UseFixedAuth: false, + FixedAuthCredentialsPath: "", + }, + } + err := ini.MapTo(cfg, path) + if err != nil { + log.Fatal(err) + } + + SiteName = cfg.WikiName + SiteNavIcon = cfg.NaviTitleIcon + HomePage = cfg.HomeHypha + UserHypha = cfg.UserHypha + HeaderLinksHypha = cfg.HeaderLinksHypha + ServerPort = strconv.FormatUint(cfg.HTTPPort, 10) + URL = cfg.URL + GeminiCertPath = cfg.GeminiCertificatePath + UseFixedAuth = cfg.UseFixedAuth + FixedCredentialsPath = cfg.FixedAuthCredentialsPath +} diff --git a/util/util.go b/util/util.go index 4dbae26..1c42d40 100644 --- a/util/util.go +++ b/util/util.go @@ -9,18 +9,24 @@ import ( "unicode" ) +// TODO: make names match to fields of config file var ( - URL string - ServerPort string - HomePage string - SiteNavIcon string - SiteName string - WikiDir string - UserHypha string - HeaderLinksHypha string - AuthMethod string + SiteName string + SiteNavIcon string + + HomePage string + UserHypha string + HeaderLinksHypha string + + ServerPort string + URL string + GeminiCertPath string + + UseFixedAuth bool FixedCredentialsPath string - GeminiCertPath string + + WikiDir string + ConfigFilePath string ) // LettersNumbersOnly keeps letters and numbers only in the given string. diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go index 7780726..e5c2dda 100644 --- a/views/stuff.qtpl.go +++ b/views/stuff.qtpl.go @@ -352,7 +352,7 @@ func StreamAboutHTML(qw422016 *qt422016.Writer) { //line views/stuff.qtpl:98 qw422016.N().S(`