diff --git a/config.yml b/config.yml index 47a122f..2827c57 100644 --- a/config.yml +++ b/config.yml @@ -6,8 +6,9 @@ output: dir: output file: index.html template: - markdown: template.md + info: template_info.html html_head: template_head.html + log: template_log.html time: format: 2006-01-02 15:04:05 MST timezone: UTC \ No newline at end of file diff --git a/main.go b/main.go index 848647f..9fa8725 100644 --- a/main.go +++ b/main.go @@ -14,8 +14,9 @@ type Config struct { RedisPassword string OutputDir string OutputFilename string - TemplateFilename string + TemplateInfoFilename string TemplateHeadFilename string + templateLogFilename string TimeFormat string Timezone string } @@ -38,7 +39,8 @@ func main() { RedisPassword: viper.GetString("redis.password"), OutputDir: viper.GetString("output.dir"), OutputFilename: viper.GetString("output.file"), - TemplateFilename: viper.GetString("template.markdown"), + TemplateInfoFilename: viper.GetString("template.info"), + templateLogFilename: viper.GetString("template.log"), TemplateHeadFilename: viper.GetString("template.html_head"), TimeFormat: viper.GetString("time.format"), Timezone: viper.GetString("time.timezone"), @@ -52,15 +54,8 @@ func main() { ctx := context.Background() // 获取订阅者和关注者列表 subscribeAndFollowers := GetSubcribesAndFollowers(rdb, ctx) - // 读取模板文件 - templateFile, err := os.ReadFile(config.TemplateFilename) - if err != nil { - fmt.Printf("Failed to read template file: %s\n", config.TemplateFilename) - panic(err) - } // 生成 HTML 文件 - bodyHtml := MdToHTML(FillMarkdownTemplate(templateFile, subscribeAndFollowers)) - htmlBytes := FillHtml(bodyHtml) + htmlBytes := GenHtml(&subscribeAndFollowers) // 输出HTML文件 // 检查输出目录是否存在,如果不存在则创建 if _, err := os.Stat(config.OutputDir); os.IsNotExist(err) { diff --git a/page.go b/page.go index 6b76639..01ed8a0 100644 --- a/page.go +++ b/page.go @@ -23,27 +23,41 @@ func MdToHTML(md []byte) []byte { return markdown.Render(doc, renderer) } -func FillHtml(html []byte) []byte { - htmlStr := string(html) +func GenHtml(subList *[]string) []byte { + var htmlStr string // 添加 html 头 htmlHead, err := os.ReadFile(config.TemplateHeadFilename) if err != nil { fmt.Printf("Failed to read template file: %s\n", config.TemplateHeadFilename) panic(err) } - htmlStr = string(htmlHead) + "\n\n" + "
\n" + htmlStr - // 添加页尾信息 - htmlStr += "\n\n" + htmlStr += fmt.Sprintf("\n

列表最后更新于 %s

\n", time.Now().In(loc).Format(config.TimeFormat)) + // 添加实时日志 + logBody, err := os.ReadFile(config.templateLogFilename) + if err != nil { + fmt.Printf("Failed to read template file: %s\n", config.templateLogFilename) + panic(err) + } + htmlStr += "\n" + string(logBody) // 添加 html 尾 htmlStr += "\n
\n\n" return []byte(htmlStr) } -func FillMarkdownTemplate(md []byte, domainList []string) []byte { +func GenSubMdList(domainList []string) []byte { var list string count := 0 var wg sync.WaitGroup @@ -66,6 +80,7 @@ func FillMarkdownTemplate(md []byte, domainList []string) []byte { }(d) } wg.Wait() + var md []byte md = append(md, []byte(fmt.Sprintf("\n共 **%d** 个站点\n", count))...) return append(md, []byte(list)...) } diff --git a/template_head.html b/template_head.html index 4dcd8cc..4e80f7e 100644 --- a/template_head.html +++ b/template_head.html @@ -26,6 +26,10 @@ max-width: 1024px; } } + span.sel { + color: var(--color-primary); + cursor: pointer; + } /* 设置 h1 的行距 */ h1{ margin-top: 1.5em; @@ -62,5 +66,22 @@ li{ margin-top: 0.5em; } + /* 美化代码块 */ + pre { + background-color: #f5f5f5; + border-radius: 0.5em; + padding: 1em; + overflow-x: auto; + } + /* 美化按钮,扁平样式 */ + button { + border: none; + border-radius: 0.5em; + padding: 0.5em 1em; + background-color: var(--color-primary); + color: white; + cursor: pointer; + transition: .2s all ease-in-out; + } \ No newline at end of file diff --git a/template_info.html b/template_info.html new file mode 100644 index 0000000..bd23c1c --- /dev/null +++ b/template_info.html @@ -0,0 +1,35 @@ +

relay.isle.moe

+ +

订阅

+ +

欢迎~

+ + + +

如果订阅异常可以试试移除中继再重新订阅!

+ +

所使用的后端为 yukimochi/Activity-Relay

+ +

页面生成器:isle-activity-relay-frontend

+ +

有问题可以联系 @Claire

+ +

订阅的实例列表

+ +

每 5 分钟更新一次

+ + + \ No newline at end of file diff --git a/template_log.html b/template_log.html new file mode 100644 index 0000000..6925798 --- /dev/null +++ b/template_log.html @@ -0,0 +1,41 @@ +

收信日志

+

+
+
+
+
+

送信日志

+

+
+
+
+
+
+
\ No newline at end of file