/
theme.go
50 lines (42 loc) · 922 Bytes
/
theme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: MIT
package data
import (
"path"
"github.com/caixw/blogit/v2/internal/loader"
"github.com/caixw/blogit/v2/internal/vars"
)
// Theme 主题描述
type Theme struct {
ID string
URL string
Description string
Authors []*loader.Author
}
// Highlight 高亮主题
type Highlight struct {
Name string // 主题名称
Path string
URL string
Media string
}
func newTheme(t *loader.Theme) *Theme {
return &Theme{
ID: t.ID,
URL: t.URL,
Description: t.Description,
Authors: t.Authors,
}
}
func newHighlights(conf *loader.Config, t *loader.Theme) []*Highlight {
hs := make([]*Highlight, 0, len(t.Highlights))
for _, h := range t.Highlights {
p := path.Join(vars.ThemesDir, t.ID, h.Name+".css")
hs = append(hs, &Highlight{
Name: h.Name,
Path: p,
URL: BuildURL(conf.URL, p),
Media: h.Media,
})
}
return hs
}