Skip to content

Commit 1682bb2

Browse files
authored
Merge branch 'main' into homepage-images
2 parents 006b797 + 956fc12 commit 1682bb2

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

docs/banner.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Banner
2+
3+
A banner can optionally be added at the bottom of the page with a custom message and link.
4+
5+
## Adding a new banner
6+
7+
Edit the banner text in the body of `src/content/banner/en.mdx`.
8+
9+
Within the file's metadata:
10+
- 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.
11+
- Make sure `hidden` is `true` for the banner to be visible
12+
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+
17+
## Removing a banner
18+
19+
- Set `hidden` to `true` in `src/content/banner/en.mdx`
20+
- Delete any translations of the banner that have been made in non-`en` locales.
21+
22+
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/Banner/index.astro

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
import { Icon } from "@components/Icon"
3+
const { entry } = Astro.props;
4+
const { Content } = await entry.render();
5+
const { link, title } = entry.data;
6+
---
7+
8+
<div class="banner bg-accent-color text-accent-type-color" style={{ display: 'none' }} data-title={title}>
9+
<a class="banner-content" href={link} target="_blank">
10+
<Content />
11+
</a>
12+
<button id="hideBanner"><Icon kind="close"></button>
13+
</div>
14+
15+
<script>
16+
const banner = document.querySelector('.banner');
17+
const hideBannerBtn = document.querySelector('#hideBanner');
18+
if (banner && hideBannerBtn) {
19+
const hiddenBanner = window.localStorage.getItem('hideBanner');
20+
const title = banner.getAttribute('data-title');
21+
if (hiddenBanner !== title) {
22+
banner.removeAttribute('style');
23+
}
24+
const hideBanner = () => {
25+
banner.setAttribute('style', 'display: none');
26+
try {
27+
window.localStorage.setItem('hideBanner', title || '');
28+
} catch (e) {
29+
console.error(e);
30+
}
31+
}
32+
hideBannerBtn.addEventListener('click', hideBanner);
33+
}
34+
</script>

src/components/Footer/index.astro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
---
2+
import { getEntry } from "astro:content";
23
import { getCurrentLocale, getUiTranslator } from "@/src/i18n/utils";
34
import { Icon } from "../Icon";
5+
import Banner from "@components/Banner/index.astro";
46
57
const currentLocale = getCurrentLocale(Astro.url.pathname);
68
const t = await getUiTranslator(currentLocale);
9+
10+
const bannerEntry = await getEntry("banner", currentLocale);
711
---
812

913
<footer
@@ -58,5 +62,6 @@ const t = await getUiTranslator(currentLocale);
5862
</div>
5963
</div>
6064
</footer>
65+
{bannerEntry && !bannerEntry.data.hidden && (<Banner entry={bannerEntry} />)}
6166

6267
<style></style>

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 bannerCollection = defineCollection({
4+
type: "content",
5+
schema: () =>
6+
z.object({
7+
title: z.string(),
8+
link: z.string(),
9+
hidden: z.boolean().optional(),
10+
}),
11+
});

src/content/banner/en.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Give each new message a unique title so we know which one a user closed
3+
title: "pr05"
4+
link: "https://processingfoundation.org/grants"
5+
hidden: false
6+
---
7+
8+
Apply to the $10k pr05 grant by May 31!

src/content/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { examplesCollection } from "./examples/config";
88
import { contributorDocsCollection } from "./contributor-docs/config";
99
import { homepageCollection } from "./homepage/config";
1010
import { pagesCollection } from "./pages/config";
11+
import { bannerCollection } from "./banner/config";
1112

1213
/**
1314
* All content collections defined in subfolders of /src/content/
@@ -26,4 +27,5 @@ export const collections = {
2627
"contributor-docs": contributorDocsCollection,
2728
homepage: homepageCollection,
2829
pages: pagesCollection,
30+
banner: bannerCollection,
2931
};

styles/global.scss

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pre.code-box {
299299
/** LAYOUT **/
300300

301301
.top-layout-grid {
302-
--nav-width: 100vw;
302+
--nav-width: 100%;
303303
--nav-offset-x: 0;
304304

305305
@media (min-width: $breakpoint-tablet) {
@@ -320,13 +320,36 @@ pre.code-box {
320320
}
321321
}
322322

323+
.banner,
323324
.settings,
324325
header,
325326
main,
326327
footer {
327328
margin-left: var(--nav-offset-x);
328329
}
329330

331+
.banner {
332+
display: flex;
333+
flex-direction: row;
334+
position: sticky;
335+
bottom: 0;
336+
padding: var(--spacing-xs) var(--spacing-md);
337+
border-top: 1px solid var(--type-color);
338+
339+
& .banner-content {
340+
flex: 1;
341+
margin-right: var(--pacing-sm);
342+
}
343+
344+
@media (min-width: $breakpoint-tablet) {
345+
padding: var(--spacing-sm) var(--spacing-lg);
346+
}
347+
348+
& p {
349+
margin: 0;
350+
}
351+
}
352+
330353
header {
331354
.homepage-header-top {
332355
display: flex;
@@ -344,6 +367,7 @@ pre.code-box {
344367
}
345368

346369
@media (min-width: $breakpoint-laptop) {
370+
height: calc(50vh - var(--spacing-3xl));
347371
max-height: calc(50vh - var(--spacing-3xl));
348372
}
349373
}
@@ -404,9 +428,9 @@ th {
404428
}
405429

406430
.hero-image {
407-
left: -2.5rem;
408-
width: calc(100% + 5rem);
409-
max-width: calc(100% + 5rem);
431+
left: calc(-1 * var(--spacing-lg));
432+
width: calc(100% + 2 * var(--spacing-lg));
433+
max-width: calc(100% + 2 * var(--spacing-lg));
410434
max-height: 50vh;
411435
height: 50vh;
412436
position: relative;

0 commit comments

Comments
 (0)