Browse Source

support image as icon

Help-14 3 years ago
parent
commit
9699849b04
2 changed files with 32 additions and 1 deletions
  1. 29 0
      src/modules/content.go
  2. 3 1
      src/themes/flame/index.html

+ 29 - 0
src/modules/content.go

@@ -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
+}

+ 3 - 1
src/themes/flame/index.html

@@ -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>