|
| 1 | +--- |
| 2 | +import type { CollectionEntry } from 'astro:content' |
| 3 | +import FormattedDate from '../components/FormattedDate.astro' |
| 4 | +import type { MarkdownHeading, ImageMetadata } from 'astro' |
| 5 | +import TableOfContents from '../components/TableOfContents.astro' |
| 6 | +import dayjs from 'dayjs' |
| 7 | +import utc from 'dayjs/plugin/utc' |
| 8 | +
|
| 9 | +dayjs.extend(utc) |
| 10 | +
|
| 11 | +type Props = CollectionEntry<'blog'>['data'] & { |
| 12 | + headings: MarkdownHeading[] |
| 13 | + slug: string |
| 14 | + remarkPluginFrontmatter: Record<string, string> |
| 15 | +} |
| 16 | +
|
| 17 | +const { |
| 18 | + title, |
| 19 | + description, |
| 20 | + pubDate, |
| 21 | + updatedDate, |
| 22 | + coverImageCredit, |
| 23 | + headings, |
| 24 | + slug, |
| 25 | + remarkPluginFrontmatter, |
| 26 | +} = Astro.props |
| 27 | +
|
| 28 | +import BaseLayout from './BaseLayout.astro' |
| 29 | +import { Image } from 'astro:assets' |
| 30 | +import { Icon } from 'astro-icon/components' |
| 31 | +
|
| 32 | +const blogImages = import.meta.glob<{ default: ImageMetadata }>( |
| 33 | + '/src/assets/blogimages/**/*.{jpeg,jpg,png,gif}' |
| 34 | +) |
| 35 | +
|
| 36 | +const coverImagePath = `/src/assets/blogimages/${slug}/cover.jpg` |
| 37 | +
|
| 38 | +const lastModified = dayjs(remarkPluginFrontmatter.lastModified) |
| 39 | + .utc() |
| 40 | + .format('D MMM YYYY') |
| 41 | +--- |
| 42 | + |
| 43 | +<BaseLayout title={title} description={description}> |
| 44 | + <main> |
| 45 | + <article> |
| 46 | + <div |
| 47 | + class="app-container flex flex-col lg:flex-row-reverse justify-between gap-8 py-24 relative" |
| 48 | + > |
| 49 | + <div class="md:w-1/4 relative"> |
| 50 | + <div class="sticky top-0 md:top-28 hidden lg:block"> |
| 51 | + <TableOfContents headings={headings} /> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + <div class="grow w-full md:max-w-[75ch]"> |
| 55 | + <div> |
| 56 | + <h1 class="text-4xl sm:text-5xl leading-snug pt-12 font-bold"> |
| 57 | + {title} |
| 58 | + </h1> |
| 59 | + <div class="text-lg flex items-center gap-4 flex-wrap py-8"> |
| 60 | + <!-- Publish date --> |
| 61 | + <span> |
| 62 | + <Icon |
| 63 | + name="mdi:calendar-month-outline" |
| 64 | + class="inline-block text-primary dark:text-primary-dark" |
| 65 | + /> |
| 66 | + <FormattedDate date={pubDate} /> |
| 67 | + </span> |
| 68 | + |
| 69 | + <!-- Updated date --> |
| 70 | + { |
| 71 | + updatedDate && ( |
| 72 | + <span> |
| 73 | + <Icon |
| 74 | + name="mdi:calendar-refresh-outline" |
| 75 | + class="inline-block text-primary dark:text-primary-dark" |
| 76 | + /> |
| 77 | + Last updated on <FormattedDate date={updatedDate} /> |
| 78 | + </span> |
| 79 | + ) |
| 80 | + } |
| 81 | + |
| 82 | + <!-- Read time --> |
| 83 | + <span> |
| 84 | + <Icon |
| 85 | + name="mdi:clock-time-four-outline" |
| 86 | + class="inline-block text-primary dark:text-primary-dark" |
| 87 | + /> |
| 88 | + {remarkPluginFrontmatter.minutesRead} |
| 89 | + </span> |
| 90 | + </div> |
| 91 | + |
| 92 | + { |
| 93 | + blogImages[coverImagePath] && ( |
| 94 | + <> |
| 95 | + <Image |
| 96 | + src={blogImages[coverImagePath]()} |
| 97 | + alt={title} |
| 98 | + class="rounded-lg" |
| 99 | + /> |
| 100 | + {coverImageCredit && ( |
| 101 | + <p class="mt-2 mb-8 opacity-80 italic text-sm"> |
| 102 | + Image Credit: {coverImageCredit} |
| 103 | + </p> |
| 104 | + )} |
| 105 | + </> |
| 106 | + ) |
| 107 | + } |
| 108 | + </div> |
| 109 | + <div |
| 110 | + class="prose prose-neutral prose-lg md:prose-xl dark:prose-invert prose-img:rounded-xl prose-figure:text-center prose-img:mx-auto" |
| 111 | + > |
| 112 | + <slot /> |
| 113 | + </div> |
| 114 | + |
| 115 | + <!-- Suggest edit --> |
| 116 | + <div class="flex justify-between mt-16 gap-4 flex-wrap italic"> |
| 117 | + <a |
| 118 | + href={`https://github.com/yashjawale/yashjawale.github.io/edit/main/src/content/blog/${slug}.md`} |
| 119 | + target="_blank" |
| 120 | + rel="noopener noreferrer" |
| 121 | + class="hover:underline underline-offset-4 opacity-70 hover:opacity-100" |
| 122 | + ><Icon name="mdi:pencil-outline" class="inline-block" /> |
| 123 | + Suggest an edit |
| 124 | + </a> |
| 125 | + <p class="opacity-70"> |
| 126 | + Last modified: {lastModified} |
| 127 | + </p> |
| 128 | + </div> |
| 129 | + </div> |
| 130 | + </div> |
| 131 | + </article> |
| 132 | + </main> |
| 133 | +</BaseLayout> |
0 commit comments