readysite / website / internal / content / seed / collections.go
5.6 KB
collections.go
package seed

import (
	"encoding/json"

	"github.com/readysite/readysite/pkg/database"
	"github.com/readysite/readysite/website/internal/content/schema"
	"github.com/readysite/readysite/website/models"
)

// Collections seeds default collections and sample data.
func Collections() {
	if models.Collections.Count("") > 0 {
		return
	}

	// Blog Posts collection
	blogFields, _ := json.Marshal([]schema.Field{
		{Name: "title", Type: schema.Text, Required: true},
		{Name: "slug", Type: schema.Text, Required: true, Unique: true},
		{Name: "excerpt", Type: schema.Text},
		{Name: "content", Type: schema.Text},
		{Name: "author", Type: schema.Text},
		{Name: "publishedAt", Type: schema.Date},
		{Name: "featured", Type: schema.Bool},
		{Name: "tags", Type: schema.JSON},
	})
	models.Collections.Insert(&models.Collection{
		Model:       database.Model{ID: "blog_posts"},
		Name:        "Blog Posts",
		Description: "Blog articles and news",
		Schema:      string(blogFields),
	})

	// Sample blog posts
	blogPosts := []map[string]any{
		{
			"title":       "Welcome to ReadySite",
			"slug":        "welcome-to-readysite",
			"excerpt":     "Get started with your new AI-powered website.",
			"content":     "Welcome to ReadySite! This is your first blog post. You can edit or delete this post from the admin panel, or ask the AI assistant to help you create new content.",
			"author":      "Admin",
			"publishedAt": "2025-01-25T00:00:00Z",
			"featured":    true,
			"tags":        []string{"welcome", "getting-started"},
		},
		{
			"title":       "Getting Started Guide",
			"slug":        "getting-started",
			"excerpt":     "Learn how to use ReadySite to build your website.",
			"content":     "ReadySite makes it easy to create and manage your website. Use the admin panel to create pages, manage collections, and chat with the AI assistant for help.",
			"author":      "Admin",
			"publishedAt": "2025-01-24T00:00:00Z",
			"featured":    false,
			"tags":        []string{"tutorial", "guide"},
		},
		{
			"title":       "AI-Powered Content Creation",
			"slug":        "ai-content-creation",
			"excerpt":     "Discover how AI can help you create better content.",
			"content":     "Our AI assistant can help you create pages, write blog posts, and manage your website content. Just start a chat and describe what you want to create.",
			"author":      "Admin",
			"publishedAt": "2025-01-23T00:00:00Z",
			"featured":    false,
			"tags":        []string{"ai", "content"},
		},
	}
	for _, data := range blogPosts {
		doc := &models.Document{CollectionID: "blog_posts"}
		doc.SetAll(data)
		models.Documents.Insert(doc)
	}

	// Team Members collection
	teamFields, _ := json.Marshal([]schema.Field{
		{Name: "name", Type: schema.Text, Required: true},
		{Name: "role", Type: schema.Text, Required: true},
		{Name: "bio", Type: schema.Text},
		{Name: "email", Type: schema.Email},
		{Name: "avatar", Type: schema.URL},
		{Name: "linkedin", Type: schema.URL},
		{Name: "twitter", Type: schema.URL},
		{Name: "order", Type: schema.Number},
	})
	models.Collections.Insert(&models.Collection{
		Model:       database.Model{ID: "team_members"},
		Name:        "Team Members",
		Description: "Team member profiles",
		Schema:      string(teamFields),
	})

	// Sample team members
	teamMembers := []map[string]any{
		{
			"name":     "Alex Johnson",
			"role":     "CEO & Founder",
			"bio":      "Passionate about building tools that empower creators. 10+ years in tech startups.",
			"email":    "alex@example.com",
			"linkedin": "https://linkedin.com/in/alexjohnson",
			"order":    1,
		},
		{
			"name":     "Sam Chen",
			"role":     "CTO",
			"bio":      "Full-stack engineer with a love for clean architecture and developer experience.",
			"email":    "sam@example.com",
			"linkedin": "https://linkedin.com/in/samchen",
			"order":    2,
		},
		{
			"name":     "Jordan Rivera",
			"role":     "Head of Design",
			"bio":      "Creating beautiful, intuitive interfaces that users love.",
			"email":    "jordan@example.com",
			"twitter":  "https://twitter.com/jordanrivera",
			"order":    3,
		},
	}
	for _, data := range teamMembers {
		doc := &models.Document{CollectionID: "team_members"}
		doc.SetAll(data)
		models.Documents.Insert(doc)
	}

	// FAQ collection
	faqFields, _ := json.Marshal([]schema.Field{
		{Name: "question", Type: schema.Text, Required: true},
		{Name: "answer", Type: schema.Text, Required: true},
		{Name: "category", Type: schema.Text},
		{Name: "order", Type: schema.Number},
	})
	models.Collections.Insert(&models.Collection{
		Model:       database.Model{ID: "faq"},
		Name:        "FAQ",
		Description: "Frequently asked questions",
		Schema:      string(faqFields),
	})

	// Sample FAQs
	faqs := []map[string]any{
		{
			"question": "What is ReadySite?",
			"answer":   "ReadySite is an AI-native content management system that makes it easy to build and manage websites. It combines the ease of WordPress with AI-powered content creation.",
			"category": "General",
			"order":    1,
		},
		{
			"question": "How do I get started?",
			"answer":   "Simply sign up, complete the setup wizard, and start creating. You can use the admin panel to create pages manually or chat with the AI assistant for help.",
			"category": "Getting Started",
			"order":    2,
		},
		{
			"question": "Can I use a custom domain?",
			"answer":   "Yes! You can connect your own domain in the Settings page. Point your domain's DNS to our servers and we'll handle the rest.",
			"category": "Domains",
			"order":    3,
		},
	}
	for _, data := range faqs {
		doc := &models.Document{CollectionID: "faq"}
		doc.SetAll(data)
		models.Documents.Insert(doc)
	}
}
← Back