diff --git a/src/model/howto.ts b/src/model/howto.ts index e956fa9..a17071a 100644 --- a/src/model/howto.ts +++ b/src/model/howto.ts @@ -157,7 +157,6 @@ const content = async (str: string, filters: FilterFunction[] = default_filters) const to_github = async (item: IHowto) => { const itemDir = item_path(item) - mkdir(itemDir) // Create README.md with all content const readmeContent = [ @@ -233,6 +232,55 @@ const to_mdx = async (item: IHowto) => { write(path.join(itemDir, 'index.mdx'), mdxContent) } +const to_astro = async (item: IHowto) => { + const itemDir = item_path(item) + mkdir(itemDir) + + // Create index.astro with all content + const astroContent = [ + '---', + `import { Image } from 'astro:assets'`, + `import Layout from '../../layouts/Layout.astro'`, + '', + `const { frontmatter } = Astro.props`, + '', + `const title = "${item.title}"`, + `const description = "${item.description}"`, + `const tags = ${JSON.stringify(item.tags)}`, + `const category = "${item.category?.label || 'uncategorized'}"`, + `const difficulty = "${item.difficulty_level}"`, + `const time = "${item.time}"`, + `const location = "${item.user?.geo ? `${item.user.geo.city ? `${item.user.geo.city}, ` : ''}${item.user.geo.countryName || ''}` : ''}"`, + '---', + '', + ``, + '
', + `

{title}

`, + '', + item.cover_image ? ` {title}` : '', + '', + `
`, + `

{description}

`, + item.user?.geo ? `

User Location: ${item.user.geo.city ? `${item.user.geo.city}, ` : ''}${item.user.geo.countryName || ''}

` : '', + `
`, + '', + '
', + ...item.steps.map((step, index) => [ + `
`, + `

Step ${index + 1}: ${step.title}

`, + `
`, + ` `, + `
`, + // Add step images if any using Astro's Image component + ...step.images.map(img => ` ${img.name}`) + ].join('\n')), + '
', + '
', + '
' + ].filter(Boolean).join('\n') + write(path.join(itemDir, 'index.astro'), astroContent) +} + const complete = async (item: IHowto) => { if (!HOWTO_ANNOTATIONS) { // return item @@ -273,7 +321,8 @@ const complete = async (item: IHowto) => { await to_github(item) await to_mdx(item) - + await to_astro(item) + return item }