Add site information management with Markdown support

This commit is contained in:
2025-05-18 11:04:59 +08:00
parent 1b5eb23a65
commit be09b55765
9 changed files with 67 additions and 8 deletions

View File

@@ -22,10 +22,12 @@ type ServerConfig struct {
CloudflareTurnstileSiteKey string `json:"cloudflare_turnstile_site_key"`
// CloudflareTurnstileSecretKey is the secret key for Cloudflare Turnstile.
CloudflareTurnstileSecretKey string `json:"cloudflare_turnstile_secret_key"`
// ServerName is the name of the server. It will be used as the title of the web page.
ServerName string `json:"server_name"`
// ServerDescription is the description of the server. It will be used as the description of html meta tag.
ServerDescription string `json:"server_description"`
// SiteInfo is an article that describes the site. It will be displayed on the home page. Markdown format.
SiteInfo string `json:"site_info"`
}
func init() {
@@ -63,8 +65,8 @@ func SetConfig(newConfig ServerConfig) {
if err != nil {
panic(err)
}
filepath := filepath.Join(utils.GetStoragePath(), "config.json")
if err := os.WriteFile(filepath, data, 0644); err != nil {
p := filepath.Join(utils.GetStoragePath(), "config.json")
if err := os.WriteFile(p, data, 0644); err != nil {
panic(err)
}
}
@@ -100,3 +102,7 @@ func ServerDescription() string {
func CloudflareTurnstileSecretKey() string {
return config.CloudflareTurnstileSecretKey
}
func SiteInfo() string {
return config.SiteInfo
}

View File

@@ -43,8 +43,9 @@ func serveIndexHtml(c fiber.Ctx) error {
description := config.ServerDescription()
preview := serverBaseURL + "/icon-192.png"
title := siteName
url := c.OriginalURL()
url := serverBaseURL + c.Path()
cfTurnstileSiteKey := config.CloudflareTurnstileSiteKey()
siteInfo := config.SiteInfo()
if strings.HasPrefix(url, "/resources/") {
idStr := strings.TrimPrefix(url, "/resources/")
@@ -75,6 +76,7 @@ func serveIndexHtml(c fiber.Ctx) error {
content = strings.ReplaceAll(content, "{{Title}}", title)
content = strings.ReplaceAll(content, "{{Url}}", url)
content = strings.ReplaceAll(content, "{{CFTurnstileSiteKey}}", cfTurnstileSiteKey)
content = strings.ReplaceAll(content, "{{SiteInfo}}", siteInfo)
c.Set("Content-Type", "text/html; charset=utf-8")
return c.SendString(content)