import { getCollection, type CollectionEntry } from "astro:content"; import { TOPOLOGY_PAGE_PROFILES } from "../config/topologyPageProfiles"; import { createPresentationTopology } from "../framework/topologyLayouts.ts"; import { createHexGrid, getGridBounds } from "./hex"; interface PersonalKnowledgeNode { id: string; label: string; subtitle?: string; q: number; r: number; variant: string; size: string; active: boolean; selected: boolean; disabled?: boolean; href?: string; } interface PersonalKnowledgeEdge { from: string; to: string; kind: string; active: boolean; muted: boolean; } type PagesEntry = CollectionEntry<"pages">; interface PersonalKnowledgeRecord { id: string; eyebrow: string; title: string; subtitle: string; summary: string; details: string[]; meta: string[]; group: string; kind: "page" | "anchor" | "link"; links: Array<{ id: string; label: string; subtitle: string }>; } function entryById(entries: PagesEntry[], id: string) { return entries.find((entry) => entry.id === id); } function toList(value: unknown) { return Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : []; } function pageRecord(entry: PagesEntry, group: string): PersonalKnowledgeRecord { const details = toList(entry.data.details); const meta = toList(entry.data.meta); return { id: entry.id, eyebrow: entry.data.eyebrow ?? "Page", title: entry.data.title, subtitle: entry.data.subtitle ?? entry.data.summary ?? "", summary: entry.data.summary, details, meta, group, kind: "page", links: [], }; } function pageRecordOrFallback(entry: PagesEntry | undefined, group: string, fallback: PersonalKnowledgeRecord) { return entry ? pageRecord(entry, group) : fallback; } function anchorRecord(id: string, title: string, subtitle: string, group: string, details: string[], links: PersonalKnowledgeRecord["links"] = []) { return { id, eyebrow: "Anchor", title, subtitle, summary: subtitle, details, meta: [group], group, kind: "anchor", links, } satisfies PersonalKnowledgeRecord; } function linkRecord(id: string, title: string, subtitle: string, href: string, group: string) { return { id, eyebrow: "Link", title, subtitle, summary: href, details: [`Open ${title.toLowerCase()} as a supporting page or destination.`], meta: [group, href], group, kind: "link", links: [], } satisfies PersonalKnowledgeRecord; } export async function createPersonalKnowledgeSceneTopology() { const personalProfile = TOPOLOGY_PAGE_PROFILES.personalKnowledge; const personalRadius = personalProfile.scene.radius; const personalCells = createHexGrid({ radius: personalRadius, columns: personalProfile.scene.columns, rows: personalProfile.scene.rows, originQ: personalProfile.scene.originQ, originR: personalProfile.scene.originR, }); const personalBounds = getGridBounds(personalCells, personalRadius); const pages = await getCollection("pages"); const gh = entryById(pages, "gh"); const about = entryById(pages, "about"); const cv = entryById(pages, "cv"); const overview = entryById(pages, "overview"); const experience = entryById(pages, "experience"); const education = entryById(pages, "education"); const journal = entryById(pages, "journal"); const organizations = entryById(pages, "organizations"); const rootNode: PersonalKnowledgeNode = { id: gh?.id ?? "gh", label: gh?.data.title ?? "GH", subtitle: gh?.data.subtitle ?? "Genaro Hernández", q: 0, r: 0, variant: "root", size: "root", active: true, selected: true, }; const anchorNodes: PersonalKnowledgeNode[] = [ { id: "personal-profile-anchor", label: "Profile", subtitle: "About, CV, identity", q: -6, r: 0, variant: "anchor", size: "lg", active: false, selected: false, }, { id: "personal-work-anchor", label: "Work", subtitle: "Experience, education, organizations", q: 6, r: 0, variant: "anchor", size: "lg", active: false, selected: false, }, { id: "personal-current-anchor", label: "Current", subtitle: "Now, focus, goals, learning", q: 6, r: -6, variant: "anchor", size: "lg", active: false, selected: false, }, { id: "personal-writing-anchor", label: "Writing", subtitle: "Journal and notes", q: 0, r: -6, variant: "anchor", size: "lg", active: false, selected: false, }, { id: "personal-links-anchor", label: "Links", subtitle: "Paths and destinations", q: 0, r: 6, variant: "anchor", size: "lg", active: false, selected: false, }, ]; const profileNodes: PersonalKnowledgeNode[] = [ { id: about?.id ?? "about", label: about?.data.title ?? "About Me", subtitle: about?.data.summary ?? "Profile node", q: -9, r: -2, variant: "node", size: "md", active: false, selected: false, href: about?.data.href ?? "#about", }, { id: cv?.id ?? "cv", label: cv?.data.title ?? "CV", subtitle: cv?.data.summary ?? "Reference node", q: -9, r: 2, variant: "node", size: "md", active: false, selected: false, href: cv?.data.href ?? "#cv", }, ]; const workNodes: PersonalKnowledgeNode[] = [ { id: experience?.id ?? "experience", label: experience?.data.title ?? "Experience", subtitle: experience?.data.summary ?? "History node", q: 8, r: -2, variant: "node", size: "md", active: false, selected: false, href: experience?.data.href ?? "#experience", }, { id: education?.id ?? "education", label: education?.data.title ?? "Education", subtitle: education?.data.summary ?? "Learning node", q: 8, r: 2, variant: "node", size: "md", active: false, selected: false, href: education?.data.href ?? "#education", }, { id: organizations?.id ?? "organizations", label: organizations?.data.title ?? "Organizations", subtitle: organizations?.data.summary ?? "Ecosystem node", q: 10, r: 0, variant: "node", size: "md", active: false, selected: false, href: organizations?.data.href ?? "#organizations", }, ]; const currentNodes: PersonalKnowledgeNode[] = [ { id: overview?.id ?? "overview", label: overview?.data.title ?? "Overview", subtitle: overview?.data.summary ?? "Current state", q: 6, r: -8, variant: "primary", size: "lg", active: false, selected: false, href: overview?.data.href ?? "/overview", }, { id: "now", label: "Now", subtitle: "What is active", q: 8, r: -10, variant: "reference", size: "sm", active: false, selected: false, disabled: true, }, { id: "focus", label: "Focus", subtitle: "What gets attention", q: 4, r: -10, variant: "reference", size: "sm", active: false, selected: false, disabled: true, }, { id: "goals", label: "Goals", subtitle: "What comes next", q: 10, r: -8, variant: "reference", size: "sm", active: false, selected: false, disabled: true, }, { id: "learning", label: "Learning", subtitle: "What is expanding", q: 6, r: -12, variant: "reference", size: "sm", active: false, selected: false, disabled: true, }, ]; const writingNodes: PersonalKnowledgeNode[] = [ { id: journal?.id ?? "journal", label: journal?.data.title ?? "Journal", subtitle: journal?.data.summary ?? "Writing node", q: 0, r: -8, variant: "node", size: "md", active: false, selected: false, href: journal?.data.href ?? "#journal", }, ]; const linkNodes: PersonalKnowledgeNode[] = [ { id: "personal-link-lab", label: "Lab", subtitle: "Topology sandbox", q: 0, r: 8, variant: "reference", size: "sm", active: false, selected: false, href: "/lab", }, { id: "personal-link-world-map", label: "World Map", subtitle: "Main topology view", q: 2, r: 8, variant: "reference", size: "sm", active: false, selected: false, href: "/world-map", }, { id: "personal-link-animation-lab", label: "Animation Lab", subtitle: "Motion testing", q: -2, r: 8, variant: "reference", size: "sm", active: false, selected: false, href: "/animation-lab", }, ]; const personalLayout = createPresentationTopology({ id: "personal-knowledge", title: rootNode.label, subtitle: rootNode.subtitle, summary: gh?.data.summary ?? "Personal knowledge topology.", status: "ready", route: "/personal-knowledge", role: "knowledge", sceneLayout: personalProfile.scene.layout, topologyLayout: personalProfile.scene.topologyLayout, anchors: [ { id: "profile", label: "Profile", subtitle: "About, CV, identity", children: profileNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle, })), }, { id: "work", label: "Work", subtitle: "Experience, education, organizations", children: workNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle, })), }, { id: "current", label: "Current", subtitle: "Now, focus, goals, learning", children: currentNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle, })), }, { id: "writing", label: "Writing", subtitle: "Journal and notes", children: writingNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle, })), }, { id: "links", label: "Links", subtitle: "Paths and destinations", children: linkNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle, })), }, ], }); const personalLayoutNodes = personalLayout.nodes; rootNode.q = personalLayoutNodes[0]?.q ?? rootNode.q; rootNode.r = personalLayoutNodes[0]?.r ?? rootNode.r; anchorNodes.forEach((node, index) => { const position = personalLayoutNodes[1 + index]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; }); let personalLayoutIndex = 1 + anchorNodes.length; for (const node of profileNodes) { const position = personalLayoutNodes[personalLayoutIndex++]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; } for (const node of workNodes) { const position = personalLayoutNodes[personalLayoutIndex++]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; } for (const node of currentNodes) { const position = personalLayoutNodes[personalLayoutIndex++]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; } for (const node of writingNodes) { const position = personalLayoutNodes[personalLayoutIndex++]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; } for (const node of linkNodes) { const position = personalLayoutNodes[personalLayoutIndex++]; node.q = position?.q ?? node.q; node.r = position?.r ?? node.r; } const topologyNodes = [ rootNode, ...anchorNodes, ...profileNodes, ...workNodes, ...currentNodes, ...writingNodes, ...linkNodes, ]; const topologyEdges: PersonalKnowledgeEdge[] = [ { from: rootNode.id, to: anchorNodes[0].id, kind: "contains", active: true, muted: false }, { from: rootNode.id, to: anchorNodes[1].id, kind: "contains", active: true, muted: false }, { from: rootNode.id, to: anchorNodes[2].id, kind: "contains", active: true, muted: false }, { from: rootNode.id, to: anchorNodes[3].id, kind: "contains", active: true, muted: false }, { from: rootNode.id, to: anchorNodes[4].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[0].id, to: profileNodes[0].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[0].id, to: profileNodes[1].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[1].id, to: workNodes[0].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[1].id, to: workNodes[1].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[1].id, to: workNodes[2].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[2].id, to: currentNodes[0].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[3].id, to: writingNodes[0].id, kind: "contains", active: true, muted: false }, { from: anchorNodes[4].id, to: linkNodes[0].id, kind: "contains", active: false, muted: true }, { from: anchorNodes[4].id, to: linkNodes[1].id, kind: "contains", active: false, muted: true }, { from: anchorNodes[4].id, to: linkNodes[2].id, kind: "contains", active: false, muted: true }, ]; const rootFallback: PersonalKnowledgeRecord = { id: "gh", eyebrow: "Root", title: "GH", subtitle: "Genaro Hernández", summary: "Root anchor and stable reference point for the topology.", details: ["This node anchors the topology and keeps orientation stable."], meta: ["Origin", "Persistent", "Top-level"], group: "Root", kind: "anchor", links: [], }; const records: PersonalKnowledgeRecord[] = [ pageRecordOrFallback(gh, "Root", rootFallback), pageRecordOrFallback(about, "Profile", anchorRecord("about", "About Me", "Profile layer", "Profile", ["Personal identity and reference nodes."], [])), pageRecordOrFallback(cv, "Profile", anchorRecord("cv", "CV", "Reference layer", "Profile", ["Compact resume-style view."], [])), pageRecordOrFallback(overview, "Current", anchorRecord("overview", "Overview", "Current snapshot", "Current", ["Current state and active focus."], [])), pageRecordOrFallback(experience, "Work", anchorRecord("experience", "Experience", "Work history", "Work", ["Professional history and supporting references."], [])), pageRecordOrFallback(education, "Work", anchorRecord("education", "Education", "Learning history", "Work", ["Courses, certifications, and technical study."], [])), pageRecordOrFallback(organizations, "Work", anchorRecord("organizations", "Organizations", "Ecosystem references", "Work", ["Organizations and case-study environments."], [])), pageRecordOrFallback(journal, "Writing", anchorRecord("journal", "Journal", "Notes and context", "Writing", ["Longer-form notes and reflections."], [])), anchorRecord("personal-profile-anchor", "Profile", "About, CV, identity", "Profile", ["Personal identity and reference nodes.", "The closest layer to the root."], profileNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" }))), anchorRecord("personal-work-anchor", "Work", "Experience, education, organizations", "Work", ["Professional history and supporting references.", "How the work branch expands from the profile."], workNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" }))), anchorRecord("personal-current-anchor", "Current", "Now, focus, goals, learning", "Current", ["The active context layer.", "What is currently important, being learned, or emphasized."], currentNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" }))), anchorRecord("personal-writing-anchor", "Writing", "Journal and notes", "Writing", ["Longer-form notes and reflections.", "A place for exploratory and written context."], writingNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" }))), anchorRecord("personal-links-anchor", "Links", "Paths and destinations", "Links", ["Quick access to related destinations.", "This group supports navigation, not authored content."], linkNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" }))), linkRecord("personal-link-lab", "Lab", "Topology sandbox", "/lab", "Links"), linkRecord("personal-link-world-map", "World Map", "Main topology view", "/world-map", "Links"), linkRecord("personal-link-animation-lab", "Animation Lab", "Motion testing", "/animation-lab", "Links"), linkRecord("now", "Now", "What is active", "current-state", "Current"), linkRecord("focus", "Focus", "What gets attention", "attention-state", "Current"), linkRecord("goals", "Goals", "What comes next", "goal-state", "Current"), linkRecord("learning", "Learning", "What is expanding", "learning-state", "Current"), ]; const recordsById = Object.fromEntries(records.map((record) => [record.id, record])); const selectorGroups = [ { label: "Root", options: [{ id: rootNode.id, label: rootNode.label, subtitle: rootNode.subtitle ?? "" }] }, { label: "Profile", options: profileNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" })) }, { label: "Work", options: workNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" })) }, { label: "Current", options: currentNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" })) }, { label: "Writing", options: writingNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" })) }, { label: "Links", options: linkNodes.map((node) => ({ id: node.id, label: node.label, subtitle: node.subtitle ?? "" })) }, ]; const selectedId = rootNode.id; const dashboardJson = JSON.stringify({ nodes: topologyNodes, relationships: topologyEdges, records, selectedId, }); return { personalProfile, personalRadius, personalCells, personalBounds, nodes: topologyNodes, edges: topologyEdges, records, recordsById, selectedId, selectedRecord: recordsById[selectedId] ?? records[0], dashboardJson, selectorGroups, rootNode, anchorNodes, profileNodes, workNodes, currentNodes, writingNodes, linkNodes, }; }