| 1 |
import {defineCollection, z} from "astro:content"; |
| 2 |
import {glob, file} from "astro/loaders"; |
| 3 |
import {slugify} from "./lib/utils"; |
| 4 |
import yaml from "js-yaml"; |
| 5 |
|
| 6 |
const home = defineCollection({ |
| 7 |
loader: glob({base: "./src/content", pattern: "index.mdx"}), |
| 8 |
schema: z.object({ |
| 9 |
title: z.string(), |
| 10 |
description: z.string(), |
| 11 |
}).strict(), |
| 12 |
}); |
| 13 |
|
| 14 |
const about = defineCollection({ |
| 15 |
loader: glob({base: "./src/content", pattern: "about.mdx"}), |
| 16 |
schema: z.object({ |
| 17 |
title: z.string(), |
| 18 |
description: z.string().optional(), |
| 19 |
}).strict(), |
| 20 |
}); |
| 21 |
|
| 22 |
const docs = defineCollection({ |
| 23 |
loader: glob({base: "./src/content", pattern: "docs.mdx"}), |
| 24 |
schema: z.object({ |
| 25 |
title: z.string(), |
| 26 |
description: z.string().optional(), |
| 27 |
thumbnail: z.string().optional(), |
| 28 |
keywords: z.array(z.string()).optional(), |
| 29 |
includeMockServer: z.boolean().optional(), |
| 30 |
}).strict(), |
| 31 |
}); |
| 32 |
|
| 33 |
const reference = defineCollection({ |
| 34 |
loader: glob({base: "./src/content/reference", pattern: "{*.md,**/*.md}"}), |
| 35 |
schema: z.object({ |
| 36 |
title: z.string(), |
| 37 |
description: z.string().optional(), |
| 38 |
keywords: z.array(z.string()).optional(), |
| 39 |
thumbnail: z.string().optional(), |
| 40 |
hidden: z.boolean().optional(), |
| 41 |
includeMockServer: z.boolean().optional(), |
| 42 |
}).strict(), |
| 43 |
}); |
| 44 |
|
| 45 |
const extensions = defineCollection({ |
| 46 |
loader: glob({base: "./src/content/extensions", pattern: "{*.md,*.mdx,**/*.md,**/*.mdx}"}), |
| 47 |
schema: z.object({ |
| 48 |
title: z.string(), |
| 49 |
description: z.string().optional(), |
| 50 |
keywords: z.array(z.string()).optional(), |
| 51 |
thumbnail: z.string().optional(), |
| 52 |
category: z.enum(['Networking', 'Performance', 'UX', 'Swap behaviors', 'Compatibility', 'Security']).optional(), |
| 53 |
icon: z.string().optional(), |
| 54 |
includeMockServer: z.boolean().optional(), |
| 55 |
}).strict(), |
| 56 |
}); |
| 57 |
|
| 58 |
const patterns = defineCollection({ |
| 59 |
loader: glob({base: "./src/content/patterns", pattern: "{*.md,*.mdx,**/*.md,**/*.mdx}"}), |
| 60 |
schema: z.object({ |
| 61 |
title: z.string(), |
| 62 |
description: z.string().optional(), |
| 63 |
keywords: z.array(z.string()).optional(), |
| 64 |
thumbnail: z.string().optional(), |
| 65 |
icon: z.string().optional(), |
| 66 |
soon: z.boolean().optional(), |
| 67 |
includeMockServer: z.boolean().optional(), |
| 68 |
}).strict(), |
| 69 |
}); |
| 70 |
|
| 71 |
const essays = defineCollection({ |
| 72 |
loader: glob({base: "./src/content/essays", pattern: ["{*.md,*.mdx,**/*.md,**/*.mdx}", "!index.mdx"]}), |
| 73 |
schema: z.object({ |
| 74 |
title: z.string(), |
| 75 |
description: z.string().optional(), |
| 76 |
created: z.date().optional(), |
| 77 |
modified: z.date().optional(), |
| 78 |
authors: z.array(z.string()).min(1), |
| 79 |
tags: z.array(z.enum(['foundations', 'the-case-for-hypermedia', 'case-studies', 'guides', 'simplicity', 'counterpoints'])).optional(), |
| 80 |
keywords: z.array(z.string()).optional(), |
| 81 |
includeMockServer: z.boolean().optional(), |
| 82 |
}).strict(), |
| 83 |
}); |
| 84 |
|
| 85 |
const interviews = defineCollection({ |
| 86 |
loader: glob({base: "./src/content/interviews", pattern: "{*.md,*.mdx,**/*.md,**/*.mdx}"}), |
| 87 |
schema: z.object({ |
| 88 |
title: z.string(), |
| 89 |
description: z.string().optional(), |
| 90 |
created: z.date().optional(), |
| 91 |
modified: z.date().optional(), |
| 92 |
authors: z.array(z.string()).optional(), |
| 93 |
keywords: z.array(z.string()).optional(), |
| 94 |
includeMockServer: z.boolean().optional(), |
| 95 |
}).strict(), |
| 96 |
}); |
| 97 |
|
| 98 |
const sponsors = defineCollection({ |
| 99 |
loader: file('src/content/sponsors.yaml', { |
| 100 |
parser: (fileContent) => (yaml.load(fileContent)).map((sponsor) => ( |
| 101 |
{ |
| 102 |
...sponsor, |
| 103 |
id: slugify(sponsor.name), |
| 104 |
url: sponsor.tracking !== false |
| 105 |
? `${sponsor.url}?utm_source=htmx&utm_medium=sponsorship&utm_campaign=${sponsor.tier}-sponsor-${new Date().getFullYear()}` |
| 106 |
: sponsor.url, |
| 107 |
})) |
| 108 |
}), |
| 109 |
schema: z.object({ |
| 110 |
id: z.string(), |
| 111 |
name: z.string(), |
| 112 |
url: z.string().url(), |
| 113 |
github: z.string().optional(), |
| 114 |
image: z.string(), |
| 115 |
tier: z.enum(['bronze', 'silver', 'gold', 'platinum']), |
| 116 |
tracking: z.boolean().default(true), |
| 117 |
}).strict(), |
| 118 |
}); |
| 119 |
|
| 120 |
const links = defineCollection({ |
| 121 |
loader: file('src/content/links.yaml', { |
| 122 |
parser: (fileContent) => { |
| 123 |
const data = (yaml.load(fileContent)); |
| 124 |
return [{ id: 'links', ...data }]; |
| 125 |
} |
| 126 |
}), |
| 127 |
schema: z.object({ |
| 128 |
id: z.string(), |
| 129 |
header: z.array(z.object({ |
| 130 |
name: z.string(), |
| 131 |
url: z.string(), |
| 132 |
})), |
| 133 |
footer: z.array(z.object({ |
| 134 |
name: z.string(), |
| 135 |
url: z.string(), |
| 136 |
iconClass: z.string(), |
| 137 |
boost: z.boolean().optional(), |
| 138 |
})), |
| 139 |
social: z.array(z.object({ |
| 140 |
name: z.string(), |
| 141 |
description: z.string(), |
| 142 |
iconClass: z.string(), |
| 143 |
url: z.string(), |
| 144 |
})), |
| 145 |
}).strict(), |
| 146 |
}) |
| 147 |
|
| 148 |
|
| 149 |
const team = defineCollection({ |
| 150 |
loader: file('src/content/team.yaml', { |
| 151 |
parser: (fileContent) => (yaml.load(fileContent)).map((member) => ({ |
| 152 |
...member, |
| 153 |
id: slugify(member.name) |
| 154 |
})) |
| 155 |
}), |
| 156 |
schema: ({image}) => z.object({ |
| 157 |
id: z.string(), |
| 158 |
name: z.string(), |
| 159 |
image: image(), |
| 160 |
github: z.string().optional(), |
| 161 |
url: z.string().url().optional(), |
| 162 |
content: z.string(), |
| 163 |
}).passthrough(), |
| 164 |
}) |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
export const collections = { |
| 169 |
home, |
| 170 |
about, |
| 171 |
docs, |
| 172 |
reference, |
| 173 |
extensions, |
| 174 |
patterns, |
| 175 |
essays, |
| 176 |
interviews, |
| 177 |
sponsors, |
| 178 |
links, |
| 179 |
team, |
| 180 |
}; |