1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Improve links visually

This commit is contained in:
bouncepaw 2020-12-15 23:59:36 +05:00
parent 37eb3d1c77
commit 8ac27fc385
11 changed files with 287 additions and 12 deletions

30
main.go
View File

@ -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)
})

View File

@ -59,6 +59,9 @@ func geminiLineToAST(line string, state *GemLexerState, ast *[]Line) {
addLine(state.buf + "</ol>")
case "pre":
state.buf += "\n"
case "launchpad":
state.where = ""
addLine(state.buf + "</ul>")
}
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(` <li class="launchpad__entry"><a class="rocketlink %s" href="%s">%s</a></li>`, class, href, text)
case startsWith("```"):
state.where = "pre"
addLine(state.buf + "</ul>")
state.id++
state.buf = fmt.Sprintf("<pre id='%d' alt='%s' class='codeblock'><code>", state.id, strings.TrimPrefix(line, "```"))
default:
state.where = ""
addLine(state.buf + "</ul>")
goto normalState
}
return
normalState:
state.id++
switch {
@ -168,9 +190,9 @@ normalState:
addLine(fmt.Sprintf(
"<blockquote id='%d'>%s</blockquote>", state.id, remover(">")(line)))
case startsWith("=>"):
href, text, class := Rocketlink(line, state.name)
addLine(fmt.Sprintf(
`<p><a id='%d' class='rocketlink %s' href="%s">%s</a></p>`, state.id, class, href, text))
state.where = "launchpad"
state.buf = fmt.Sprintf("<ul class='launchpad' id='%d'>\n", state.id)
goto launchpadState
case startsWith("<="):
addLine(parseTransclusion(line, state.name))

View File

@ -1,6 +1,7 @@
package markup
import (
"fmt"
"path"
"strings"
)
@ -19,7 +20,13 @@ func LinkParts(addr, display, hyphaName string) (href, text, class string) {
switch {
case strings.ContainsRune(addr, ':'):
return addr, text, "wikilink_external"
pos := strings.IndexRune(addr, ':')
destination := addr[:pos]
text = addr[pos+1:]
if strings.HasPrefix(text, "//") && len(text) > 2 {
text = text[2:]
}
return addr, text + fmt.Sprintf(`<img class="wikilink__destination-type" src="/static/icon/%s" width="16" height="16"/>`, destination), "wikilink_external"
case strings.HasPrefix(addr, "/"):
return addr, text, class
case strings.HasPrefix(addr, "./"):

View File

@ -11,11 +11,6 @@ type MycoDoc struct {
// data
hyphaName string
contents string
// state
recursionDepth int
// results
}
// Constructor
@ -27,10 +22,17 @@ func Doc(hyphaName, contents string) *MycoDoc {
}
// AsHtml returns an html representation of the document
func (md *MycoDoc) AsHtml() string {
func (md *MycoDoc) AsHTML() string {
return ""
}
// OpenGraphHTML returns an html representation of og: meta tags.
func (md *MycoDoc) OpenGraphHTML() string {
return ""
}
/* The rest of this file is currently unused. TODO: use it I guess */
type BlockType int
const (

View File

@ -1,3 +1,21 @@
{% func DefaultCSS() %}
{% cat "default.css" %}
{% endfunc %}
Next three are from https://remixicon.com/
{% func IconHTTP() %}
{% cat "icon/http-protocol-icon.svg" %}
{% endfunc %}
{% func IconGemini() %}
{% cat "icon/gemini-protocol-icon.svg" %}
{% endfunc %}
{% func IconMailto() %}
{% cat "icon/mailto-protocol-icon.svg" %}
{% endfunc %}
This is a modified version of https://www.svgrepo.com/svg/232085/rat
{% func IconGopher() %}
{% cat "icon/gopher-protocol-icon.svg" %}
{% endfunc %}

View File

@ -45,7 +45,8 @@ main h1:not(.navi-title) {font-size:1.7rem;}
blockquote {border-left: 4px black solid; margin-left: 0; padding-left: 1rem;}
.wikilink_new {color:#a55858;}
.wikilink_new:visited {color:#a55858;}
.wikilink_external::after {content:"🌐"; margin-left: .5rem; font-size: small; text-decoration: none; align: bottom;}
.wikilink__destination-type {display: inline; margin-left: .5rem; vertical-align: sub; }
article code {background-color:#eee; padding: .1rem .3rem; border-radius: .25rem; font-size: 90%; }
article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wrap; border-radius: .25rem;}
.codeblock code {padding:0; font-size:15px;}
@ -55,6 +56,9 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr
.transclusion__link {display: block; text-align: right; font-style: italic; margin-top: .5rem; margin-right: .25rem; color: black; text-decoration: none;}
.transclusion__link::before {content: "⇐ ";}
.launchpad { position: relative; list-style: none; }
.launchpad li::before { content: '⇒'; position: absolute; left: 0; }
.binary-container_with-img img,
.binary-container_with-video video,
.binary-container_with-audio audio {width: 100%}
@ -121,3 +125,177 @@ func DefaultCSS() string {
return qs422016
//line templates/asset.qtpl:3
}
// Next three are from https://remixicon.com/
//line templates/asset.qtpl:6
func StreamIconHTTP(qw422016 *qt422016.Writer) {
//line templates/asset.qtpl:6
qw422016.N().S(`
`)
//line templates/asset.qtpl:7
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-2.29-2.333A17.9 17.9 0 0 1 8.027 13H4.062a8.008 8.008 0 0 0 5.648 6.667zM10.03 13c.151 2.439.848 4.73 1.97 6.752A15.905 15.905 0 0 0 13.97 13h-3.94zm9.908 0h-3.965a17.9 17.9 0 0 1-1.683 6.667A8.008 8.008 0 0 0 19.938 13zM4.062 11h3.965A17.9 17.9 0 0 1 9.71 4.333 8.008 8.008 0 0 0 4.062 11zm5.969 0h3.938A15.905 15.905 0 0 0 12 4.248 15.905 15.905 0 0 0 10.03 11zm4.259-6.667A17.9 17.9 0 0 1 15.973 11h3.965a8.008 8.008 0 0 0-5.648-6.667z"/></svg>
`)
//line templates/asset.qtpl:7
qw422016.N().S(`
`)
//line templates/asset.qtpl:8
}
//line templates/asset.qtpl:8
func WriteIconHTTP(qq422016 qtio422016.Writer) {
//line templates/asset.qtpl:8
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/asset.qtpl:8
StreamIconHTTP(qw422016)
//line templates/asset.qtpl:8
qt422016.ReleaseWriter(qw422016)
//line templates/asset.qtpl:8
}
//line templates/asset.qtpl:8
func IconHTTP() string {
//line templates/asset.qtpl:8
qb422016 := qt422016.AcquireByteBuffer()
//line templates/asset.qtpl:8
WriteIconHTTP(qb422016)
//line templates/asset.qtpl:8
qs422016 := string(qb422016.B)
//line templates/asset.qtpl:8
qt422016.ReleaseByteBuffer(qb422016)
//line templates/asset.qtpl:8
return qs422016
//line templates/asset.qtpl:8
}
//line templates/asset.qtpl:10
func StreamIconGemini(qw422016 *qt422016.Writer) {
//line templates/asset.qtpl:10
qw422016.N().S(`
`)
//line templates/asset.qtpl:11
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M15.502 20A6.523 6.523 0 0 1 12 23.502 6.523 6.523 0 0 1 8.498 20h2.26c.326.489.747.912 1.242 1.243.495-.33.916-.754 1.243-1.243h2.259zM18 14.805l2 2.268V19H4v-1.927l2-2.268V9c0-3.483 2.504-6.447 6-7.545C15.496 2.553 18 5.517 18 9v5.805zM17.27 17L16 15.56V9c0-2.318-1.57-4.43-4-5.42C9.57 4.57 8 6.681 8 9v6.56L6.73 17h10.54zM12 11a2 2 0 1 1 0-4 2 2 0 0 1 0 4z"/></svg>
`)
//line templates/asset.qtpl:11
qw422016.N().S(`
`)
//line templates/asset.qtpl:12
}
//line templates/asset.qtpl:12
func WriteIconGemini(qq422016 qtio422016.Writer) {
//line templates/asset.qtpl:12
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/asset.qtpl:12
StreamIconGemini(qw422016)
//line templates/asset.qtpl:12
qt422016.ReleaseWriter(qw422016)
//line templates/asset.qtpl:12
}
//line templates/asset.qtpl:12
func IconGemini() string {
//line templates/asset.qtpl:12
qb422016 := qt422016.AcquireByteBuffer()
//line templates/asset.qtpl:12
WriteIconGemini(qb422016)
//line templates/asset.qtpl:12
qs422016 := string(qb422016.B)
//line templates/asset.qtpl:12
qt422016.ReleaseByteBuffer(qb422016)
//line templates/asset.qtpl:12
return qs422016
//line templates/asset.qtpl:12
}
//line templates/asset.qtpl:14
func StreamIconMailto(qw422016 *qt422016.Writer) {
//line templates/asset.qtpl:14
qw422016.N().S(`
`)
//line templates/asset.qtpl:15
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 3h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zm17 4.238l-7.928 7.1L4 7.216V19h16V7.238zM4.511 5l7.55 6.662L19.502 5H4.511z"/></svg>
`)
//line templates/asset.qtpl:15
qw422016.N().S(`
`)
//line templates/asset.qtpl:16
}
//line templates/asset.qtpl:16
func WriteIconMailto(qq422016 qtio422016.Writer) {
//line templates/asset.qtpl:16
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/asset.qtpl:16
StreamIconMailto(qw422016)
//line templates/asset.qtpl:16
qt422016.ReleaseWriter(qw422016)
//line templates/asset.qtpl:16
}
//line templates/asset.qtpl:16
func IconMailto() string {
//line templates/asset.qtpl:16
qb422016 := qt422016.AcquireByteBuffer()
//line templates/asset.qtpl:16
WriteIconMailto(qb422016)
//line templates/asset.qtpl:16
qs422016 := string(qb422016.B)
//line templates/asset.qtpl:16
qt422016.ReleaseByteBuffer(qb422016)
//line templates/asset.qtpl:16
return qs422016
//line templates/asset.qtpl:16
}
// This is a modified version of https://www.svgrepo.com/svg/232085/rat
//line templates/asset.qtpl:19
func StreamIconGopher(qw422016 *qt422016.Writer) {
//line templates/asset.qtpl:19
qw422016.N().S(`
`)
//line templates/asset.qtpl:20
qw422016.N().S(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="24" height="24">
<path d="M447.238,204.944v-70.459c0-8.836-7.164-16-16-16c-34.051,0-64.414,21.118-75.079,55.286
C226.094,41.594,0,133.882,0,319.435c0,0.071,0.01,0.14,0.011,0.21c0.116,44.591,36.423,80.833,81.04,80.833h171.203
c8.836,0,16-7.164,16-16c0-8.836-7.164-16-16-16H81.051c-21.441,0-39.7-13.836-46.351-33.044H496c8.836,0,16-7.164,16-16
C512,271.82,486.82,228.692,447.238,204.944z M415.238,153.216v37.805c-10.318-2.946-19.556-4.305-29.342-4.937
C390.355,168.611,402.006,157.881,415.238,153.216z M295.484,303.435L295.484,303.435c-7.562-41.495-43.948-73.062-87.593-73.062
c-8.836,0-16,7.164-16,16c0,8.836,7.164,16,16,16c25.909,0,47.826,17.364,54.76,41.062H32.722
c14.415-159.15,218.064-217.856,315.136-90.512c3.545,4.649,9.345,6.995,15.124,6.118
c55.425-8.382,107.014,29.269,115.759,84.394H295.484z"/>
<circle cx="415.238" cy="260.05" r="21.166"/>
</svg>
`)
//line templates/asset.qtpl:20
qw422016.N().S(`
`)
//line templates/asset.qtpl:21
}
//line templates/asset.qtpl:21
func WriteIconGopher(qq422016 qtio422016.Writer) {
//line templates/asset.qtpl:21
qw422016 := qt422016.AcquireWriter(qq422016)
//line templates/asset.qtpl:21
StreamIconGopher(qw422016)
//line templates/asset.qtpl:21
qt422016.ReleaseWriter(qw422016)
//line templates/asset.qtpl:21
}
//line templates/asset.qtpl:21
func IconGopher() string {
//line templates/asset.qtpl:21
qb422016 := qt422016.AcquireByteBuffer()
//line templates/asset.qtpl:21
WriteIconGopher(qb422016)
//line templates/asset.qtpl:21
qs422016 := string(qb422016.B)
//line templates/asset.qtpl:21
qt422016.ReleaseByteBuffer(qb422016)
//line templates/asset.qtpl:21
return qs422016
//line templates/asset.qtpl:21
}

View File

@ -20,7 +20,8 @@ main h1:not(.navi-title) {font-size:1.7rem;}
blockquote {border-left: 4px black solid; margin-left: 0; padding-left: 1rem;}
.wikilink_new {color:#a55858;}
.wikilink_new:visited {color:#a55858;}
.wikilink_external::after {content:"🌐"; margin-left: .5rem; font-size: small; text-decoration: none; align: bottom;}
.wikilink__destination-type {display: inline; margin-left: .5rem; vertical-align: sub; }
article code {background-color:#eee; padding: .1rem .3rem; border-radius: .25rem; font-size: 90%; }
article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wrap; border-radius: .25rem;}
.codeblock code {padding:0; font-size:15px;}
@ -30,6 +31,9 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr
.transclusion__link {display: block; text-align: right; font-style: italic; margin-top: .5rem; margin-right: .25rem; color: black; text-decoration: none;}
.transclusion__link::before {content: "⇐ ";}
.launchpad { position: relative; list-style: none; }
.launchpad li::before { content: '⇒'; position: absolute; left: 0; }
.binary-container_with-img img,
.binary-container_with-video video,
.binary-container_with-audio audio {width: 100%}

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M15.502 20A6.523 6.523 0 0 1 12 23.502 6.523 6.523 0 0 1 8.498 20h2.26c.326.489.747.912 1.242 1.243.495-.33.916-.754 1.243-1.243h2.259zM18 14.805l2 2.268V19H4v-1.927l2-2.268V9c0-3.483 2.504-6.447 6-7.545C15.496 2.553 18 5.517 18 9v5.805zM17.27 17L16 15.56V9c0-2.318-1.57-4.43-4-5.42C9.57 4.57 8 6.681 8 9v6.56L6.73 17h10.54zM12 11a2 2 0 1 1 0-4 2 2 0 0 1 0 4z"/></svg>

After

Width:  |  Height:  |  Size: 498 B

View File

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="24" height="24">
<path d="M447.238,204.944v-70.459c0-8.836-7.164-16-16-16c-34.051,0-64.414,21.118-75.079,55.286
C226.094,41.594,0,133.882,0,319.435c0,0.071,0.01,0.14,0.011,0.21c0.116,44.591,36.423,80.833,81.04,80.833h171.203
c8.836,0,16-7.164,16-16c0-8.836-7.164-16-16-16H81.051c-21.441,0-39.7-13.836-46.351-33.044H496c8.836,0,16-7.164,16-16
C512,271.82,486.82,228.692,447.238,204.944z M415.238,153.216v37.805c-10.318-2.946-19.556-4.305-29.342-4.937
C390.355,168.611,402.006,157.881,415.238,153.216z M295.484,303.435L295.484,303.435c-7.562-41.495-43.948-73.062-87.593-73.062
c-8.836,0-16,7.164-16,16c0,8.836,7.164,16,16,16c25.909,0,47.826,17.364,54.76,41.062H32.722
c14.415-159.15,218.064-217.856,315.136-90.512c3.545,4.649,9.345,6.995,15.124,6.118
c55.425-8.382,107.014,29.269,115.759,84.394H295.484z"/>
<circle cx="415.238" cy="260.05" r="21.166"/>
</svg>

After

Width:  |  Height:  |  Size: 927 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-2.29-2.333A17.9 17.9 0 0 1 8.027 13H4.062a8.008 8.008 0 0 0 5.648 6.667zM10.03 13c.151 2.439.848 4.73 1.97 6.752A15.905 15.905 0 0 0 13.97 13h-3.94zm9.908 0h-3.965a17.9 17.9 0 0 1-1.683 6.667A8.008 8.008 0 0 0 19.938 13zM4.062 11h3.965A17.9 17.9 0 0 1 9.71 4.333 8.008 8.008 0 0 0 4.062 11zm5.969 0h3.938A15.905 15.905 0 0 0 12 4.248 15.905 15.905 0 0 0 10.03 11zm4.259-6.667A17.9 17.9 0 0 1 15.973 11h3.965a8.008 8.008 0 0 0-5.648-6.667z"/></svg>

After

Width:  |  Height:  |  Size: 652 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 3h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1zm17 4.238l-7.928 7.1L4 7.216V19h16V7.238zM4.511 5l7.55 6.662L19.502 5H4.511z"/></svg>

After

Width:  |  Height:  |  Size: 286 B