1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-07-14 07:02:48 +00:00

Make navi-title better

This commit is contained in:
bouncepaw 2021-01-10 16:58:02 +05:00
parent b1f33c872c
commit d19adf6729
4 changed files with 17 additions and 6 deletions

15
name.go
View File

@ -23,16 +23,19 @@ func CanonicalName(name string) string {
func naviTitle(canonicalName string) string { func naviTitle(canonicalName string) string {
var ( var (
html = fmt.Sprintf(`<h1 class="navi-title" id="navi-title"> html = fmt.Sprintf(`<h1 class="navi-title" id="navi-title">
<a href="/page/%s">%s</a>`, util.HomePage, util.SiteTitle) <a href="/page/%s">%s</a><span aria-hidden="true" class="navi-title__colon">:&nbsp;</span>`, util.HomePage, util.SiteTitle)
prevAcc = `/page/` prevAcc = `/page/`
parts = strings.Split(canonicalName, "/") parts = strings.Split(canonicalName, "/")
) )
for _, part := range parts { for i, part := range parts {
html += fmt.Sprintf(` if i > 0 {
<span aria-hidden="true">/</span> html += `<span aria-hidden="true" class="navi-title__separator">/</span>`
<a href="%s">%s</a>`, }
html += fmt.Sprintf(
`<a href="%s">%s</a>`,
prevAcc+part, prevAcc+part,
strings.Title(part)) util.BeautifulName(part),
)
prevAcc += part + "/" prevAcc += part + "/"
} }
return html + "</h1>" return html + "</h1>"

View File

@ -63,6 +63,7 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr
.binary-container_with-video video, .binary-container_with-video video,
.binary-container_with-audio audio {width: 100%} .binary-container_with-audio audio {width: 100%}
.navi-title a {text-decoration:none;} .navi-title a {text-decoration:none;}
.navi-title__separator { margin: 0 .25rem; }
.img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; } .img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; }
.img-gallery_many-images { background-color: #eee; border-radius: .25rem; padding: .5rem; } .img-gallery_many-images { background-color: #eee; border-radius: .25rem; padding: .5rem; }
.img-gallery img { max-width: 100%; max-height: 50vh; } .img-gallery img { max-width: 100%; max-height: 50vh; }

View File

@ -38,6 +38,7 @@ article pre.codeblock {background-color:#eee; padding:.5rem; white-space: pre-wr
.binary-container_with-video video, .binary-container_with-video video,
.binary-container_with-audio audio {width: 100%} .binary-container_with-audio audio {width: 100%}
.navi-title a {text-decoration:none;} .navi-title a {text-decoration:none;}
.navi-title__separator { margin: 0 .25rem; }
.img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; } .img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; }
.img-gallery_many-images { background-color: #eee; border-radius: .25rem; padding: .5rem; } .img-gallery_many-images { background-color: #eee; border-radius: .25rem; padding: .5rem; }
.img-gallery img { max-width: 100%; max-height: 50vh; } .img-gallery img { max-width: 100%; max-height: 50vh; }

View File

@ -4,6 +4,7 @@ import (
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"net/http" "net/http"
"path"
"strings" "strings"
) )
@ -55,3 +56,8 @@ func RandomString(n int) (string, error) {
} }
return hex.EncodeToString(bytes), nil return hex.EncodeToString(bytes), nil
} }
// Strip hypha name from all ancestor names, replace _ with spaces, title case
func BeautifulName(uglyName string) string {
return strings.Title(strings.ReplaceAll(path.Base(uglyName), "_", " "))
}