favicon. #19
This commit is contained in:
parent
7667190a9c
commit
94918b5b62
|
@ -7,6 +7,12 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{{ .Title }} - {{ .User.Config.Title }}</title>
|
<title>{{ .Title }} - {{ .User.Config.Title }}</title>
|
||||||
|
|
||||||
|
{{ if .User.FaviconUrl }}
|
||||||
|
<link rel="icon" href="{{ .User.FaviconUrl }}">
|
||||||
|
{{ else }}
|
||||||
|
<link rel="icon" href="data:,">
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<meta property="og:title" content="{{ .Title }}" />
|
<meta property="og:title" content="{{ .Title }}" />
|
||||||
{{ if .Description }}
|
{{ if .Description }}
|
||||||
<meta name="description" content="{{ .Description }}">
|
<meta name="description" content="{{ .Description }}">
|
||||||
|
|
|
@ -360,3 +360,13 @@ func TestOpenGraphTags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddFaviconIfExist(t *testing.T) {
|
||||||
|
user := getTestUser()
|
||||||
|
os.WriteFile(path.Join(user.MediaDir(), "favicon.png"), []byte("test"), 0644)
|
||||||
|
|
||||||
|
result, _ := owl.RenderIndexPage(user)
|
||||||
|
if !strings.Contains(result, "favicon.png") {
|
||||||
|
t.Error("favicon not rendered. Got: " + result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
10
user.go
10
user.go
|
@ -78,6 +78,16 @@ func (user User) AvatarUrl() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user User) FaviconUrl() string {
|
||||||
|
for _, ext := range []string{".jpg", ".jpeg", ".png", ".gif", ".ico"} {
|
||||||
|
if fileExists(path.Join(user.MediaDir(), "favicon"+ext)) {
|
||||||
|
url, _ := url.JoinPath(user.MediaUrl(), "favicon"+ext)
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (user User) Posts() ([]*Post, error) {
|
func (user User) Posts() ([]*Post, error) {
|
||||||
postFiles := listDir(path.Join(user.Dir(), "public"))
|
postFiles := listDir(path.Join(user.Dir(), "public"))
|
||||||
posts := make([]*Post, 0)
|
posts := make([]*Post, 0)
|
||||||
|
|
15
user_test.go
15
user_test.go
|
@ -324,3 +324,18 @@ func TestPostNameIllegalFileName(t *testing.T) {
|
||||||
t.Error("Should not have failed")
|
t.Error("Should not have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFaviconIfNotExist(t *testing.T) {
|
||||||
|
user := getTestUser()
|
||||||
|
if user.FaviconUrl() != "" {
|
||||||
|
t.Error("Favicon should be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFaviconSetIfFileExist(t *testing.T) {
|
||||||
|
user := getTestUser()
|
||||||
|
os.WriteFile(path.Join(user.MediaDir(), "favicon.ico"), []byte("test"), 0644)
|
||||||
|
if user.FaviconUrl() == "" {
|
||||||
|
t.Error("Favicon should not be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue