Make header on dirs and files floating fixed

master v1.5
bel 2019-12-07 11:21:47 -07:00
parent f0a1c21678
commit 72894cd5cc
3 changed files with 11 additions and 7 deletions

View File

@ -22,8 +22,8 @@ func h1(content string) string {
return h("1", content)
}
func h2(content string) string {
return h("2", content)
func h2(content string, style ...string) string {
return h("2", content, style...)
}
func h3(content string) string {
@ -38,6 +38,10 @@ func h5(content string) string {
return h("5", content)
}
func h(level, content string) string {
return fmt.Sprintf("\n<h%s>\n%s\n</h%s>\n", level, content, level)
func h(level, content string, style ...string) string {
s := ""
if len(style) > 0 {
s = fmt.Sprintf("style=%q", style[0])
}
return fmt.Sprintf("\n<h%s %s>\n%s\n</h%s>\n", level, s, content, level)
}

View File

@ -39,7 +39,7 @@ func TestBlock(t *testing.T) {
func TestH(t *testing.T) {
s := strings.ReplaceAll(strings.TrimSpace(h2("hi")), "\n", ".")
if ok, err := regexp.MatchString("<h2>.*hi.*<.h2>", s); err != nil {
if ok, err := regexp.MatchString("<h2[ ]*>.*hi.*<.h2>", s); err != nil {
t.Fatal(err, s)
} else if !ok {
t.Fatal(ok, s)

View File

@ -22,9 +22,9 @@ func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
}
func notesHead(w http.ResponseWriter, p filetree.Path) {
fmt.Fprintln(w, h2(p.MultiLink()))
fmt.Fprintln(w, h2(p.MultiLink(), "margin: 0; position: fixed; padding: .25em; background-color: #202b38; width: 100%; top: 0;"))
fmt.Fprintf(w, `
<form action=%q method="post">
<form action=%q method="post" style="padding-top: 2.5em">
<input type="text" name="keywords"></input>
<button type="submit">Search</button>
</form>