Skip to content

Commit d249f3a

Browse files
committed
Add rotating social media card image for web site
1 parent 2cd5cb9 commit d249f3a

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed
1.48 MB
Loading
87.9 KB
Loading
411 KB
Loading
220 KB
Loading

src/layouts/Base.astro

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
import { languages, markdownify, isRtl } from '../i18n/config';
33
import ThemeToggle from '../components/ThemeToggle.astro';
4+
import { glob } from 'node:fs/promises';
45
56
interface Props {
67
title: string;
@@ -15,6 +16,15 @@ const {
1516
} = Astro.props;
1617
1718
const dir = isRtl(lang) ? "rtl" : "ltr";
19+
20+
// Pick a random lockdown image at build time for social media previews
21+
const lockdownImages: string[] = [];
22+
for await (const entry of glob('public/img/lockdowns/*.{png,jpg,jpeg,webp}')) {
23+
lockdownImages.push(entry.replace(/^public/, ''));
24+
}
25+
const ogImage = lockdownImages.length > 0
26+
? `https://keepandroidopen.org${lockdownImages[Math.floor(Math.random() * lockdownImages.length)]}`
27+
: 'https://keepandroidopen.org/img/keepandroidopen.png';
1828
---
1929
<!DOCTYPE html>
2030
<html lang={lang} dir={dir}>
@@ -28,11 +38,11 @@ const dir = isRtl(lang) ? "rtl" : "ltr";
2838
<meta name="description" content={description}>
2939
<meta property="og:title" content={title}>
3040
<meta property="og:description" content={description}>
31-
<meta property="og:image" content="https://keepandroidopen.org/img/keepandroidopen.png">
41+
<meta property="og:image" content={ogImage}>
3242
<meta property="og:type" content="website">
3343
<meta name="twitter:card" content="summary">
3444
<meta name="twitter:title" content={title}>
35-
<meta name="twitter:image" content="https://keepandroidopen.org/img/keepandroidopen.png">
45+
<meta name="twitter:image" content={ogImage}>
3646
<link rel="me" href="https://techhub.social/@keepandroidopen">
3747
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
3848

src/pages/open-letter.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ function logoPath(url: string): string {
3030
// Build compose/draft URLs for each social platform
3131
function xDraftUrl(orgName: string, xUrl: string): string {
3232
const handle = '@' + xUrl.split('/').pop();
33-
const text = `Thank you ${handle} for supporting Keep @Android Open @AlteredDeal #KeepAndroidOpen`;
33+
const text = `Thank you ${orgName} (${handle}) for supporting Keep @Android Open @AlteredDeal #KeepAndroidOpen`;
3434
return `https://x.com/intent/tweet?text=${encodeURIComponent(text)}`;
3535
}
3636
3737
function bskyDraftUrl(orgName: string, bskyUrl: string): string {
3838
const handle = '@' + bskyUrl.split('/').pop();
39-
const text = `Thank you ${handle} for supporting Keep Android Open @keepandroidopen.bsky.social #KeepAndroidOpen`;
39+
const text = `Thank you ${orgName} (${handle}) for supporting Keep Android Open @keepandroidopen.bsky.social #KeepAndroidOpen`;
4040
return `https://bsky.app/intent/compose?text=${encodeURIComponent(text)}`;
4141
}
4242
4343
function mastodonDraftUrl(orgName: string, mastodonUrl: string): string {
4444
const url = new URL(mastodonUrl);
4545
const user = url.pathname.split('/').pop();
4646
const handle = `${user}@${url.hostname}`;
47-
const text = `Thank you ${handle} for supporting Keep Android Open at https://keepandroidopen.org/open-letter/#signatories @keepandroidopen@techhub.social #KeepAndroidOpen`;
47+
const text = `Thank you ${orgName} (${handle}) for supporting Keep Android Open at https://keepandroidopen.org/open-letter/#signatories @keepandroidopen@techhub.social #KeepAndroidOpen`;
4848
return `https://share.joinmastodon.org/?text=${encodeURIComponent(text)}`;
4949
}
5050

0 commit comments

Comments
 (0)