From eebeb1a57562c0501b644da2f55612e8e8f978eb Mon Sep 17 00:00:00 2001 From: cawcenter Date: Tue, 16 Dec 2025 12:25:33 -0500 Subject: [PATCH] Fix: Change editors to client:only + add demo page generator using database content --- src/pages/admin/pages/demo-generator.astro | 218 +++++++++++++++++++++ src/pages/admin/pages/new.astro | 2 +- src/pages/admin/posts/new.astro | 2 +- 3 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 src/pages/admin/pages/demo-generator.astro diff --git a/src/pages/admin/pages/demo-generator.astro b/src/pages/admin/pages/demo-generator.astro new file mode 100644 index 0000000..a373d73 --- /dev/null +++ b/src/pages/admin/pages/demo-generator.astro @@ -0,0 +1,218 @@ +--- +// Demo Page Generator - Uses Real Database Content +import AdminLayout from '@/layouts/AdminLayout.astro'; +import { pool } from '@/lib/db'; + +// Get site +const { rows: sites } = await pool.query<{id: string; domain: string}>('SELECT id, domain FROM sites LIMIT 1'); +const site = sites[0]; + +if (!site) { + return Astro.redirect('/admin/sites'); +} + +// Get content fragments if they exist +const { rows: fragments } = await pool.query<{fragment_type: string; content: any}>( + 'SELECT fragment_type, content FROM content_fragments LIMIT 10' +); + +// Get article templates if they exist +const { rows: templates } = await pool.query<{name: string; template: any}>( + 'SELECT name, template FROM article_templates ORDER BY created_at DESC LIMIT 5' +); + +// Build demo page HTML +let demoHTML = ` +
+
+

+ Welcome to ${site.domain} +

+

+ This page was auto-generated using content from your database +

+
+ +
+

About Your Platform

+

+ You have ${fragments.length} content fragments and ${templates.length} article templates in your database. + This demonstrates the direct database integration working perfectly! +

+
+`; + +// Add content fragments section if exist +if (fragments.length > 0) { + demoHTML += ` +
+

📦 Your Content Fragments

+
+ `; + + fragments.slice(0, 6).forEach(frag => { + demoHTML += ` +
+

+ ${frag.fragment_type || 'Content Block'} +

+

+ ${JSON.stringify(frag.content).substring(0, 100)}... +

+
+ `; + }); + + demoHTML += ` +
+
+ `; +} + +// Add templates section if exist +if (templates.length > 0) { + demoHTML += ` +
+

📄 Your Article Templates

+
+ `; + + templates.forEach(tmpl => { + demoHTML += ` +
+

+ ✨ ${tmpl.name} +

+
+ ${JSON.stringify(tmpl.template, null, 2).substring(0, 300)}... +
+
+ `; + }); + + demoHTML += ` +
+
+ `; +} + +demoHTML += ` +
+

🚀 Ready to Build More?

+

+ This page demonstrates that your database content is accessible and renders perfectly. +

+
+ + Create Custom Page + + + Create Blog Post + +
+
+ +
+

✨ Auto-generated from ${site.domain} database | God Mode Direct PostgreSQL Integration

+
+
+`; + +// Create the page using the API +const pageData = { + site_id: site.id, + name: "Database Demo Page", + route: "/demo", + html_content: demoHTML, + meta_title: `${site.domain} - Database Integration Demo`, + meta_description: "Auto-generated demo page showing content from the database", + status: "published" +}; + +let createdPage = null; +try { + const response = await fetch(`${Astro.url.origin}/api/shim/pages/create`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${import.meta.env.GOD_MODE_TOKEN}` + }, + body: JSON.stringify(pageData) + }); + + if (response.ok) { + createdPage = await response.json(); + } +} catch (error) { + console.error('Failed to create demo page:', error); +} +--- + + +
+ +
+
+

📊 Database Demo Page

+

Auto-generated page using your database content

+
+ + ← Back to Admin + +
+ + {createdPage ? ( +
+

✅ Demo Page Created!

+

+ Your demo page has been successfully created from database content. +

+ + +
+

+ ID: {createdPage.id}
+ Route: {createdPage.route}
+ Status: {createdPage.status} +

+
+
+ ) : ( +
+

⚠️ Page Creation

+

+ Generating demo page... refresh if needed. +

+
+ )} + +
+

Database Content Found:

+
+
+
{fragments.length}
+
Content Fragments
+
+
+
{templates.length}
+
Article Templates
+
+
+
+ +
+
diff --git a/src/pages/admin/pages/new.astro b/src/pages/admin/pages/new.astro index 4848d5f..a08e85e 100644 --- a/src/pages/admin/pages/new.astro +++ b/src/pages/admin/pages/new.astro @@ -27,7 +27,7 @@ if (!siteId) {
{ window.location.href = `/admin/pages/${page.id}/edit`; diff --git a/src/pages/admin/posts/new.astro b/src/pages/admin/posts/new.astro index 80ce377..15d939f 100644 --- a/src/pages/admin/posts/new.astro +++ b/src/pages/admin/posts/new.astro @@ -27,7 +27,7 @@ if (!siteId) {
{ window.location.href = `/admin/posts/${post.id}/edit`;