Skip to content

Commit

Permalink
improved title copying
Browse files Browse the repository at this point in the history
  • Loading branch information
klausbreyer committed Oct 5, 2023
1 parent c6c6f6d commit 44bc961
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/html.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package src

import (
"fmt"
"html/template"
"strings"

"github.com/klausbreyer/grr"
)
Expand Down Expand Up @@ -97,24 +99,28 @@ type DataBook struct {
}

func getBook(data DataBook) template.HTML {
// Erstellen Sie die eigene Variable und entfernen Sie alle ":"
titleStr := strings.ReplaceAll(fmt.Sprintf("%s, %s, %d", data.Book.Title, data.Book.Author, data.Book.FirstHighlightYear), ":", "")

return grr.Render(`
<a id="{{.BookIndex}}" href="#{{.BookIndex}}">#{{.BookIndex}}</a>
<h2 style="cursor:copy;" onclick="copyToClipboard('{{.Book.Title}}, {{.Book.Author}}, {{.Book.FirstHighlightYear}}')" > {{.Book.Title}}, {{.Book.Author}}, {{.Book.FirstHighlightYear}}</h2>
<h2 style="cursor:copy;" onclick="copyToClipboard('read/{{.TitleStr}}')" >{{.TitleStr}}</h2>
<span onclick="copyToClipboard('{{.Book.SourceURL}}')" style="cursor:copy;" >{{.Book.SourceURL}}</span>
<a href="{{.Book.SourceURL}}" target="_blank">&raquo;</a>
<a href="{{.Book.SourceURL}}" target="_blank">&raquo;&raquo;&raquo;</a>
<ul>
{{.Highlights}}
</ul>
<hr/>
`, struct {
Book Book
BookIndex int
Highlights template.HTML
TitleStr string
}{
data.Book,
data.BookIndex,
getHighlights(data.Book.Highlights),
titleStr,
})
}

Expand Down

0 comments on commit 44bc961

Please sign in to comment.