Files
marqdo/plugins/web/internal/page/page.go
T
cflmyandCursor 23e4bc406e feat(web): Go W-G7 RSS, sitemap, redirect, and SEO bags
Add paginate/meta wiring, RSS and sitemap builders, and app
redirect/error/sitemap/robots route bags so content and W7 offline
smokes pass on libweb.so.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-10 17:51:50 +08:00

69 lines
1.5 KiB
Go

package page
import "strconv"
// New builds a page bag (ABI web_page_new), matching the Rust plugin shape.
func New(args map[string]any) map[string]any {
title := strOpt(args, "title", "Marqdo Web")
intro := strOpt(args, "intro", "")
out := map[string]any{
"title": title,
"intro": intro,
}
if s, ok := strAny(args, "shell_css", "壳样式"); ok {
out["shell_css"] = s
}
if s, ok := strAny(args, "layout", "布局"); ok {
out["layout"] = s
}
if s, ok := strAny(args, "asset_version", "资源版本"); ok {
out["asset_version"] = s
}
return out
}
// Paginate stamps page.paginate with offset/limit/path (Rust web_page_paginate).
func Paginate(page map[string]any, offset, limit int64, path string) map[string]any {
out := map[string]any{}
for k, v := range page {
out[k] = v
}
if path == "" {
path = "/"
}
out["paginate"] = map[string]any{
"offset": offset,
"limit": limit,
"path": path,
}
return out
}
func strOpt(args map[string]any, key, def string) string {
if s, ok := strAny(args, key); ok {
return s
}
return def
}
func strAny(args map[string]any, keys ...string) (string, bool) {
for _, k := range keys {
v, ok := args[k]
if !ok || v == nil {
continue
}
switch t := v.(type) {
case string:
return t, true
case float64:
if t == float64(int64(t)) {
return strconv.FormatInt(int64(t), 10), true
}
return strconv.FormatFloat(t, 'f', -1, 64), true
case bool:
return strconv.FormatBool(t), true
}
}
return "", false
}