Skip to content

Commit f73af6c

Browse files
committed
Make banner its own collection
1 parent f95eaee commit f73af6c

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

docs/banner.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ A banner can optionally be added at the bottom of the page with a custom message
44

55
## Adding a new banner
66

7-
Edit the banner text in the body of `src/content/text-detail/en/banner.tsx`.
7+
Edit the banner text in the body of `src/content/banner/en.mdx`.
88

99
Within the file's metadata:
1010
- Change the `title` metadata to a new slug for each message. This does not get displayed anywhere, but it gets recorded when a user dismisses the banner. This way, we can hide that banner for the user the next time they return, but still show them a new banner when we create a new message.
1111
- Make sure `hidden` is `true` for the banner to be visible
1212

13+
## Translating banners
14+
15+
Copy the `en.mdx` file to `${locale}.mdx` (e.g. `es.mdx`) and translate just the body text, leaving the metadata the same.
16+
1317
## Removing a banner
1418

15-
- Set `hidden` to `true` in `src/content/text-detail/en/banner.tsx`
19+
- Set `hidden` to `true` in `src/content/banner/en.mdx`
1620
- Delete any translations of the banner that have been made in non-`en` locales.
1721

1822
This is to make sure that the next time a new banner is made, there is a clean slate to start from for translations.

src/components/Footer/index.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
2+
import { getEntry } from "astro:content";
23
import { getCurrentLocale, getUiTranslator } from "@/src/i18n/utils";
3-
import { getCollectionInLocaleWithFallbacks } from "@pages/_utils";
44
import { Icon } from "../Icon";
55
import Banner from "@components/Banner/index.astro";
66
77
const currentLocale = getCurrentLocale(Astro.url.pathname);
88
const t = await getUiTranslator(currentLocale);
99
10-
const collection = await getCollectionInLocaleWithFallbacks("text-detail", currentLocale);
11-
const bannerEntry = collection.find((entry) => entry.slug === 'banner');
10+
const bannerEntry = await getEntry("banner", currentLocale);
1211
---
1312

1413
<footer

src/content/banner/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { z, defineCollection } from "astro:content";
2+
3+
export const textDetailCollection = defineCollection({
4+
type: "content",
5+
schema: () =>
6+
z.object({
7+
title: z.string(),
8+
link: z.string(),
9+
hidden: z.boolean().optional(),
10+
}),
11+
});
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
slug: "banner"
32
# Give each new message a unique title so we know which one a user closed
43
title: "pr05"
54
link: "https://processingfoundation.org/grants"

src/content/text-detail/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ export const textDetailCollection = defineCollection({
77
title: z.string(),
88
featuredImage: image().optional(),
99
featuredImageAlt: z.string().optional(),
10-
link: z.string().optional(),
11-
hidden: z.boolean().optional(),
1210
}),
1311
});

0 commit comments

Comments
 (0)