// pages/AreaPage.js - Single-topic view for area pages import { areasData } from '../data/areas.js'; import { featuredArtifacts } from '../data/artifacts.js'; import { createArtifactCarousel } from '../cards/ArtifactSummaryCard.js'; import { sampleResources } from '../data/resources.js'; import { createResourceCard, initializeResourceCards } from '../cards/ResourceCard.js'; export function renderAreaPage(areaId, topicId = null) { const area = areasData[areaId]; if (!area) { return { content: `

Area not found

`, init: () => {} }; } // If no topic specified, show overview of the area if (!topicId) { return renderAreaOverview(area, areaId); } // Show specific topic const topic = area.subAreas[topicId]; if (!topic) { return { content: `

Topic not found

`, init: () => {} }; } return renderTopicView(area, areaId, topic, topicId); } function renderAreaOverview(area, areaId) { // Get sub-areas as array const topics = Object.entries(area.subAreas).map(([key, value]) => ({ id: key, name: typeof value === 'string' ? value : value.name, navName: typeof value === 'string' ? value : (value.navName || value.name), description: typeof value === 'string' ? '' : (value.description || ''), color: typeof value === 'object' ? value.color : 'bg-gray-200 text-gray-700' })); const content = `
${area.navTitle}: Overview ${topics.map((topic, index) => ` ${index === 0 ? '' : ''} ${topic.navName} ${index < topics.length - 1 ? '' : ''} `).join('')}

${area.title}

${area.description}

${area.openness ? `

🤗 The Role of Openness

${area.openness}

` : ''}

Topics in this area:

${topics.map(topic => { // Extract colors from topic.color let bgColor = 'bg-gray-200'; let textColor = 'text-gray-700'; if (topic.color) { const bgMatch = topic.color.match(/bg-(\w+)-(\d+)/); const textMatch = topic.color.match(/text-(\w+)-(\d+)/); if (bgMatch) bgColor = `bg-${bgMatch[1]}-${bgMatch[2]}`; if (textMatch) textColor = `text-${textMatch[1]}-700`; } return ` ${topic.navName} `; }).join('')}
`; return { content, init: () => {} }; } function renderTopicView(area, areaId, topic, topicId) { const topicName = topic.navName || topic.name; const topicDescription = topic.description || ''; const topicOpenness = topic.openness || ''; // Get all topics for navigation const allTopics = Object.entries(area.subAreas).map(([key, value]) => ({ id: key, navName: typeof value === 'string' ? value : (value.navName || value.name) })); const content = `
${area.navTitle}: Overview ${allTopics.map((t, index) => ` ${index === 0 ? '' : ''} ${t.navName} ${index < allTopics.length - 1 ? '' : ''} `).join('')}
${area.navTitle} ${topicName}

${topic.name}

${topicDescription ? `

${topicDescription}

` : ''} ${topicOpenness ? `

🤗 The Role of Openness

${topicOpenness}

` : ''}

Related Research & Resources

`; return { content, init: () => { // Initialize artifact carousel for this topic setTimeout(async () => { try { const allArtifacts = window.allArtifacts || []; // Filter artifacts by this specific topic const filteredArtifacts = allArtifacts.filter(artifact => artifact.topics && artifact.topics.includes(topicId) ); // Transform field names to match expected format const transformedArtifacts = filteredArtifacts.map(artifact => ({ ...artifact, areaTags: artifact.areas, subAreaTags: artifact.topics, sourceUrl: artifact.url })); const carouselId = `${topicId}-artifacts-carousel`; createArtifactCarousel(transformedArtifacts.length > 0 ? transformedArtifacts : featuredArtifacts, carouselId); } catch (error) { console.error(`Error creating carousel for ${topicId}:`, error); const carouselId = `${topicId}-artifacts-carousel`; createArtifactCarousel(featuredArtifacts, carouselId); } }, 50); } }; }