Skip to content

Commit 08a8990

Browse files
authored
Propagate consumer fixes: MDXInstance PostLayout props, guard git-log + remote fetch (#116)
Fixes surfaced while syncing loudmouth/homepage: - PostLayout Props: MarkdownLayoutProps -> Omit<MDXInstance<{}>,'frontmatter'> + headings, matching the MDX page spread (astro check flags the old type under exactOptionalPropertyTypes; zaduma's tsc-only typecheck doesn't, but consumers running astro check do) - derivedTitleAndDatePlugin: guard execFileSync git-log against missing git/.git (fall back to current date) - Image.astro: throw on non-ok remote image responses instead of decoding an error body
1 parent 225e9bf commit 08a8990

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/build-time/derivedTitleAndDatePlugin.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@ export const derivedTitleAndDatePlugin: Plugin<
1313
frontmatter.title ||= title(file.stem || "");
1414

1515
if (!frontmatter.date) {
16-
const createdAt =
17-
execFileSync(
18-
"git",
19-
[
20-
"log",
21-
"--follow",
22-
"--diff-filter=A",
23-
"--find-renames=40%",
24-
"--format=%ai",
25-
file.path,
26-
],
27-
{ encoding: "utf8" },
28-
)
29-
.trim()
30-
.split("\n")[0] || new Date().toISOString();
16+
let createdAt: string;
17+
try {
18+
createdAt =
19+
execFileSync(
20+
"git",
21+
[
22+
"log",
23+
"--follow",
24+
"--diff-filter=A",
25+
"--find-renames=40%",
26+
"--format=%ai",
27+
file.path,
28+
],
29+
{ encoding: "utf8" },
30+
)
31+
.trim()
32+
.split("\n")[0] || new Date().toISOString();
33+
} catch {
34+
createdAt = new Date().toISOString();
35+
}
3136

3237
frontmatter.date = createdAt;
3338
}

src/layouts/PostLayout.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import type { MarkdownLayoutProps } from "astro";
2+
import type { MarkdownHeading, MDXInstance } from "astro";
33
44
import { createOgImageLink } from "../lib/createOgImageLink";
55
import { formatDate } from "../lib/formatDate";
@@ -13,8 +13,9 @@ import BaseLayout from "./BaseLayout.astro";
1313
1414
import "../global-styles/shiki.css";
1515
16-
interface Props extends Omit<MarkdownLayoutProps<{}>, "frontmatter"> {
16+
interface Props extends Omit<MDXInstance<{}>, "frontmatter"> {
1717
frontmatter: PostFrontmatter;
18+
headings: MarkdownHeading[];
1819
}
1920
2021
const { frontmatter, headings } = Astro.props;

src/lib/prose/Image.astro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ if (isRaw) {
120120
let imageForPlaceholder: Buffer;
121121
if (pathToImage.startsWith("http")) {
122122
const res = await fetch(pathToImage);
123+
if (!res.ok) {
124+
throw new Error(
125+
`Failed to fetch image ${pathToImage}: ${res.status} ${res.statusText}`,
126+
);
127+
}
123128
imageForPlaceholder = Buffer.from(await res.arrayBuffer());
124129
} else {
125130
// Resolve the source image from the project root. `pathToImage` is

0 commit comments

Comments
 (0)