aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components
diff options
context:
space:
mode:
authorYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-09-15 22:01:29 +0900
committerYasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com>2026-09-15 22:01:29 +0900
commitdea594c6dda0f84ee3ebf6982ea1c98ff760bf71 (patch)
treef335463efbd05962e80a07ee6ea3497ea7c2a849 /src/components
parent2d287d60868a5059ad3ba3938ef0972ead0ff066 (diff)
SocialShare: X投稿のキャプションをページごとに生成
Diffstat (limited to 'src/components')
-rw-r--r--src/components/SocialShare.astro11
-rw-r--r--src/components/starlight/Footer.astro9
2 files changed, 13 insertions, 7 deletions
diff --git a/src/components/SocialShare.astro b/src/components/SocialShare.astro
index f3be8e8..a375884 100644
--- a/src/components/SocialShare.astro
+++ b/src/components/SocialShare.astro
@@ -2,7 +2,7 @@
export interface Props {
/** Page URL (defaults to current page) */
url?: string;
- /** Page title */
+ /** 共有時のキャプション(ページを表す文言) */
title?: string;
}
@@ -11,12 +11,11 @@ const pageUrl = url ?? Astro.url.href;
const pageTitle = title ?? "";
const encodedUrl = encodeURIComponent(pageUrl);
-const encodedTitle = encodeURIComponent(pageTitle);
-const siteCredits = encodeURIComponent("小平市議 安竹洋平");
+const siteCredits = "小平市議 安竹洋平";
-const xText = encodedTitle
- ? `${encodedTitle}%20%7C%20${siteCredits}`
- : siteCredits;
+const xText = encodeURIComponent(
+ pageTitle ? `${siteCredits} ${pageTitle}` : siteCredits,
+);
const SHARE_LINKS = [
{
diff --git a/src/components/starlight/Footer.astro b/src/components/starlight/Footer.astro
index 7c3871c..5b59d09 100644
--- a/src/components/starlight/Footer.astro
+++ b/src/components/starlight/Footer.astro
@@ -5,10 +5,17 @@ import Pagination from 'virtual:starlight/components/Pagination';
import config from 'virtual:starlight/user-config';
import { Icon } from '@astrojs/starlight/components';
import SocialShare from '../SocialShare.astro';
+import { shareCaption } from '../../utils/share-caption';
+
+const route = Astro.locals.starlightRoute;
+const caption = shareCaption(
+ route.entry?.slug || route.id || '',
+ route.entry?.data?.title,
+);
---
<footer class="sl-flex">
- <SocialShare />
+ <SocialShare title={caption} />
<div class="meta sl-flex">
<EditLink />