Skip to content

Commit dfd8d1e

Browse files
committed
Add banner
1 parent 4b488e6 commit dfd8d1e

5 files changed

Lines changed: 78 additions & 4 deletions

File tree

src/components/Banner/index.astro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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" 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 hiddenBanner = window.localStorage.getItem('hideBanner');
18+
const title = banner.getAttribute('data-title');
19+
if (hiddenBanner !== title) {
20+
banner.removeAttribute('style');
21+
}
22+
const hideBanner = () => {
23+
banner.setAttribute('style', 'display: none');
24+
try {
25+
window.localStorage.setItem('hideBanner', title);
26+
} catch (e) {
27+
console.error(e);
28+
}
29+
}
30+
document.querySelector('#hideBanner').addEventListener('click', hideBanner);
31+
</script>

src/components/Footer/index.astro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
---
22
import { getCurrentLocale, getUiTranslator } from "@/src/i18n/utils";
3+
import { getCollectionInLocaleWithFallbacks } from "@pages/_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 collection = await getCollectionInLocaleWithFallbacks("text-detail", currentLocale);
11+
const bannerEntry = collection.find((entry) => entry.slug === 'banner');
12+
console.log(currentLocale)
13+
console.log(bannerEntry)
714
---
815

916
<footer
@@ -59,5 +66,6 @@ const t = await getUiTranslator(currentLocale);
5966
</div>
6067
</div>
6168
</footer>
69+
{bannerEntry && !bannerEntry.data.hidden && (<Banner entry={bannerEntry} />)}
6270

6371
<style></style>

src/content/text-detail/config.ts

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

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)