diff --git a/main.go b/main.go index 1215861..d368bb0 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,14 @@ package main import ( "fmt" + "io/ioutil" "log" "math/rand" "net/http" "os" "path/filepath" "regexp" + "strings" "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/templates" @@ -99,6 +101,33 @@ func handlerStyle(w http.ResponseWriter, rq *http.Request) { } } +func handlerIcon(w http.ResponseWriter, rq *http.Request) { + iconName := strings.TrimPrefix(rq.URL.Path, "/static/icon/") + if iconName == "https" { + iconName = "http" + } + files, err := ioutil.ReadDir(WikiDir + "/static/icon") + if err == nil { + for _, f := range files { + if strings.HasPrefix(f.Name(), iconName+"-protocol-icon") { + http.ServeFile(w, rq, WikiDir+"/static/icon/"+f.Name()) + return + } + } + } + w.Header().Set("Content-Type", "image/svg+xml") + switch iconName { + case "gemini": + w.Write([]byte(templates.IconGemini())) + case "mailto": + w.Write([]byte(templates.IconMailto())) + case "gopher": + w.Write([]byte(templates.IconGopher())) + default: + w.Write([]byte(templates.IconHTTP())) + } +} + func main() { log.Println("Running MycorrhizaWiki β") parseCliArgs() @@ -124,6 +153,7 @@ func main() { http.ServeFile(w, rq, WikiDir+"/static/favicon.ico") }) http.HandleFunc("/static/common.css", handlerStyle) + http.HandleFunc("/static/icon/", handlerIcon) http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) { http.Redirect(w, rq, "/page/"+util.HomePage, http.StatusSeeOther) }) diff --git a/markup/lexer.go b/markup/lexer.go index 08476d6..9ff58f5 100644 --- a/markup/lexer.go +++ b/markup/lexer.go @@ -59,6 +59,9 @@ func geminiLineToAST(line string, state *GemLexerState, ast *[]Line) { addLine(state.buf + "") case "pre": state.buf += "\n" + case "launchpad": + state.where = "" + addLine(state.buf + "") } return } @@ -80,6 +83,8 @@ func geminiLineToAST(line string, state *GemLexerState, ast *[]Line) { goto listState case "number": goto numberState + case "launchpad": + goto launchpadState default: goto normalState } @@ -135,6 +140,23 @@ numberState: } return +launchpadState: + switch { + case startsWith("=>"): + href, text, class := Rocketlink(line, state.name) + state.buf += fmt.Sprintf(`
  • %s
  • `, class, href, text) + case startsWith("```"): + state.where = "pre" + addLine(state.buf + "") + state.id++ + state.buf = fmt.Sprintf("
    ", state.id, strings.TrimPrefix(line, "```"))
    +	default:
    +		state.where = ""
    +		addLine(state.buf + "")
    +		goto normalState
    +	}
    +	return
    +
     normalState:
     	state.id++
     	switch {
    @@ -168,9 +190,9 @@ normalState:
     		addLine(fmt.Sprintf(
     			"
    %s
    ", state.id, remover(">")(line))) case startsWith("=>"): - href, text, class := Rocketlink(line, state.name) - addLine(fmt.Sprintf( - `

    %s

    `, state.id, class, href, text)) + state.where = "launchpad" + state.buf = fmt.Sprintf("