Skip to content

Commit a1b7332

Browse files
committed
feat: add heroImage support to blog posts
Currently has two bugs: 1. For the image to work with `meta` tags, it needs to live in `public`. And/or, for it to work with Markdown, it needs to live in `public`. I tried using relative paths to no avail. I didn't see much info in the docs about including relative images from Markdown. Since it lives in `public`, it's treated as a _remote_ image by the `@astrojs/image` plugin [[1]]. This means we need to include an `aspectRatio`, which means we would need to make all blog posts have heroImages with equal ratios. The first image I threw in here uses a nonsensical ratio, because I did not understand this limitation when I made it. 2. The `Picture` component always adds a `height` attribute to the rendered element. The content has a max-width of about 800px, but I wanted to use a 1200px-wide image so it would look nicer on high-density displays. I'm not sure this is even optimized, but even if not, the resulting bug will still show up: The image ends up looking all squashed! The max-width of the image is the width of the content, while the `height` attribute sets something corresponding to the (hypothetical) `width` attribute. Since actual width is narrower than this `1200px`, the height ends up mismatching. If there were a way to remove this attribute from the rendered element, it would look great! [1]: https://docs.astro.build/en/guides/integrations-guide/image/#src-1
1 parent df66e94 commit a1b7332

File tree

7 files changed

+770
-14
lines changed

7 files changed

+770
-14
lines changed

astro.config.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { defineConfig } from 'astro/config';
22
import mdx from '@astrojs/mdx';
33
import { addLayoutToBlogPosts, remarkReadingTime } from './markdown-extensions.mjs';
4-
54
import sitemap from '@astrojs/sitemap';
65

6+
import image from "@astrojs/image";
7+
78
// https://astro.build/config
89
export default defineConfig({
9-
site: 'https://ahalabs.dev',
10-
integrations: [mdx(), sitemap()],
11-
markdown: {
12-
remarkPlugins: [addLayoutToBlogPosts, remarkReadingTime],
13-
extendDefaultPlugins: true,
14-
}
10+
site: 'https://ahalabs.dev',
11+
integrations: [mdx(), sitemap(), image({
12+
serviceEntryPoint: '@astrojs/image/sharp',
13+
})],
14+
markdown: {
15+
remarkPlugins: [addLayoutToBlogPosts, remarkReadingTime],
16+
extendDefaultPlugins: true
17+
}
1518
});

0 commit comments

Comments
 (0)