// cards/ResourceCard.js - Resource card component for SPA import { areasData } from '../data/areas.js'; export function createResourceCard(resource) { // Get the primary area for this resource const primaryArea = areasData[resource.areaTags[0]]; const primaryColor = primaryArea?.primaryColor || 'gray'; // Format date const formattedDate = new Date(resource.date).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); // Generate area tags const areaTagsHtml = resource.areaTags.map(areaId => { const area = areasData[areaId]; if (!area) return ''; return `${area.name}`; }).join(''); // Generate sub-area tags const subAreaTagsHtml = resource.subAreaTags.map(subAreaKey => { // Find the sub-area name and color by looking through all areas let subAreaName = subAreaKey; // fallback to key if not found let textColor = 'text-gray-700'; // fallback color for (const areaKey in areasData) { const area = areasData[areaKey]; if (area.subAreas && area.subAreas[subAreaKey]) { const subArea = area.subAreas[subAreaKey]; subAreaName = typeof subArea === 'string' ? subArea : subArea.name; // Extract just the text color from the sub-area color if (typeof subArea === 'object' && subArea.color) { const colorMatch = subArea.color.match(/text-(\w+)-(\d+)/); if (colorMatch) { textColor = `text-${colorMatch[1]}-700`; // Use consistent 700 shade } } break; } } return `${subAreaName}`; }).join(''); // Type badge const typeBadge = resource.type === 'dataset' ? 'Dataset' : 'Tool'; const typeColor = resource.type === 'dataset' ? 'bg-blue-100 text-blue-800' : 'bg-green-100 text-green-800'; return `
${resource.description}