support image as icon
This commit is contained in:
parent
931afa0439
commit
9699849b04
2 changed files with 32 additions and 1 deletions
|
@ -2,8 +2,10 @@ package modules
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"index/suffixarray"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
@ -34,6 +36,10 @@ func (b *BookmarkData) IsSVG() bool {
|
|||
return strings.Contains(b.Icon, ".svg")
|
||||
}
|
||||
|
||||
func (b *BookmarkData) IsImage() bool {
|
||||
return contains(b.Icon, ".jpg", ".jpeg", ".png", ".gif", ".apng", ".bmp", ".ico", ".webp")
|
||||
}
|
||||
|
||||
func LoadContent() ContentData {
|
||||
emptyData := ContentData{}
|
||||
|
||||
|
@ -51,3 +57,26 @@ func LoadContent() ContentData {
|
|||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func contains(str string, subStrs ...string) bool {
|
||||
if len(subStrs) == 0 {
|
||||
return true
|
||||
}
|
||||
r := regexp.MustCompile(strings.Join(subStrs, "|"))
|
||||
index := suffixarray.New([]byte(str))
|
||||
res := index.FindAllIndex(r, -1)
|
||||
exists := make(map[string]int)
|
||||
for _, v := range subStrs {
|
||||
exists[v] = 1
|
||||
}
|
||||
for _, pair := range res {
|
||||
s := str[pair[0]:pair[1]]
|
||||
exists[s] = exists[s] + 1
|
||||
}
|
||||
for _, v := range exists {
|
||||
if v == 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -66,7 +66,9 @@
|
|||
{{range .Bookmarks}}
|
||||
<a href="{{.Url}}">
|
||||
<div class="icon-container">
|
||||
{{if .IsSVG}}
|
||||
{{if .IsImage}}
|
||||
<img src="{{.Icon}}" class="icon">
|
||||
{{else if .IsSVG}}
|
||||
<svg-file src="{{.Icon}}" class="svg-icon"></svg-file>
|
||||
{{else}}
|
||||
<i class="{{.Icon}} fa-xl icon"></i>
|
||||
|
|
Loading…
Add table
Reference in a new issue