this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

✨ Allow markdown in tag/tech/coll descriptions (Closes #4)

Signed-off-by: Gwenn Le Bihan <gwenn.lebihan7@gmail.com>

+74 -24
+2 -2
src/aliases.ts
··· 6 6 * @returns the aliases array for that aliased entry 7 7 */ 8 8 export function makeAliasEntries< 9 - Entry extends { aliases: string[]; slug: string }, 9 + Entry extends { aliases?: string[] | undefined; slug?: string | undefined }, 10 10 >(entry: Entry) { 11 11 return [ 12 12 entry, 13 - ...entry.aliases.map((alias) => ({ 13 + ...(entry.aliases ?? []).map((alias) => ({ 14 14 ...entry, 15 15 slug: alias, 16 16 aliases: [IS_ALIAS_TAG, entry.slug],
+47 -13
src/content.config.ts
··· 5 5 import PO from "pofile"; 6 6 import { makeAliasEntries } from "./aliases"; 7 7 import { wakatimeCollection } from "./wakatime"; 8 + import { readFile } from "node:fs/promises"; 9 + import slug from "slug"; 8 10 9 11 const translatedString = z.object({ 10 12 en: z.string(), ··· 226 228 ) { 227 229 return defineCollection({ 228 230 schema, 229 - loader: file(filename, { 230 - parser(content) { 231 - const parsed = YAML.parse(content); 231 + loader: { 232 + name: "YAML Loader", 233 + async load({ renderMarkdown, store }) { 234 + const raw = await readFile(filename); 235 + const parsed: Array<z.infer<Schema>> | Record<string, z.infer<Schema>> = 236 + YAML.parse(raw.toString()); 237 + 232 238 if (Array.isArray(parsed)) { 233 - const out = parsed 239 + const entries = parsed 234 240 .map((data) => { 235 - const out = { ...data }; 241 + const out: z.infer<Schema> & { 242 + slug?: string; 243 + aliases?: string[]; 244 + } = { ...data }; 245 + 236 246 if (slugify) out.slug ??= slugify(data); 237 247 238 248 const aliasable = z ··· 243 253 .safeParse(out); 244 254 245 255 if (aliasable.success || additionalAliases) { 256 + out.aliases ??= []; 246 257 if (additionalAliases) { 247 - out.aliases = [ 248 - ...(out.aliases ?? []), 249 - ...additionalAliases(data), 250 - ]; 258 + out.aliases = [...out.aliases, ...additionalAliases(data)]; 251 259 } 252 260 return makeAliasEntries(out); 253 261 } ··· 256 264 }) 257 265 .flat(); 258 266 259 - return out; 267 + store.clear(); 268 + for (const entry of entries) { 269 + store.set({ 270 + id: entry.slug ?? slug(entry.title), 271 + data: entry, 272 + rendered: await renderMarkdown( 273 + "description" in entry 274 + ? typeof entry.description === "string" 275 + ? entry.description 276 + : entry.description[process.env.LANG === "fr" ? "fr" : "en"] 277 + : "", 278 + ), 279 + }); 280 + } 281 + } else { 282 + store.clear(); 283 + for (const [key, data] of Object.entries(parsed)) { 284 + store.set({ 285 + id: key, 286 + data: data as z.infer<Schema>, 287 + rendered: await renderMarkdown( 288 + "description" in data 289 + ? typeof data.description === "string" 290 + ? data.description 291 + : data.description[process.env.LANG === "fr" ? "fr" : "en"] 292 + : "", 293 + ), 294 + }); 295 + } 260 296 } 261 - 262 - return parsed; 263 297 }, 264 - }), 298 + }, 265 299 }); 266 300 } 267 301
+6 -4
src/pages/collections/[collection].astro
··· 51 51 --- 52 52 53 53 <Layout> 54 - <StrongHeader title={title}> 55 - <p> 56 - <Translated {...description} /> 57 - </p> 54 + <StrongHeader 55 + back="/" 56 + title={title} 57 + editButton="~/projects.local/portfolio/collections.yaml" 58 + > 59 + <div set:html={entry.rendered!.html} /> 58 60 </StrongHeader> 59 61 60 62 <WorksGrid works={works} />
+6 -2
src/pages/tags/[tag].astro
··· 33 33 --- 34 34 35 35 <Layout> 36 - <StrongHeader title={plural}> 36 + <StrongHeader 37 + back="/" 38 + title={plural} 39 + editButton="~/projects.local/portfolio/tags.yaml" 40 + > 37 41 <section class="description"> 38 - <p>{description}</p> 42 + <div i18n class="description" set:html={entry.rendered!.html} /> 39 43 { 40 44 learnMoreAt && ( 41 45 <a href={learnMoreAt} class="learn-more" i18n>
+13 -3
src/pages/using/[tech].astro
··· 28 28 --- 29 29 30 30 <Layout> 31 - <StrongHeader back="/" title={tech.data.name}> 32 - <p i18n>{tech.data.description}</p> 33 - <a i18n href={tech.data["learn more at"]}>learn more</a> 31 + <StrongHeader 32 + back="/" 33 + title={tech.data.name} 34 + editButton="~/projects.local/portfolio/technologies.yaml" 35 + > 36 + <div class="description" i18n set:html={tech.rendered!.html} /> 37 + { 38 + tech.data["learn more at"] && ( 39 + <a i18n href={tech.data["learn more at"]}> 40 + learn more 41 + </a> 42 + ) 43 + } 34 44 </StrongHeader> 35 45 36 46 <WorksGrid works={works} />