// Package assets ports head/images/icons HTML assembly (W8 / W-G6). package assets import ( "fmt" "path" "strings" "github.com/marqdo/marqdo/plugins/web/internal/table" ) // HeadLink is one or `, esc(href)) s.WriteString(tag) continue } tag := fmt.Sprintf(``, esc(loading)) inner := img if href != "" { inner = fmt.Sprintf(`%s`, esc(href), img) } figClass := "mq-img" if class != "" { figClass = "mq-img " + class } figures.WriteString(fmt.Sprintf(`
%s`, figClass, inner)) if caption != "" { figures.WriteString(fmt.Sprintf("
%s
", esc(caption))) } figures.WriteString("
") } if figures.Len() == 0 { return "" } return `
` + figures.String() + `
` } // AttachHead merges head table links onto page.head. func AttachHead(page map[string]any, table any) map[string]any { out := cloneMap(page) links := AsHeadLinks(table) existing := HeadLinksFromJSON(out["head"]) for _, link := range links { dup := false for _, e := range existing { if e.Href == link.Href && strings.EqualFold(e.Rel, link.Rel) { dup = true break } } if !dup { existing = append(existing, link) } } out["head"] = HeadLinksToJSON(existing) return out } // AttachImages appends images_html on page. func AttachImages(page map[string]any, table any) map[string]any { out := cloneMap(page) html := MakeImagesHTML(table) prev, _ := out["images_html"].(string) switch { case prev == "": out["images_html"] = html case html == "": out["images_html"] = prev default: out["images_html"] = prev + html } return out } // AttachMeta sets page.meta from SEO table. func AttachMeta(page map[string]any, meta any) map[string]any { out := cloneMap(page) out["meta"] = table.AsMetaMap(meta) return out } func cloneMap(m map[string]any) map[string]any { if m == nil { return map[string]any{} } out := make(map[string]any, len(m)) for k, v := range m { out[k] = v } return out }