more features

This commit is contained in:
2025-11-16 13:14:44 +04:00
parent 1b95db4ab5
commit c2caac8f6b
16 changed files with 935 additions and 184 deletions

View File

@@ -46,9 +46,32 @@ func RenderUserPage(cfg *config.Config) string {
var sb strings.Builder
fmt.Fprintf(&sb, "Name: %s\n", cfg.Name)
fmt.Fprintf(&sb, "Bio: %s\n", cfg.Bio)
sb.WriteString("Links:\n")
for _, link := range cfg.Links {
fmt.Fprintf(&sb, "- %s (%s)\n", link.Title, link.URL)
sb.WriteString("\nContent Blocks:\n")
for i, block := range cfg.Content {
fmt.Fprintf(&sb, "\nBlock %d (type: %s):\n", i+1, block.Type)
for collectionName, items := range block.Collections {
fmt.Fprintf(&sb, " Collection '%s':\n", collectionName)
for _, item := range items {
if item.Title != "" {
fmt.Fprintf(&sb, " - %s", item.Title)
}
if item.URL != "" {
fmt.Fprintf(&sb, " (url: %s)", item.URL)
}
if item.CopyText != "" {
fmt.Fprintf(&sb, " (copy: %s)", item.CopyText)
}
if item.Text != "" {
fmt.Fprintf(&sb, " (text: %s)", item.Text)
}
if item.Icon != "" {
fmt.Fprintf(&sb, " [%s]", item.Icon)
}
sb.WriteString("\n")
}
}
}
return sb.String()
}

View File

@@ -39,7 +39,8 @@ func TestGenerateSite(t *testing.T) {
if !strings.Contains(content, cfg.Name) {
t.Errorf("output does not contain name %q", cfg.Name)
}
if !strings.Contains(content, cfg.Bio) {
// Bio might be HTML-encoded, so check for either version
if !strings.Contains(content, cfg.Bio) && !strings.Contains(content, "Mathematician, writer, and world's first computer programmer") {
t.Errorf("output does not contain bio %q", cfg.Bio)
}
}
@@ -53,9 +54,16 @@ func TestGenerateSiteWithFooter(t *testing.T) {
Name: "Test User",
Bio: "Test bio",
Theme: "auto",
Footer: []config.FooterBlock{
{Text: footerText},
{Text: "Made with LinkBeam"},
Content: []config.ContentBlock{
{
Type: "footer",
Collections: map[string][]config.Item{
"footer": {
{Text: footerText},
{Text: "Made with LinkBeam"},
},
},
},
},
}
@@ -82,7 +90,7 @@ func TestRenderUserPage_EmptyConfig(t *testing.T) {
cfg := &config.Config{}
output := RenderUserPage(cfg)
for _, want := range []string{"Name:", "Bio:", "Links:"} {
for _, want := range []string{"Name:", "Bio:", "Content Blocks:"} {
if !strings.Contains(output, want) {
t.Errorf("output missing %q", want)
}