- CHANGELOG.md:v2.8.0 条目(中英双语); - README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明); - doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制); - skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/ require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过); - 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
84 lines
2.0 KiB
Go
Executable File
84 lines
2.0 KiB
Go
Executable File
// Package rss builds RSS 2.0 feeds (content-site W4 / W-G7).
|
|
package rss
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func esc(s string) string {
|
|
s = strings.ReplaceAll(s, "&", "&")
|
|
s = strings.ReplaceAll(s, "<", "<")
|
|
s = strings.ReplaceAll(s, ">", ">")
|
|
s = strings.ReplaceAll(s, `"`, """)
|
|
return s
|
|
}
|
|
|
|
func cellStr(v any) string {
|
|
switch t := v.(type) {
|
|
case nil:
|
|
return ""
|
|
case string:
|
|
return t
|
|
case bool:
|
|
return strconv.FormatBool(t)
|
|
case float64:
|
|
if t == float64(int64(t)) {
|
|
return strconv.FormatInt(int64(t), 10)
|
|
}
|
|
return strconv.FormatFloat(t, 'f', -1, 64)
|
|
default:
|
|
return fmt.Sprint(t)
|
|
}
|
|
}
|
|
|
|
func pick(m map[string]any, keys ...string) any {
|
|
for _, k := range keys {
|
|
if v, ok := m[k]; ok {
|
|
return v
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BuildRSS assembles RSS 2.0 XML from channel metadata and row maps.
|
|
func BuildRSS(title, link, description string, items []any) string {
|
|
body := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
|
|
<rss version="2.0"><channel>
|
|
<title>%s</title>
|
|
<link>%s</link>
|
|
<description>%s</description>
|
|
`, esc(title), esc(link), esc(description))
|
|
for _, row := range items {
|
|
m, ok := row.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
itemTitle := cellStr(pick(m, "title", "标题"))
|
|
itemLink := cellStr(pick(m, "link", "href", "链接", "slug"))
|
|
itemDesc := cellStr(pick(m, "description", "summary", "摘要", "body", "正文"))
|
|
pubDate := cellStr(pick(m, "pubDate", "published", "created_at", "发布"))
|
|
fullLink := link
|
|
if itemLink != "" {
|
|
if strings.HasPrefix(itemLink, "http") {
|
|
fullLink = itemLink
|
|
} else if itemLink[0] == '/' {
|
|
fullLink = link + itemLink
|
|
} else {
|
|
fullLink = link + "/" + itemLink
|
|
}
|
|
}
|
|
body += "<item>"
|
|
body += fmt.Sprintf("<title>%s</title>", esc(itemTitle))
|
|
body += fmt.Sprintf("<link>%s</link>", esc(fullLink))
|
|
body += fmt.Sprintf("<description>%s</description>", esc(itemDesc))
|
|
if pubDate != "" {
|
|
body += fmt.Sprintf("<pubDate>%s</pubDate>", esc(pubDate))
|
|
}
|
|
body += "</item>"
|
|
}
|
|
body += "</channel></rss>"
|
|
return body
|
|
}
|