Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion blog-cloudflare/emdash-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// <reference types="emdash/locals" />

import type { ContentBylineCredit, PortableTextBlock } from "emdash";
import type { ContentBylineCredit, TaxonomyTerm, PortableTextBlock } from "emdash";

export interface Page {
id: string;
Expand All @@ -15,6 +15,7 @@ export interface Page {
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

export interface Post {
Expand All @@ -29,6 +30,7 @@ export interface Post {
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

declare module "emdash" {
Expand Down
4 changes: 2 additions & 2 deletions blog-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"dependencies": {
"@astrojs/cloudflare": "^13.5.3",
"@astrojs/react": "^5.0.0",
"@emdash-cms/cloudflare": "^0.16.1",
"@emdash-cms/cloudflare": "^0.18.0",
"@emdash-cms/plugin-forms": "^0.2.3",
"@emdash-cms/plugin-webhook-notifier": "^0.2.0",
"astro": "^6.3.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
22 changes: 9 additions & 13 deletions blog-cloudflare/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
getEmDashEntry,
getEmDashCollection,
getEntryTerms,
getTermsForEntries,
getSeoMeta,
decodeSlug,
Expand Down Expand Up @@ -72,18 +71,15 @@ const bylines = post.data.bylines ?? [];
// Get reading time
const readingTime = getReadingTime(post.data.content);

// Fetch this post's tags and the related-posts list in parallel — they're
// independent queries, so running them concurrently halves the round-trip
// cost on remote databases.
// Note: post.id is the slug, post.data.id is the database ULID.
const [tags, { entries: recentPosts }] = await Promise.all([
getEntryTerms("posts", post.data.id, "tag"),
// Fetch a few extra in case the current post is among them
getEmDashCollection("posts", {
orderBy: { published_at: "desc" },
limit: 4,
}),
]);
// This post's tags are already hydrated onto the entry by getEmDashEntry —
// no extra query needed.
const tags = post.data.terms?.tag ?? [];

// Fetch a few extra recent posts in case the current post is among them.
const { entries: recentPosts } = await getEmDashCollection("posts", {
orderBy: { published_at: "desc" },
limit: 4,
});
const otherPosts = recentPosts.filter((p) => p.id !== post.id).slice(0, 3);

// Single batched query for related-posts tags, rather than one
Expand Down
4 changes: 3 additions & 1 deletion blog/emdash-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// <reference types="emdash/locals" />

import type { ContentBylineCredit, PortableTextBlock } from "emdash";
import type { ContentBylineCredit, TaxonomyTerm, PortableTextBlock } from "emdash";

export interface Page {
id: string;
Expand All @@ -15,6 +15,7 @@ export interface Page {
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

export interface Post {
Expand All @@ -29,6 +30,7 @@ export interface Post {
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

declare module "emdash" {
Expand Down
2 changes: 1 addition & 1 deletion blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@emdash-cms/plugin-audit-log": "^0.2.0",
"astro": "^6.3.0",
"better-sqlite3": "^12.8.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
22 changes: 9 additions & 13 deletions blog/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
getEmDashEntry,
getEmDashCollection,
getEntryTerms,
getTermsForEntries,
getSeoMeta,
decodeSlug,
Expand Down Expand Up @@ -72,18 +71,15 @@ const bylines = post.data.bylines ?? [];
// Get reading time
const readingTime = getReadingTime(post.data.content);

// Fetch this post's tags and the related-posts list in parallel — they're
// independent queries, so running them concurrently halves the round-trip
// cost on remote databases.
// Note: post.id is the slug, post.data.id is the database ULID.
const [tags, { entries: recentPosts }] = await Promise.all([
getEntryTerms("posts", post.data.id, "tag"),
// Fetch a few extra in case the current post is among them
getEmDashCollection("posts", {
orderBy: { published_at: "desc" },
limit: 4,
}),
]);
// This post's tags are already hydrated onto the entry by getEmDashEntry —
// no extra query needed.
const tags = post.data.terms?.tag ?? [];

// Fetch a few extra recent posts in case the current post is among them.
const { entries: recentPosts } = await getEmDashCollection("posts", {
orderBy: { published_at: "desc" },
limit: 4,
});
const otherPosts = recentPosts.filter((p) => p.id !== post.id).slice(0, 3);

// Single batched query for related-posts tags, rather than one
Expand Down
4 changes: 2 additions & 2 deletions marketing-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"dependencies": {
"@astrojs/cloudflare": "^13.5.3",
"@astrojs/react": "^5.0.0",
"@emdash-cms/cloudflare": "^0.16.1",
"@emdash-cms/cloudflare": "^0.18.0",
"@iconify-json/ph": "^1.2.2",
"astro": "^6.3.0",
"astro-iconset": "^0.0.4",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion marketing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"astro": "^6.3.0",
"astro-iconset": "^0.0.4",
"better-sqlite3": "^12.8.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
4 changes: 2 additions & 2 deletions portfolio-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"dependencies": {
"@astrojs/cloudflare": "^13.5.3",
"@astrojs/react": "^5.0.0",
"@emdash-cms/cloudflare": "^0.16.1",
"@emdash-cms/cloudflare": "^0.18.0",
"astro": "^6.3.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion portfolio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/react": "^5.0.0",
"astro": "^6.3.0",
"better-sqlite3": "^12.8.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
6 changes: 5 additions & 1 deletion starter-cloudflare/emdash-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// <reference types="emdash/locals" />

import type { PortableTextBlock } from "emdash";
import type { ContentBylineCredit, TaxonomyTerm, PortableTextBlock } from "emdash";

export interface Page {
id: string;
Expand All @@ -14,6 +14,8 @@ export interface Page {
createdAt: Date;
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

export interface Post {
Expand All @@ -27,6 +29,8 @@ export interface Post {
createdAt: Date;
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

declare module "emdash" {
Expand Down
4 changes: 2 additions & 2 deletions starter-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"dependencies": {
"@astrojs/cloudflare": "^13.5.3",
"@astrojs/react": "^5.0.0",
"@emdash-cms/cloudflare": "^0.16.1",
"@emdash-cms/cloudflare": "^0.18.0",
"astro": "^6.3.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
8 changes: 4 additions & 4 deletions starter-cloudflare/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { getEmDashEntry, getEntryTerms, getSeoMeta, decodeSlug, getSiteSettings } from "emdash";
import { getEmDashEntry, getSeoMeta, decodeSlug, getSiteSettings } from "emdash";
import { Image, PortableText, WidgetArea } from "emdash/ui";
import Base from "../../layouts/Base.astro";
import { resolveStarterSiteIdentity } from "../../utils/site-identity";
Expand All @@ -26,9 +26,9 @@ const seo = getSeoMeta(post, {
path: `/posts/${slug}`,
});

// Taxonomy terms for this post (use post.data.id, not post.id)
const tags = await getEntryTerms("posts", post.data.id, "tag");
const categories = await getEntryTerms("posts", post.data.id, "category");
// Taxonomy terms are already hydrated onto the entry by getEmDashEntry.
const tags = post.data.terms?.tag ?? [];
const categories = post.data.terms?.category ?? [];
---

<Base
Expand Down
6 changes: 5 additions & 1 deletion starter/emdash-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// <reference types="emdash/locals" />

import type { PortableTextBlock } from "emdash";
import type { ContentBylineCredit, TaxonomyTerm, PortableTextBlock } from "emdash";

export interface Page {
id: string;
Expand All @@ -14,6 +14,8 @@ export interface Page {
createdAt: Date;
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

export interface Post {
Expand All @@ -27,6 +29,8 @@ export interface Post {
createdAt: Date;
updatedAt: Date;
publishedAt: Date | null;
bylines?: ContentBylineCredit[];
terms?: Record<string, TaxonomyTerm[]>;
}

declare module "emdash" {
Expand Down
2 changes: 1 addition & 1 deletion starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/react": "^5.0.0",
"astro": "^6.3.0",
"better-sqlite3": "^12.8.0",
"emdash": "^0.16.1",
"emdash": "^0.18.0",
"react": "19.2.4",
"react-dom": "19.2.4"
},
Expand Down
8 changes: 4 additions & 4 deletions starter/src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { getEmDashEntry, getEntryTerms, getSeoMeta, decodeSlug, getSiteSettings } from "emdash";
import { getEmDashEntry, getSeoMeta, decodeSlug, getSiteSettings } from "emdash";
import { Image, PortableText, WidgetArea } from "emdash/ui";
import Base from "../../layouts/Base.astro";
import { resolveStarterSiteIdentity } from "../../utils/site-identity";
Expand All @@ -26,9 +26,9 @@ const seo = getSeoMeta(post, {
path: `/posts/${slug}`,
});

// Taxonomy terms for this post (use post.data.id, not post.id)
const tags = await getEntryTerms("posts", post.data.id, "tag");
const categories = await getEntryTerms("posts", post.data.id, "category");
// Taxonomy terms are already hydrated onto the entry by getEmDashEntry.
const tags = post.data.terms?.tag ?? [];
const categories = post.data.terms?.category ?? [];
---

<Base
Expand Down
Loading