[Archived] Archived WIP of vielle.dev

Update how navList entries are defined and read.

vielle.dev c8a646c4 a17437ae

verified
Changed files
+76 -63
src
components
content
+3 -2
src/components/generic/Nav.astro
··· 2 2 import NavEntry from "./NavEntry.astro"; 3 3 import Hamburger from "@/assets/hamburger.svg"; 4 4 import X from "@/assets/x.svg"; 5 - import { getCollection } from "astro:content"; 5 + import { getEntry } from "astro:content"; 6 6 7 7 interface Props { 8 8 current: string; ··· 10 10 11 11 const { current } = Astro.props; 12 12 13 - const data = await getCollection("nav").then((x) => x.map((x) => x.data)); 13 + const data = (await getEntry("nav", "urls")?.then((x) => x.data)) ?? []; 14 + console.log(data); 14 15 --- 15 16 16 17 <button
+4 -7
src/components/generic/NavEntry.astro
··· 13 13 { 14 14 data.map((x) => ( 15 15 <li> 16 - {x.slug ? ( 17 - <a href={`${root}${x.slug}`}>{x.name}</a> 16 + {x.url ? ( 17 + <a href={`${root}${x.url}`}>{x.name}</a> 18 18 ) : ( 19 19 <span>{x.name}</span> 20 20 )} 21 - {x.children && x.children.length > 0 ? ( 22 - <Astro.self 23 - root={`${root}${x.slug ? x.slug : ""}`} 24 - data={x.children} 25 - /> 21 + {x.children ? ( 22 + <Astro.self root={`${root}${x.url ? x.url : ""}`} data={x.children} /> 26 23 ) : null} 27 24 </li> 28 25 ))
+11 -10
src/content/config.ts
··· 28 28 }), 29 29 }); 30 30 31 - const baseNav = z.object({ 32 - slug: z.string().or(z.literal(false)), 33 - name: z.string(), 34 - }); 35 - 36 - export type nav = z.infer<typeof baseNav> & { 31 + export type nav = { 32 + name: string; 33 + url: string | false; 37 34 children?: nav[]; 38 35 }; 39 36 40 - const navSchema: z.ZodType<nav> = baseNav.extend({ 41 - children: z.lazy(() => navSchema.array()), 42 - }); 37 + const navSchema: z.ZodType<nav> = z.lazy(() => 38 + z.object({ 39 + name: z.string(), 40 + url: z.string().or(z.literal(false)), 41 + children: z.optional(z.array(navSchema)), 42 + }), 43 + ); 43 44 44 45 const nav = defineCollection({ 45 46 loader: file("src/content/navList.json"), 46 - schema: navSchema, 47 + schema: z.array(navSchema), 47 48 }); 48 49 49 50 export const collections = { blog, blogMdx, nav };
+58 -44
src/content/navList.json
··· 1 - [ 2 - { 3 - "slug": "/", 4 - "name": "Home", 5 - "children": [] 6 - }, 7 - { 8 - "slug": "/blog", 9 - "name": "Blog", 10 - "children": [] 11 - }, 12 - { 13 - "slug": false, 14 - "name": "Socials", 15 - "children": [ 16 - { 17 - "slug": "https://pdsls.dev/at://did:plc:4zht3z4caxwrw3dlsybodywc", 18 - "name": "atproto (pdsls)", 19 - "children": [ 20 - { 21 - "slug": "https://deer.social/profile/did:plc:4zht3z4caxwrw3dlsybodywc", 22 - "name": "Bluesky", 23 - "children": [] 24 - }, 25 - { 26 - "slug": "https://tangled.sh/@vielle.dev", 27 - "name": "Tangled.sh", 28 - "children": [] 29 - } 30 - ] 31 - }, 32 - { 33 - "slug": "https://what-if-doctor-who-was-yuri-yaoi.tumblr.com/", 34 - "name": "Tumblr", 35 - "children": [] 36 - }, 37 - { 38 - "slug": "https://github.com/afterlifepro/", 39 - "name": "Github", 40 - "children": [] 41 - } 42 - ] 43 - } 44 - ] 1 + { 2 + "urls": [ 3 + { 4 + "url": "/", 5 + "name": "Home" 6 + }, 7 + { 8 + "url": "/blog", 9 + "name": "Blog" 10 + }, 11 + { 12 + "url": false, 13 + "name": "Socials", 14 + "children": [ 15 + { 16 + "url": "https://pdsls.dev/at://did:plc:4zht3z4caxwrw3dlsybodywc", 17 + "name": "atproto (pdsls)", 18 + "children": [ 19 + { 20 + "url": "https://deer.social/profile/did:plc:4zht3z4caxwrw3dlsybodywc", 21 + "name": "Bluesky" 22 + }, 23 + { 24 + "url": "https://tangled.sh/@vielle.dev", 25 + "name": "Tangled.sh" 26 + } 27 + ] 28 + }, 29 + { 30 + "url": "https://what-if-doctor-who-was-yuri-yaoi.tumblr.com/", 31 + "name": "Tumblr" 32 + }, 33 + { 34 + "url": "https://github.com/afterlifepro/", 35 + "name": "Github" 36 + } 37 + ] 38 + }, 39 + { 40 + "url": false, 41 + "name": "Projects", 42 + "children": [ 43 + { 44 + "url": "https://dong.vielle.dev", 45 + "name": "Dong (web)" 46 + }, 47 + { 48 + "url": "https://saltire-the-gays.vielle.dev", 49 + "name": "Saltire the Gays" 50 + }, 51 + { 52 + "url": "https://afterlifepro.neocities.org", 53 + "name": "Neocities (old site)" 54 + } 55 + ] 56 + } 57 + ] 58 + }