mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-07 18:30:26 +00:00
Do nothing in particular
This commit is contained in:
parent
171e9e2bac
commit
b4dd2dcfad
@ -1,9 +1,9 @@
|
|||||||
|
// Package history provides a git wrapper.
|
||||||
package history
|
package history
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
||||||
"html"
|
"html"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -12,6 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,10 +22,10 @@ var gitpath string
|
|||||||
var renameMsgPattern = regexp.MustCompile(`^Rename ‘(.*)’ to ‘.*’`)
|
var renameMsgPattern = regexp.MustCompile(`^Rename ‘(.*)’ to ‘.*’`)
|
||||||
|
|
||||||
// Start finds git and initializes git credentials.
|
// Start finds git and initializes git credentials.
|
||||||
func Start(wikiDir string) {
|
func Start() {
|
||||||
path, err := exec.LookPath("git")
|
path, err := exec.LookPath("git")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Cound not find the git executable. Check your $PATH.")
|
log.Fatal("Could not find the git executable. Check your $PATH.")
|
||||||
}
|
}
|
||||||
gitpath = path
|
gitpath = path
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// information.go
|
|
||||||
// Things related to gathering existing information.
|
|
||||||
package history
|
package history
|
||||||
|
|
||||||
|
// information.go
|
||||||
|
// Things related to gathering existing information.
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
@ -174,13 +174,20 @@ func parseRevisionLine(line string) Revision {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See how the file with `filepath` looked at commit with `hash`.
|
// FileAtRevision shows how the file with the given file path looked at the commit with the hash. It may return an error if git fails.
|
||||||
func FileAtRevision(filepath, hash string) (string, error) {
|
func FileAtRevision(filepath, hash string) (string, error) {
|
||||||
out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/"))
|
out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/"))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
return out.String(), err
|
return out.String(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrimitiveDiffAtRevision generates a plain-text diff for the given filepath at the commit with the given hash. It may return an error if git fails.
|
||||||
func PrimitiveDiffAtRevision(filepath, hash string) (string, error) {
|
func PrimitiveDiffAtRevision(filepath, hash string) (string, error) {
|
||||||
out, err := silentGitsh("diff", "--unified=1", "--no-color", hash+"~", hash, "--", filepath)
|
out, err := silentGitsh("diff", "--unified=1", "--no-color", hash+"~", hash, "--", filepath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
return out.String(), err
|
return out.String(), err
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// history/operations.go
|
|
||||||
// Things related to writing history.
|
|
||||||
package history
|
package history
|
||||||
|
|
||||||
|
// history/operations.go
|
||||||
|
// Things related to writing history.
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -84,7 +84,10 @@ func (hop *HistoryOp) WithFilesRemoved(paths ...string) *HistoryOp {
|
|||||||
func (hop *HistoryOp) WithFilesRenamed(pairs map[string]string) *HistoryOp {
|
func (hop *HistoryOp) WithFilesRenamed(pairs map[string]string) *HistoryOp {
|
||||||
for from, to := range pairs {
|
for from, to := range pairs {
|
||||||
if from != "" {
|
if from != "" {
|
||||||
os.MkdirAll(filepath.Dir(to), 0777)
|
if err := os.MkdirAll(filepath.Dir(to), 0777); err != nil {
|
||||||
|
hop.Errs = append(hop.Errs, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := Rename(from, to); err != nil {
|
if err := Rename(from, to); err != nil {
|
||||||
hop.Errs = append(hop.Errs, err)
|
hop.Errs = append(hop.Errs, err)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// The `hyphae` package is for the Hypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util.
|
// Package hyphae is for the Hypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util.
|
||||||
package hyphae
|
package hyphae
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// HyphaPattern is a pattern which all hyphae must match.
|
// HyphaPattern is a pattern which all hyphae must match.
|
||||||
var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"\'&%{}]+`)
|
var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"'&%{}]+`)
|
||||||
|
|
||||||
type Hypha struct {
|
type Hypha struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
2
main.go
2
main.go
@ -37,7 +37,7 @@ func main() {
|
|||||||
// Init the subsystems:
|
// Init the subsystems:
|
||||||
hyphae.Index(cfg.WikiDir)
|
hyphae.Index(cfg.WikiDir)
|
||||||
user.InitUserDatabase()
|
user.InitUserDatabase()
|
||||||
history.Start(cfg.WikiDir)
|
history.Start()
|
||||||
shroom.SetHeaderLinks()
|
shroom.SetHeaderLinks()
|
||||||
|
|
||||||
// Network:
|
// Network:
|
||||||
|
@ -3,7 +3,6 @@ package markup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ func (md *MycoDoc) Lex(recursionLevel int) *MycoDoc {
|
|||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsHtml returns an html representation of the document
|
// AsHTML returns an html representation of the document
|
||||||
func (md *MycoDoc) AsHTML() string {
|
func (md *MycoDoc) AsHTML() string {
|
||||||
md.html = Parse(md.Lex(0).ast, 0, 0, 0)
|
md.html = Parse(md.Lex(0).ast, 0, 0, 0)
|
||||||
return md.html
|
return md.html
|
||||||
@ -97,76 +96,3 @@ func (md *MycoDoc) ogFillVars() *MycoDoc {
|
|||||||
func ogTag(property, content string) string {
|
func ogTag(property, content string) string {
|
||||||
return fmt.Sprintf(`<meta property="og:%s" content="%s"/>`, property, content)
|
return fmt.Sprintf(`<meta property="og:%s" content="%s"/>`, property, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The rest of this file is currently unused. TODO: use it I guess */
|
|
||||||
|
|
||||||
type BlockType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
BlockH1 = iota
|
|
||||||
BlockH2
|
|
||||||
BlockH3
|
|
||||||
BlockH4
|
|
||||||
BlockH5
|
|
||||||
BlockH6
|
|
||||||
BlockRocket
|
|
||||||
BlockPre
|
|
||||||
BlockQuote
|
|
||||||
BlockPara
|
|
||||||
)
|
|
||||||
|
|
||||||
type CrawlWhere int
|
|
||||||
|
|
||||||
const (
|
|
||||||
inSomewhere = iota
|
|
||||||
inPre
|
|
||||||
inEnd
|
|
||||||
)
|
|
||||||
|
|
||||||
func crawl(name, content string) []string {
|
|
||||||
stateStack := []CrawlWhere{inSomewhere}
|
|
||||||
|
|
||||||
startsWith := func(token string) bool {
|
|
||||||
return strings.HasPrefix(content, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
pop := func() {
|
|
||||||
stateStack = stateStack[:len(stateStack)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
push := func(s CrawlWhere) {
|
|
||||||
stateStack = append(stateStack, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
readln := func(c string) (string, string) {
|
|
||||||
parts := strings.SplitN(c, "\n", 1)
|
|
||||||
return parts[0], parts[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
preAcc := ""
|
|
||||||
line := ""
|
|
||||||
|
|
||||||
for {
|
|
||||||
switch stateStack[0] {
|
|
||||||
case inSomewhere:
|
|
||||||
switch {
|
|
||||||
case startsWith("```"):
|
|
||||||
push(inPre)
|
|
||||||
_, content = readln(content)
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
case inPre:
|
|
||||||
switch {
|
|
||||||
case startsWith("```"):
|
|
||||||
pop()
|
|
||||||
_, content = readln(content)
|
|
||||||
default:
|
|
||||||
line, content = readln(content)
|
|
||||||
preAcc += html.EscapeString(line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
|
@ -10,14 +10,3 @@ func remover(prefix string) func(string) string {
|
|||||||
return strings.TrimSpace(strings.TrimPrefix(l, prefix))
|
return strings.TrimSpace(strings.TrimPrefix(l, prefix))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove #, ## or ### from beginning of `line`.
|
|
||||||
func removeHeadingOctothorps(line string) string {
|
|
||||||
f := remover("#")
|
|
||||||
return f(f(f(line)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a canonical representation of a hypha `name`.
|
|
||||||
func canonicalName(name string) string {
|
|
||||||
return strings.ToLower(strings.ReplaceAll(strings.TrimSpace(name), " ", "_"))
|
|
||||||
}
|
|
||||||
|
@ -2,6 +2,7 @@ package markup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -67,11 +68,11 @@ func parseTransclusion(line, hyphaName string) (xclusion Transclusion) {
|
|||||||
func xclCanonicalName(hyphaName, xclName string) string {
|
func xclCanonicalName(hyphaName, xclName string) string {
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(xclName, "./"):
|
case strings.HasPrefix(xclName, "./"):
|
||||||
return canonicalName(path.Join(hyphaName, strings.TrimPrefix(xclName, "./")))
|
return util.CanonicalName(path.Join(hyphaName, strings.TrimPrefix(xclName, "./")))
|
||||||
case strings.HasPrefix(xclName, "../"):
|
case strings.HasPrefix(xclName, "../"):
|
||||||
return canonicalName(path.Join(path.Dir(hyphaName), strings.TrimPrefix(xclName, "../")))
|
return util.CanonicalName(path.Join(path.Dir(hyphaName), strings.TrimPrefix(xclName, "../")))
|
||||||
default:
|
default:
|
||||||
return canonicalName(xclName)
|
return util.CanonicalName(xclName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,6 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bouncepaw/mycorrhiza/assets"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -16,7 +13,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/assets"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
"github.com/bouncepaw/mycorrhiza/views"
|
"github.com/bouncepaw/mycorrhiza/views"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user