diff --git a/Makefile b/Makefile
index 51525fe..c48dc4f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,6 @@
run: build
./mycorrhiza metarrhiza
-auth_run: build
- ./mycorrhiza -auth-method fixed metarrhiza
-
-gemini_run: build
- ./mycorrhiza -gemini-cert-path "." metarrhiza
-
config_run: build
./mycorrhiza -config-path "assets/config.ini" metarrhiza
diff --git a/assets/assets.qtpl b/assets/assets.qtpl
index 2e6b4f2..a3a56f6 100644
--- a/assets/assets.qtpl
+++ b/assets/assets.qtpl
@@ -1,3 +1,11 @@
+{%- func HelpMessage() -%}
+Usage of %s:
+{%- endfunc -%}
+
+{%- func ExampleConfig() -%}
+{% cat "config.ini" %}
+{%- endfunc -%}
+
{% func DefaultCSS() %}
{% cat "default.css" %}
{% endfunc %}
diff --git a/assets/assets.qtpl.go b/assets/assets.qtpl.go
index 94343bd..00ad405 100644
--- a/assets/assets.qtpl.go
+++ b/assets/assets.qtpl.go
@@ -18,11 +18,97 @@ var (
)
//line assets/assets.qtpl:1
-func StreamDefaultCSS(qw422016 *qt422016.Writer) {
+func StreamHelpMessage(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:1
+ qw422016.N().S(`Usage of %s:
+`)
+//line assets/assets.qtpl:3
+}
+
+//line assets/assets.qtpl:3
+func WriteHelpMessage(qq422016 qtio422016.Writer) {
+//line assets/assets.qtpl:3
+ qw422016 := qt422016.AcquireWriter(qq422016)
+//line assets/assets.qtpl:3
+ StreamHelpMessage(qw422016)
+//line assets/assets.qtpl:3
+ qt422016.ReleaseWriter(qw422016)
+//line assets/assets.qtpl:3
+}
+
+//line assets/assets.qtpl:3
+func HelpMessage() string {
+//line assets/assets.qtpl:3
+ qb422016 := qt422016.AcquireByteBuffer()
+//line assets/assets.qtpl:3
+ WriteHelpMessage(qb422016)
+//line assets/assets.qtpl:3
+ qs422016 := string(qb422016.B)
+//line assets/assets.qtpl:3
+ qt422016.ReleaseByteBuffer(qb422016)
+//line assets/assets.qtpl:3
+ return qs422016
+//line assets/assets.qtpl:3
+}
+
+//line assets/assets.qtpl:5
+func StreamExampleConfig(qw422016 *qt422016.Writer) {
+//line assets/assets.qtpl:6
+ qw422016.N().S(`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
+`)
+//line assets/assets.qtpl:6
qw422016.N().S(`
`)
-//line assets/assets.qtpl:2
+//line assets/assets.qtpl:7
+}
+
+//line assets/assets.qtpl:7
+func WriteExampleConfig(qq422016 qtio422016.Writer) {
+//line assets/assets.qtpl:7
+ qw422016 := qt422016.AcquireWriter(qq422016)
+//line assets/assets.qtpl:7
+ StreamExampleConfig(qw422016)
+//line assets/assets.qtpl:7
+ qt422016.ReleaseWriter(qw422016)
+//line assets/assets.qtpl:7
+}
+
+//line assets/assets.qtpl:7
+func ExampleConfig() string {
+//line assets/assets.qtpl:7
+ qb422016 := qt422016.AcquireByteBuffer()
+//line assets/assets.qtpl:7
+ WriteExampleConfig(qb422016)
+//line assets/assets.qtpl:7
+ qs422016 := string(qb422016.B)
+//line assets/assets.qtpl:7
+ qt422016.ReleaseByteBuffer(qb422016)
+//line assets/assets.qtpl:7
+ return qs422016
+//line assets/assets.qtpl:7
+}
+
+//line assets/assets.qtpl:9
+func StreamDefaultCSS(qw422016 *qt422016.Writer) {
+//line assets/assets.qtpl:9
+ qw422016.N().S(`
+`)
+//line assets/assets.qtpl:10
qw422016.N().S(`.amnt-grid { display: grid; grid-template-columns: 1fr 1fr; }
.upload-binary__input { display: block; margin: .25rem 0; }
@@ -298,168 +384,168 @@ mark { background: rgba(130, 80, 30, 5); color: inherit; }
.backlinks { display: none; }
`)
-//line assets/assets.qtpl:2
+//line assets/assets.qtpl:10
qw422016.N().S(`
`)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
}
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
func WriteDefaultCSS(qq422016 qtio422016.Writer) {
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
qw422016 := qt422016.AcquireWriter(qq422016)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
StreamDefaultCSS(qw422016)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
qt422016.ReleaseWriter(qw422016)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
}
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
func DefaultCSS() string {
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
qb422016 := qt422016.AcquireByteBuffer()
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
WriteDefaultCSS(qb422016)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
qs422016 := string(qb422016.B)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
qt422016.ReleaseByteBuffer(qb422016)
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
return qs422016
-//line assets/assets.qtpl:3
+//line assets/assets.qtpl:11
}
// Next three are from https://remixicon.com/
-//line assets/assets.qtpl:6
+//line assets/assets.qtpl:14
func StreamIconHTTP(qw422016 *qt422016.Writer) {
-//line assets/assets.qtpl:6
+//line assets/assets.qtpl:14
qw422016.N().S(`
`)
-//line assets/assets.qtpl:7
+//line assets/assets.qtpl:15
qw422016.N().S(`
`)
-//line assets/assets.qtpl:7
+//line assets/assets.qtpl:15
qw422016.N().S(`
`)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
}
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
func WriteIconHTTP(qq422016 qtio422016.Writer) {
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
qw422016 := qt422016.AcquireWriter(qq422016)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
StreamIconHTTP(qw422016)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
qt422016.ReleaseWriter(qw422016)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
}
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
func IconHTTP() string {
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
qb422016 := qt422016.AcquireByteBuffer()
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
WriteIconHTTP(qb422016)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
qs422016 := string(qb422016.B)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
qt422016.ReleaseByteBuffer(qb422016)
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
return qs422016
-//line assets/assets.qtpl:8
+//line assets/assets.qtpl:16
}
-//line assets/assets.qtpl:10
+//line assets/assets.qtpl:18
func StreamIconGemini(qw422016 *qt422016.Writer) {
-//line assets/assets.qtpl:10
+//line assets/assets.qtpl:18
qw422016.N().S(`
`)
-//line assets/assets.qtpl:11
+//line assets/assets.qtpl:19
qw422016.N().S(`
`)
-//line assets/assets.qtpl:11
- qw422016.N().S(`
-`)
-//line assets/assets.qtpl:12
-}
-
-//line assets/assets.qtpl:12
-func WriteIconGemini(qq422016 qtio422016.Writer) {
-//line assets/assets.qtpl:12
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line assets/assets.qtpl:12
- StreamIconGemini(qw422016)
-//line assets/assets.qtpl:12
- qt422016.ReleaseWriter(qw422016)
-//line assets/assets.qtpl:12
-}
-
-//line assets/assets.qtpl:12
-func IconGemini() string {
-//line assets/assets.qtpl:12
- qb422016 := qt422016.AcquireByteBuffer()
-//line assets/assets.qtpl:12
- WriteIconGemini(qb422016)
-//line assets/assets.qtpl:12
- qs422016 := string(qb422016.B)
-//line assets/assets.qtpl:12
- qt422016.ReleaseByteBuffer(qb422016)
-//line assets/assets.qtpl:12
- return qs422016
-//line assets/assets.qtpl:12
-}
-
-//line assets/assets.qtpl:14
-func StreamIconMailto(qw422016 *qt422016.Writer) {
-//line assets/assets.qtpl:14
- qw422016.N().S(`
-`)
-//line assets/assets.qtpl:15
- qw422016.N().S(`
-`)
-//line assets/assets.qtpl:15
- qw422016.N().S(`
-`)
-//line assets/assets.qtpl:16
-}
-
-//line assets/assets.qtpl:16
-func WriteIconMailto(qq422016 qtio422016.Writer) {
-//line assets/assets.qtpl:16
- qw422016 := qt422016.AcquireWriter(qq422016)
-//line assets/assets.qtpl:16
- StreamIconMailto(qw422016)
-//line assets/assets.qtpl:16
- qt422016.ReleaseWriter(qw422016)
-//line assets/assets.qtpl:16
-}
-
-//line assets/assets.qtpl:16
-func IconMailto() string {
-//line assets/assets.qtpl:16
- qb422016 := qt422016.AcquireByteBuffer()
-//line assets/assets.qtpl:16
- WriteIconMailto(qb422016)
-//line assets/assets.qtpl:16
- qs422016 := string(qb422016.B)
-//line assets/assets.qtpl:16
- qt422016.ReleaseByteBuffer(qb422016)
-//line assets/assets.qtpl:16
- return qs422016
-//line assets/assets.qtpl:16
-}
-
-// This is a modified version of https://www.svgrepo.com/svg/232085/rat
-
-//line assets/assets.qtpl:19
-func StreamIconGopher(qw422016 *qt422016.Writer) {
//line assets/assets.qtpl:19
qw422016.N().S(`
`)
//line assets/assets.qtpl:20
+}
+
+//line assets/assets.qtpl:20
+func WriteIconGemini(qq422016 qtio422016.Writer) {
+//line assets/assets.qtpl:20
+ qw422016 := qt422016.AcquireWriter(qq422016)
+//line assets/assets.qtpl:20
+ StreamIconGemini(qw422016)
+//line assets/assets.qtpl:20
+ qt422016.ReleaseWriter(qw422016)
+//line assets/assets.qtpl:20
+}
+
+//line assets/assets.qtpl:20
+func IconGemini() string {
+//line assets/assets.qtpl:20
+ qb422016 := qt422016.AcquireByteBuffer()
+//line assets/assets.qtpl:20
+ WriteIconGemini(qb422016)
+//line assets/assets.qtpl:20
+ qs422016 := string(qb422016.B)
+//line assets/assets.qtpl:20
+ qt422016.ReleaseByteBuffer(qb422016)
+//line assets/assets.qtpl:20
+ return qs422016
+//line assets/assets.qtpl:20
+}
+
+//line assets/assets.qtpl:22
+func StreamIconMailto(qw422016 *qt422016.Writer) {
+//line assets/assets.qtpl:22
+ qw422016.N().S(`
+`)
+//line assets/assets.qtpl:23
+ qw422016.N().S(`
+`)
+//line assets/assets.qtpl:23
+ qw422016.N().S(`
+`)
+//line assets/assets.qtpl:24
+}
+
+//line assets/assets.qtpl:24
+func WriteIconMailto(qq422016 qtio422016.Writer) {
+//line assets/assets.qtpl:24
+ qw422016 := qt422016.AcquireWriter(qq422016)
+//line assets/assets.qtpl:24
+ StreamIconMailto(qw422016)
+//line assets/assets.qtpl:24
+ qt422016.ReleaseWriter(qw422016)
+//line assets/assets.qtpl:24
+}
+
+//line assets/assets.qtpl:24
+func IconMailto() string {
+//line assets/assets.qtpl:24
+ qb422016 := qt422016.AcquireByteBuffer()
+//line assets/assets.qtpl:24
+ WriteIconMailto(qb422016)
+//line assets/assets.qtpl:24
+ qs422016 := string(qb422016.B)
+//line assets/assets.qtpl:24
+ qt422016.ReleaseByteBuffer(qb422016)
+//line assets/assets.qtpl:24
+ return qs422016
+//line assets/assets.qtpl:24
+}
+
+// This is a modified version of https://www.svgrepo.com/svg/232085/rat
+
+//line assets/assets.qtpl:27
+func StreamIconGopher(qw422016 *qt422016.Writer) {
+//line assets/assets.qtpl:27
+ qw422016.N().S(`
+`)
+//line assets/assets.qtpl:28
qw422016.N().S(`
`)
-//line assets/assets.qtpl:20
+//line assets/assets.qtpl:28
qw422016.N().S(`
`)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
}
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
func WriteIconGopher(qq422016 qtio422016.Writer) {
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
qw422016 := qt422016.AcquireWriter(qq422016)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
StreamIconGopher(qw422016)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
qt422016.ReleaseWriter(qw422016)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
}
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
func IconGopher() string {
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
qb422016 := qt422016.AcquireByteBuffer()
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
WriteIconGopher(qb422016)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
qs422016 := string(qb422016.B)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
qt422016.ReleaseByteBuffer(qb422016)
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
return qs422016
-//line assets/assets.qtpl:21
+//line assets/assets.qtpl:29
}
diff --git a/flag.go b/flag.go
index fcc8c22..b3be793 100644
--- a/flag.go
+++ b/flag.go
@@ -2,13 +2,18 @@ package main
import (
"flag"
+ "fmt"
"log"
+ "os"
"path/filepath"
+ "github.com/bouncepaw/mycorrhiza/assets"
"github.com/bouncepaw/mycorrhiza/user"
"github.com/bouncepaw/mycorrhiza/util"
)
+var printExampleConfig bool
+
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")
@@ -21,6 +26,15 @@ func init() {
// 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.")
+ flag.BoolVar(&printExampleConfig, "print-example-config", false, "If true, print an example configuration file contents and exit. You can save the output to a file and base your own configuration on it.")
+ flag.Usage = func() {
+ fmt.Fprintf(
+ flag.CommandLine.Output(),
+ assets.HelpMessage(),
+ os.Args[0],
+ )
+ flag.PrintDefaults()
+ }
}
// Do the things related to cli args and die maybe
@@ -28,13 +42,17 @@ func parseCliArgs() {
flag.Parse()
args := flag.Args()
+ if printExampleConfig {
+ fmt.Printf(assets.ExampleConfig())
+ os.Exit(0)
+ }
+
if len(args) == 0 {
log.Fatal("Error: pass a wiki directory")
}
- if util.ConfigFilePath != "" {
- util.ReadConfigFile(util.ConfigFilePath)
- }
+ // It is ok if the path is ""
+ util.ReadConfigFile(util.ConfigFilePath)
var err error
WikiDir, err = filepath.Abs(args[0])
diff --git a/history/history.go b/history/history.go
index d02e156..a1e897b 100644
--- a/history/history.go
+++ b/history/history.go
@@ -13,11 +13,22 @@ import (
"github.com/bouncepaw/mycorrhiza/util"
)
+// Path to git executable. Set at init()
+var gitpath string
+
var renameMsgPattern = regexp.MustCompile(`^Rename ‘(.*)’ to ‘.*’`)
-// Start initializes git credentials.
+// Start finds git and initializes git credentials.
func Start(wikiDir string) {
- _, err := gitsh("config", "user.name", "wikimind")
+ path, err := exec.LookPath("git")
+ if err != nil {
+ log.Fatal("Cound not find the git executable. Check your $PATH.")
+ } else {
+ log.Println("Git path is", path)
+ }
+ gitpath = path
+
+ _, err = gitsh("config", "user.name", "wikimind")
if err != nil {
log.Fatal(err)
}
@@ -110,20 +121,6 @@ func (rev *Revision) bestLink() string {
}
}
-// Path to git executable. Set at init()
-var gitpath string
-
-func init() {
- path, err := exec.LookPath("git")
- if err != nil {
- log.Fatal("Cound not find the git executable. Check your $PATH.")
- } else {
- log.Println("Git path is", path)
- }
- gitpath = path
-
-}
-
// I pronounce it as [gɪt͡ʃ].
// gitsh is async-safe, therefore all other git-related functions in this module are too.
func gitsh(args ...string) (out bytes.Buffer, err error) {
diff --git a/main.go b/main.go
index 203c59d..2b0987d 100644
--- a/main.go
+++ b/main.go
@@ -168,8 +168,8 @@ Crawl-delay: 5`))
}
func main() {
- log.Println("Running MycorrhizaWiki β")
parseCliArgs()
+ log.Println("Running MycorrhizaWiki β")
if err := os.Chdir(WikiDir); err != nil {
log.Fatal(err)
}
diff --git a/util/config.go b/util/config.go
index be9e4f3..0cf2687 100644
--- a/util/config.go
+++ b/util/config.go
@@ -33,7 +33,6 @@ type Authorization struct {
}
func ReadConfigFile(path string) {
- log.Println("Loading config at", path)
cfg := &Config{
WikiName: "MycorrhizaWiki",
NaviTitleIcon: "🍄",
@@ -52,9 +51,13 @@ func ReadConfigFile(path string) {
FixedAuthCredentialsPath: "",
},
}
- err := ini.MapTo(cfg, path)
- if err != nil {
- log.Fatal(err)
+
+ if path != "" {
+ log.Println("Loading config at", path)
+ err := ini.MapTo(cfg, path)
+ if err != nil {
+ log.Fatal(err)
+ }
}
SiteName = cfg.WikiName