diff options
author | Jordan <me@jordan.im> | 2022-01-15 10:56:09 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2022-01-15 10:56:09 -0700 |
commit | 35339a2918240c7948d2748b2e8d484ea5cd9a76 (patch) | |
tree | 544064385b20ac74fb879db7a632de4dae4d0e9d | |
parent | ce063274e2711e615dc2eea1a44ff1f1867d9d0f (diff) | |
download | crane-35339a2918240c7948d2748b2e8d484ea5cd9a76.tar.gz crane-35339a2918240c7948d2748b2e8d484ea5cd9a76.zip |
http, templates: normalize paper metadata
-rw-r--r-- | http.go | 22 | ||||
-rw-r--r-- | templates/admin-edit.html | 3 | ||||
-rw-r--r-- | templates/list.html | 9 |
3 files changed, 24 insertions, 10 deletions
@@ -12,25 +12,32 @@ import ( var templateDir = getTemplateDir() -var indexTemp = template.Must(template.ParseFiles( +var funcMap = template.FuncMap{ + "normalizeStr": normalizeStr, +} + +var indexTemp = template.Must(template.New("index.html").Funcs(funcMap).ParseFiles( filepath.Join(templateDir, "layout.html"), filepath.Join(templateDir, "index.html"), filepath.Join(templateDir, "list.html"), )) -var adminTemp = template.Must(template.ParseFiles( + +var adminTemp = template.Must(template.New("admin.html").Funcs(funcMap).ParseFiles( filepath.Join(templateDir, "admin.html"), filepath.Join(templateDir, "layout.html"), filepath.Join(templateDir, "list.html"), )) -var editTemp = template.Must(template.ParseFiles( + +var editTemp = template.Must(template.New("admin-edit.html").Funcs(funcMap).ParseFiles( filepath.Join(templateDir, "admin-edit.html"), filepath.Join(templateDir, "layout.html"), filepath.Join(templateDir, "list.html"), )) -func cat(cat string) string { +func normalizeStr(s string) string { - return strings.Replace(cat, "-", "‑", -1) + trim := strings.TrimPrefix(strings.TrimSuffix(s, "\n"), "\n") + return strings.Join(strings.Fields(trim), " ") } // getTemplateDir returns the absolute path of the templates directory, @@ -58,7 +65,10 @@ func (papers *Papers) IndexHandler(w http.ResponseWriter, r *http.Request) { return } res := Resp{Papers: *papers} - indexTemp.Execute(w, &res) + err := indexTemp.Execute(w, &res) + if err != nil { + fmt.Println(err) + } } // AdminHandler renders the index of papers stored in papers.Path with diff --git a/templates/admin-edit.html b/templates/admin-edit.html index d8805f9..d4c9196 100644 --- a/templates/admin-edit.html +++ b/templates/admin-edit.html @@ -65,7 +65,8 @@ {{ if $paper.Meta.Title }} <span class="title"> <input type="checkbox" id="{{ $path }}" name="paper" value="{{ $path }}"/> - <a href='/download/{{ $path }}' title='{{ $paper.Meta.Title }}'>{{ $paper.Meta.Title }}</a> + <a href='/download/{{ $path }}' title='{{ normalizeStr $paper.Meta.Title }}'> + {{- normalizeStr $paper.Meta.Title }}</a> </span> <br /> {{ else }} diff --git a/templates/list.html b/templates/list.html index b9f7fd2..6d6cdaf 100644 --- a/templates/list.html +++ b/templates/list.html @@ -10,12 +10,14 @@ <div class="paper"> {{ if $paper.Meta.Title }} <span class="title"> - <a href='/download/{{ $path }}' title='{{ $paper.Meta.Title }}'>{{ $paper.Meta.Title }}</a> + <a href='/download/{{ $path }}' title='{{ normalizeStr $paper.Meta.Title }}'> + {{- normalizeStr $paper.Meta.Title }}</a> </span> <br /> {{ else }} <span class="title"> - <a href='/download/{{ $path }}' title='{{ $paper.PaperName }}'>{{ $paper.PaperName }}</a> + <a href='/download/{{ $path }}' title='{{ $paper.PaperName }}'> + {{- $paper.PaperName }}</a> </span> <br /> {{ end }} @@ -46,7 +48,8 @@ {{ else if $paper.Meta.ArxivID }} {{ if $hasVal }}- {{ end }} <span class="doi"> - <a href="https://arxiv.org/abs/{{ $paper.Meta.ArxivID }}">{{ $paper.Meta.ArxivID }}</a> + <a href="https://arxiv.org/abs/{{ $paper.Meta.ArxivID }}"> + {{- $paper.Meta.ArxivID }}</a> </span> {{ else if $paper.Meta.Resource }} {{ if $hasVal }}- {{ end }} |