@hutusi/amytis 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/GEMINI.md +6 -2
  2. package/TODO.md +11 -15
  3. package/bun.lock +3 -0
  4. package/content/about.mdx +1 -0
  5. package/content/about.zh.mdx +21 -0
  6. package/content/flows/2026/02/20.md +16 -0
  7. package/content/links.mdx +42 -0
  8. package/content/links.zh.mdx +41 -0
  9. package/content/posts/2026-02-20-i18n-routing-considerations.mdx +150 -0
  10. package/content/posts/multimedia-showcase/index.mdx +261 -0
  11. package/content/privacy.mdx +32 -0
  12. package/content/privacy.zh.mdx +32 -0
  13. package/docs/ARCHITECTURE.md +8 -0
  14. package/package.json +2 -1
  15. package/scripts/copy-assets.ts +1 -1
  16. package/site.config.ts +126 -44
  17. package/src/app/[slug]/page.tsx +0 -10
  18. package/src/app/archive/page.tsx +38 -10
  19. package/src/app/books/[slug]/page.tsx +18 -0
  20. package/src/app/flows/[year]/[month]/[day]/page.tsx +20 -3
  21. package/src/app/layout.tsx +47 -21
  22. package/src/app/page.tsx +135 -72
  23. package/src/app/posts/[slug]/page.tsx +6 -12
  24. package/src/app/series/[slug]/page.tsx +18 -0
  25. package/src/app/subscribe/page.tsx +17 -0
  26. package/src/app/tags/[tag]/page.tsx +9 -26
  27. package/src/app/tags/page.tsx +3 -8
  28. package/src/components/AuthorCard.tsx +43 -0
  29. package/src/components/Comments.tsx +20 -4
  30. package/src/components/ExternalLinks.tsx +6 -2
  31. package/src/components/Footer.tsx +35 -26
  32. package/src/components/LanguageProvider.tsx +0 -5
  33. package/src/components/LanguageSwitch.tsx +117 -6
  34. package/src/components/LocaleSwitch.tsx +33 -0
  35. package/src/components/Navbar.tsx +31 -8
  36. package/src/components/PostNavigation.tsx +55 -0
  37. package/src/components/PostSidebar.tsx +172 -126
  38. package/src/components/ReadingProgressBar.tsx +6 -21
  39. package/src/components/RelatedPosts.tsx +1 -1
  40. package/src/components/Search.tsx +24 -4
  41. package/src/components/SelectedBooksSection.tsx +12 -6
  42. package/src/components/ShareBar.tsx +115 -0
  43. package/src/components/SimpleLayoutHeader.tsx +5 -14
  44. package/src/components/SubscribePage.tsx +298 -0
  45. package/src/components/TagContentTabs.tsx +103 -0
  46. package/src/components/TagPageHeader.tsx +7 -13
  47. package/src/components/TagSidebar.tsx +142 -0
  48. package/src/components/TagsIndexClient.tsx +156 -0
  49. package/src/hooks/useScrollY.ts +41 -0
  50. package/src/i18n/translations.ts +84 -0
  51. package/src/layouts/PostLayout.tsx +33 -6
  52. package/src/layouts/SimpleLayout.tsx +53 -15
  53. package/src/lib/markdown.ts +71 -15
  54. package/src/components/TableOfContents.tsx +0 -158
@@ -1,9 +1,12 @@
1
1
  'use client';
2
2
 
3
- import { useState, useEffect, useRef, useCallback } from 'react';
3
+ import { useState, useEffect, useRef } from 'react';
4
4
  import Link from 'next/link';
5
5
  import { PostData, Heading } from '@/lib/markdown';
6
6
  import { useLanguage } from './LanguageProvider';
7
+ import { useScrollY } from '@/hooks/useScrollY';
8
+ import ShareBar from './ShareBar';
9
+ import { siteConfig } from '../../site.config';
7
10
 
8
11
  interface PostSidebarProps {
9
12
  seriesSlug?: string;
@@ -11,28 +14,52 @@ interface PostSidebarProps {
11
14
  posts?: PostData[];
12
15
  currentSlug: string;
13
16
  headings: Heading[];
17
+ localeHeadings?: Record<string, Heading[]>;
18
+ shareUrl?: string;
19
+ shareTitle?: string;
14
20
  }
15
21
 
16
- export default function PostSidebar({ seriesSlug, seriesTitle, posts, currentSlug, headings }: PostSidebarProps) {
17
- const { t } = useLanguage();
22
+ function getVisibleIndices(total: number, current: number): (number | 'ellipsis')[] {
23
+ if (total <= 7) return Array.from({ length: total }, (_, i) => i);
24
+ const result: (number | 'ellipsis')[] = [];
25
+ result.push(0);
26
+ const windowStart = Math.max(1, current - 2);
27
+ const windowEnd = Math.min(total - 2, current + 2);
28
+ if (windowStart > 1) result.push('ellipsis');
29
+ for (let i = windowStart; i <= windowEnd; i++) result.push(i);
30
+ if (windowEnd < total - 2) result.push('ellipsis');
31
+ result.push(total - 1);
32
+ return result;
33
+ }
34
+
35
+ export default function PostSidebar({ seriesSlug, seriesTitle, posts, currentSlug, headings, localeHeadings, shareUrl, shareTitle }: PostSidebarProps) {
36
+ const { t, language } = useLanguage();
37
+ const activeHeadings = localeHeadings?.[language] ?? headings;
18
38
  const hasSeries = !!(seriesSlug && posts && posts.length > 0);
19
39
  const currentIndex = hasSeries ? posts!.findIndex(p => p.slug === currentSlug) : -1;
40
+ // Chronological sort (ascending date) — used for both progress counter and isPast styling
41
+ const sortedPosts = hasSeries
42
+ ? [...posts!].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
43
+ : null;
44
+ const progressIndex = hasSeries ? sortedPosts!.findIndex(p => p.slug === currentSlug) : -1;
20
45
  const currentItemRef = useRef<HTMLLIElement>(null);
21
46
  const sidebarRef = useRef<HTMLElement>(null);
22
47
  const [activeHeadingId, setActiveHeadingId] = useState<string>('');
23
48
  const [tocCollapsed, setTocCollapsed] = useState(false);
49
+ const [seriesCollapsed, setSeriesCollapsed] = useState(false);
50
+ const scrollY = useScrollY();
24
51
 
25
- // Scroll tracking for page headings
26
- const handleScroll = useCallback(() => {
27
- if (headings.length === 0) return;
52
+ // Derive active heading from shared scroll position
53
+ useEffect(() => {
54
+ if (activeHeadings.length === 0) return;
28
55
 
29
- const headingElements = headings
56
+ const headingElements = activeHeadings
30
57
  .map(h => document.getElementById(h.id))
31
58
  .filter(Boolean) as HTMLElement[];
32
59
 
33
60
  if (headingElements.length === 0) return;
34
61
 
35
- const scrollPosition = window.scrollY + 100;
62
+ const scrollPosition = scrollY + 100;
36
63
  let current = headingElements[0];
37
64
  for (const el of headingElements) {
38
65
  if (el.offsetTop <= scrollPosition) {
@@ -42,23 +69,11 @@ export default function PostSidebar({ seriesSlug, seriesTitle, posts, currentSlu
42
69
  }
43
70
  }
44
71
 
45
- if (current) {
46
- setActiveHeadingId(current.id);
47
- }
48
- }, [headings]);
49
-
50
- useEffect(() => {
51
- if (headings.length === 0) return;
52
-
53
- // Use requestAnimationFrame to avoid cascading render lint error on mount
54
- const rafId = requestAnimationFrame(handleScroll);
55
-
56
- window.addEventListener('scroll', handleScroll, { passive: true });
57
- return () => {
58
- cancelAnimationFrame(rafId);
59
- window.removeEventListener('scroll', handleScroll);
60
- };
61
- }, [handleScroll, headings.length]);
72
+ const rafId = requestAnimationFrame(() => {
73
+ if (current) setActiveHeadingId(current.id);
74
+ });
75
+ return () => cancelAnimationFrame(rafId);
76
+ }, [scrollY, activeHeadings]);
62
77
 
63
78
  const scrollToHeading = (e: React.MouseEvent<HTMLAnchorElement>, id: string) => {
64
79
  e.preventDefault();
@@ -88,113 +103,33 @@ export default function PostSidebar({ seriesSlug, seriesTitle, posts, currentSlu
88
103
  ref={sidebarRef}
89
104
  className="hidden lg:block sticky top-20 self-start w-[280px] max-h-[calc(100vh-6rem)] overflow-y-auto pr-4 scrollbar-hide hover:scrollbar-thin"
90
105
  >
91
- {/* Series section */}
92
- {hasSeries && (
93
- <>
94
- <div className="mb-6 pb-4 border-b border-muted/10">
95
- <Link href={`/series/${seriesSlug}`} className="group block no-underline">
96
- <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-accent mb-2 block">
97
- {t('series')}
98
- </span>
99
- <h3 className="font-serif font-bold text-heading text-lg leading-snug group-hover:text-accent transition-colors">
100
- {seriesTitle}
101
- </h3>
102
- </Link>
103
-
104
- {/* Progress */}
105
- <div className="mt-3 flex items-center gap-3">
106
- <div className="flex-1 h-1 bg-muted/10 rounded-full overflow-hidden">
107
- <div
108
- className="h-full bg-accent/60 rounded-full transition-all duration-500"
109
- style={{ width: `${((currentIndex + 1) / posts!.length) * 100}%` }}
110
- />
111
- </div>
112
- <span className="text-xs font-mono text-muted whitespace-nowrap">
113
- {currentIndex + 1}/{posts!.length}
114
- </span>
115
- </div>
116
- </div>
117
-
118
- {/* Series posts list */}
119
- <nav aria-label="Series navigation" className="mb-6">
120
- <ul className="space-y-1 relative">
121
- <div className="absolute left-[11px] top-3 bottom-3 w-px bg-muted/15" />
122
- {posts!.map((post, index) => {
123
- const isCurrent = post.slug === currentSlug;
124
- const isPast = index < currentIndex;
125
-
126
- return (
127
- <li key={post.slug} ref={isCurrent ? currentItemRef : undefined} className="relative">
128
- <Link
129
- href={`/posts/${post.slug}`}
130
- className={`group flex items-start gap-3 py-2 px-2 -mx-2 rounded-lg no-underline transition-all duration-200 ${
131
- isCurrent ? 'bg-accent/5' : 'hover:bg-muted/5'
132
- }`}
133
- aria-current={isCurrent ? 'page' : undefined}
134
- >
135
- <div className={`relative z-10 flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-mono font-bold transition-colors ${
136
- isCurrent
137
- ? 'bg-accent text-white shadow-sm shadow-accent/30'
138
- : isPast
139
- ? 'bg-accent/20 text-accent'
140
- : 'bg-muted/10 text-muted group-hover:bg-muted/20 group-hover:text-foreground'
141
- }`}>
142
- {String(index + 1).padStart(2, '0')}
143
- </div>
144
- <div className="flex-1 min-w-0 pt-0.5">
145
- <span className={`block text-sm leading-snug transition-colors ${
146
- isCurrent
147
- ? 'text-accent font-semibold'
148
- : isPast
149
- ? 'text-foreground/70 group-hover:text-foreground'
150
- : 'text-muted group-hover:text-foreground'
151
- }`}>
152
- {post.title}
153
- </span>
154
- </div>
155
- </Link>
156
- </li>
157
- );
158
- })}
159
- </ul>
160
- </nav>
161
-
162
- {/* Footer link */}
163
- <div className="mb-6 pb-4 border-b border-muted/10">
164
- <Link
165
- href={`/series/${seriesSlug}`}
166
- className="text-xs font-sans text-muted hover:text-accent transition-colors no-underline flex items-center gap-1"
106
+ {/* TOC always at top */}
107
+ {activeHeadings.length > 0 && (
108
+ <nav
109
+ aria-label="Table of contents"
110
+ className={`mb-6 ${hasSeries ? 'pb-4 border-b border-muted/10' : ''}`}
111
+ >
112
+ <div className="flex items-center justify-between mb-3">
113
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted">
114
+ {t('on_this_page')}
115
+ </span>
116
+ <button
117
+ onClick={() => setTocCollapsed(prev => !prev)}
118
+ className="text-muted hover:text-foreground transition-colors"
119
+ aria-label={tocCollapsed ? 'Expand table of contents' : 'Collapse table of contents'}
167
120
  >
168
- {t('view_full_series')}
169
- <svg className="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
170
- <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
121
+ <svg
122
+ className={`w-3.5 h-3.5 transition-transform duration-200 ${tocCollapsed ? '' : 'rotate-180'}`}
123
+ fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}
124
+ >
125
+ <path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
171
126
  </svg>
172
- </Link>
127
+ </button>
173
128
  </div>
174
- </>
175
- )}
176
-
177
- {/* Page TOC */}
178
- {headings.length > 0 && (
179
- <nav aria-label="Table of contents">
180
- <button
181
- onClick={() => setTocCollapsed(prev => !prev)}
182
- className="w-full flex items-center justify-between gap-2 mb-3"
183
- >
184
- <h2 className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted">
185
- {t('on_this_page')}
186
- </h2>
187
- <svg
188
- className={`w-3.5 h-3.5 text-muted flex-shrink-0 transition-transform duration-200 ${tocCollapsed ? '' : 'rotate-180'}`}
189
- fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}
190
- >
191
- <path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
192
- </svg>
193
- </button>
194
129
 
195
130
  {!tocCollapsed && (
196
131
  <ul className="space-y-0.5 border-l border-muted/15 animate-slide-down">
197
- {headings.map(heading => {
132
+ {activeHeadings.map(heading => {
198
133
  const isActive = heading.id === activeHeadingId;
199
134
  const isH3 = heading.level === 3;
200
135
 
@@ -220,6 +155,117 @@ export default function PostSidebar({ seriesSlug, seriesTitle, posts, currentSlu
220
155
  )}
221
156
  </nav>
222
157
  )}
158
+
159
+ {/* Series section — below TOC */}
160
+ {hasSeries && (
161
+ <div>
162
+ {/* Header — always visible */}
163
+ <div className="mb-3">
164
+ <div className="flex items-center justify-between mb-1">
165
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-accent">
166
+ {t('series')}
167
+ </span>
168
+ <span className="text-[10px] font-mono text-muted/60">
169
+ {progressIndex >= 0 ? progressIndex + 1 : '?'} / {posts!.length}
170
+ </span>
171
+ </div>
172
+ <div className="flex items-start justify-between gap-2">
173
+ <Link href={`/series/${seriesSlug}`} className="group block no-underline flex-1 min-w-0">
174
+ <h3 className="font-serif font-bold text-heading text-base leading-snug group-hover:text-accent transition-colors">
175
+ {seriesTitle}
176
+ </h3>
177
+ </Link>
178
+ <button
179
+ onClick={() => setSeriesCollapsed(prev => !prev)}
180
+ className="flex-shrink-0 mt-0.5 text-muted hover:text-foreground transition-colors"
181
+ aria-label={seriesCollapsed ? 'Expand series' : 'Collapse series'}
182
+ >
183
+ <svg
184
+ className={`w-3.5 h-3.5 transition-transform duration-200 ${seriesCollapsed ? '' : 'rotate-180'}`}
185
+ fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}
186
+ >
187
+ <path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
188
+ </svg>
189
+ </button>
190
+ </div>
191
+ </div>
192
+
193
+ {/* Collapsible: post list + footer link */}
194
+ {!seriesCollapsed && (
195
+ <>
196
+ <nav aria-label="Series navigation" className="mb-4 animate-slide-down">
197
+ <ul className="space-y-1 relative before:absolute before:left-[11px] before:top-3 before:bottom-3 before:w-px before:bg-muted/15">
198
+ {getVisibleIndices(posts!.length, currentIndex).map((item, i) => {
199
+ if (item === 'ellipsis') {
200
+ return (
201
+ <li key={`ellipsis-${i}`} className="flex items-center py-1 pl-3">
202
+ <span className="text-xs font-mono text-muted/40 tracking-widest">···</span>
203
+ </li>
204
+ );
205
+ }
206
+ const post = posts![item];
207
+ const isCurrent = post.slug === currentSlug;
208
+ const chronoIndex = sortedPosts ? sortedPosts.findIndex(p => p.slug === post.slug) : item;
209
+ const isPast = chronoIndex < progressIndex;
210
+
211
+ return (
212
+ <li key={post.slug} ref={isCurrent ? currentItemRef : undefined} className="relative">
213
+ <Link
214
+ href={`/posts/${post.slug}`}
215
+ className={`group flex items-start gap-3 py-2 px-2 -mx-2 rounded-lg no-underline transition-all duration-200 ${
216
+ isCurrent ? 'bg-accent/5' : 'hover:bg-muted/5'
217
+ }`}
218
+ aria-current={isCurrent ? 'page' : undefined}
219
+ >
220
+ <div className={`relative z-10 flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-mono font-bold transition-colors ${
221
+ isCurrent
222
+ ? 'bg-accent text-white shadow-sm shadow-accent/30'
223
+ : isPast
224
+ ? 'bg-accent/20 text-accent'
225
+ : 'bg-muted/10 text-muted group-hover:bg-muted/20 group-hover:text-foreground'
226
+ }`}>
227
+ {String(item + 1).padStart(2, '0')}
228
+ </div>
229
+ <div className="flex-1 min-w-0 pt-0.5">
230
+ <span className={`block text-sm leading-snug transition-colors ${
231
+ isCurrent
232
+ ? 'text-accent font-semibold'
233
+ : isPast
234
+ ? 'text-foreground/70 group-hover:text-foreground'
235
+ : 'text-muted group-hover:text-foreground'
236
+ }`}>
237
+ {post.title}
238
+ </span>
239
+ </div>
240
+ </Link>
241
+ </li>
242
+ );
243
+ })}
244
+ </ul>
245
+ </nav>
246
+
247
+ <Link
248
+ href={`/series/${seriesSlug}`}
249
+ className="text-xs font-sans text-muted hover:text-accent transition-colors no-underline flex items-center gap-1"
250
+ >
251
+ {t('view_full_series')}
252
+ <svg className="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
253
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
254
+ </svg>
255
+ </Link>
256
+ </>
257
+ )}
258
+ </div>
259
+ )}
260
+
261
+ {shareUrl && siteConfig.share?.enabled && (
262
+ <div className="mt-6 pt-6 border-t border-muted/10">
263
+ <p className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted mb-3">
264
+ {t('share_post')}
265
+ </p>
266
+ <ShareBar url={shareUrl} title={shareTitle ?? ''} />
267
+ </div>
268
+ )}
223
269
  </aside>
224
270
  );
225
271
  }
@@ -1,28 +1,13 @@
1
1
  'use client';
2
2
 
3
- import { useState, useEffect, useCallback } from 'react';
3
+ import { useScrollY } from '@/hooks/useScrollY';
4
4
 
5
5
  export default function ReadingProgressBar() {
6
- const [progress, setProgress] = useState(0);
7
-
8
- const handleScroll = useCallback(() => {
9
- const scrollTop = window.scrollY;
10
- const docHeight = document.documentElement.scrollHeight - window.innerHeight;
11
- if (docHeight > 0) {
12
- setProgress(Math.min(100, Math.max(0, (scrollTop / docHeight) * 100)));
13
- }
14
- }, []);
15
-
16
- useEffect(() => {
17
- // Initial check on mount via animation frame to avoid cascading render error
18
- const rafId = requestAnimationFrame(handleScroll);
19
-
20
- window.addEventListener('scroll', handleScroll, { passive: true });
21
- return () => {
22
- cancelAnimationFrame(rafId);
23
- window.removeEventListener('scroll', handleScroll);
24
- };
25
- }, [handleScroll]);
6
+ const scrollY = useScrollY();
7
+ const docHeight = typeof document !== 'undefined'
8
+ ? document.documentElement.scrollHeight - window.innerHeight
9
+ : 0;
10
+ const progress = docHeight > 0 ? Math.min(100, Math.max(0, (scrollY / docHeight) * 100)) : 0;
26
11
 
27
12
  if (progress <= 0) return null;
28
13
 
@@ -6,7 +6,7 @@ export default function RelatedPosts({ posts }: { posts: PostData[] }) {
6
6
  if (!posts || posts.length === 0) return null;
7
7
 
8
8
  return (
9
- <div className="mt-16 pt-12 border-t border-muted/20">
9
+ <div className="mt-12 pt-12 border-t border-muted/20">
10
10
  <h3 className="text-2xl font-serif font-bold text-heading mb-8">{t('related_posts')}</h3>
11
11
  <div className="grid grid-cols-1 md:grid-cols-3 gap-8">
12
12
  {posts.map(post => (
@@ -6,6 +6,8 @@ import Link from 'next/link';
6
6
  import { useLanguage } from '@/components/LanguageProvider';
7
7
  import { type ContentType, getResultType, getDateFromUrl, cleanTitle } from '@/lib/search-utils';
8
8
  import type { TranslationKey } from '@/i18n/translations';
9
+ import { siteConfig } from '../../site.config';
10
+ import { resolveLocaleValue } from '@/lib/i18n';
9
11
  // ─── Types ───────────────────────────────────────────────────────────────────
10
12
 
11
13
  interface DisplayResult {
@@ -18,7 +20,18 @@ interface DisplayResult {
18
20
 
19
21
  // ─── Constants ────────────────────────────────────────────────────────────────
20
22
 
21
- const CONTENT_TYPES: ContentType[] = ['All', 'Post', 'Flow', 'Book'];
23
+ const CONTENT_TYPES: ContentType[] = [
24
+ 'All',
25
+ ...(siteConfig.features?.posts?.enabled !== false ? ['Post' as ContentType] : []),
26
+ ...(siteConfig.features?.flows?.enabled !== false ? ['Flow' as ContentType] : []),
27
+ ...(siteConfig.features?.books?.enabled !== false ? ['Book' as ContentType] : []),
28
+ ];
29
+
30
+ const CONTENT_TYPE_FEATURE: Record<Exclude<ContentType, 'All'>, keyof typeof siteConfig.features> = {
31
+ Post: 'posts',
32
+ Flow: 'flows',
33
+ Book: 'books',
34
+ };
22
35
  const RECENT_KEY = 'amytis-recent-searches';
23
36
  const MAX_RECENT = 5;
24
37
  const MAX_RESULTS = 8;
@@ -101,7 +114,14 @@ export default function Search() {
101
114
  const [isUnavailable, setIsUnavailable] = useState(false);
102
115
  const searchRef = useRef<HTMLDivElement>(null);
103
116
  const inputRef = useRef<HTMLInputElement>(null);
104
- const { t, tWith } = useLanguage();
117
+ const { t, tWith, language } = useLanguage();
118
+
119
+ const getTypeLabel = (type: Exclude<ContentType, 'All'>): string => {
120
+ const featureKey = CONTENT_TYPE_FEATURE[type];
121
+ const featureName = siteConfig.features?.[featureKey]?.name;
122
+ if (featureName) return resolveLocaleValue(featureName, language);
123
+ return t(TYPE_LABEL_KEYS[type]);
124
+ };
105
125
 
106
126
  // True while debounce is pending — suppress "no results" flash
107
127
  const isTyping = query.length > 0 && query !== debouncedQuery;
@@ -348,7 +368,7 @@ export default function Search() {
348
368
  : 'text-muted hover:text-foreground hover:bg-muted/5'
349
369
  }`}
350
370
  >
351
- {type === 'All' ? t('search_all') : t(TYPE_LABEL_KEYS[type])}
371
+ {type === 'All' ? t('search_all') : getTypeLabel(type)}
352
372
  <span className="ml-1 text-[10px] opacity-60">{typeCounts[type]}</span>
353
373
  <span className="hidden sm:inline ml-1 text-[9px] opacity-30">⌥{i + 1}</span>
354
374
  </button>
@@ -379,7 +399,7 @@ export default function Search() {
379
399
  <span className="text-[10px] font-mono text-muted/60">{result.date}</span>
380
400
  )}
381
401
  <span className={`text-[10px] px-1.5 py-0.5 rounded-full border font-medium ${TYPE_STYLES[result.type]}`}>
382
- {t(TYPE_LABEL_KEYS[result.type])}
402
+ {getTypeLabel(result.type)}
383
403
  </span>
384
404
  </div>
385
405
  </div>
@@ -2,6 +2,7 @@
2
2
 
3
3
  import Link from 'next/link';
4
4
  import CoverImage from './CoverImage';
5
+ import HorizontalScroll from './HorizontalScroll';
5
6
  import { useLanguage } from './LanguageProvider';
6
7
 
7
8
  export interface BookItem {
@@ -16,12 +17,15 @@ export interface BookItem {
16
17
 
17
18
  interface SelectedBooksSectionProps {
18
19
  books: BookItem[];
20
+ maxItems?: number;
21
+ scrollThreshold?: number;
19
22
  }
20
23
 
21
- export default function SelectedBooksSection({ books }: SelectedBooksSectionProps) {
24
+ export default function SelectedBooksSection({ books, maxItems = 4, scrollThreshold = 2 }: SelectedBooksSectionProps) {
22
25
  const { t } = useLanguage();
26
+ const displayed = books.slice(0, maxItems);
23
27
 
24
- if (books.length === 0) return null;
28
+ if (displayed.length === 0) return null;
25
29
 
26
30
  return (
27
31
  <section className="mb-24">
@@ -31,9 +35,10 @@ export default function SelectedBooksSection({ books }: SelectedBooksSectionProp
31
35
  {t('all_books')} →
32
36
  </Link>
33
37
  </div>
34
- <div className="grid grid-cols-1 md:grid-cols-2 gap-8">
35
- {books.map(book => (
36
- <Link key={book.slug} href={`/books/${book.slug}`} className="group block no-underline">
38
+ <HorizontalScroll itemCount={displayed.length} scrollThreshold={scrollThreshold}>
39
+ <div className={`flex gap-8 ${displayed.length > scrollThreshold ? 'pb-4' : ''}`}>
40
+ {displayed.map(book => (
41
+ <Link key={book.slug} href={`/books/${book.slug}`} className={`group block no-underline ${displayed.length > scrollThreshold ? 'w-[85vw] md:w-[calc(50%-1rem)] flex-shrink-0 snap-start' : 'flex-1'}`}>
37
42
  <div className="card-base h-full group flex flex-col p-0 overflow-hidden">
38
43
  <div className="relative h-48 w-full overflow-hidden bg-muted/10">
39
44
  <CoverImage
@@ -74,7 +79,8 @@ export default function SelectedBooksSection({ books }: SelectedBooksSectionProp
74
79
  </div>
75
80
  </Link>
76
81
  ))}
77
- </div>
82
+ </div>
83
+ </HorizontalScroll>
78
84
  </section>
79
85
  );
80
86
  }
@@ -0,0 +1,115 @@
1
+ 'use client'
2
+
3
+ import { useState } from 'react';
4
+ import { IconType } from 'react-icons';
5
+ import { FaXTwitter, FaFacebook, FaLinkedin, FaWeibo, FaRedditAlien, FaTelegram, FaMastodon, FaHackerNews } from 'react-icons/fa6';
6
+ import { SiBluesky, SiDouban, SiZhihu } from 'react-icons/si';
7
+ import { LuLink, LuCheck } from 'react-icons/lu';
8
+ import { siteConfig } from '../../site.config';
9
+ import { useLanguage } from './LanguageProvider';
10
+
11
+ interface ShareBarProps {
12
+ url: string;
13
+ title: string;
14
+ className?: string;
15
+ }
16
+
17
+ type Platform =
18
+ | 'twitter' | 'facebook' | 'linkedin' | 'weibo'
19
+ | 'reddit' | 'hackernews' | 'telegram' | 'bluesky' | 'mastodon'
20
+ | 'douban' | 'zhihu'
21
+ | 'copy';
22
+
23
+ const PLATFORM_META: Record<Platform, { label: string; Icon: IconType }> = {
24
+ twitter: { label: 'X / Twitter', Icon: FaXTwitter },
25
+ facebook: { label: 'Facebook', Icon: FaFacebook },
26
+ linkedin: { label: 'LinkedIn', Icon: FaLinkedin },
27
+ weibo: { label: '微博', Icon: FaWeibo },
28
+ reddit: { label: 'Reddit', Icon: FaRedditAlien },
29
+ hackernews: { label: 'Hacker News', Icon: FaHackerNews },
30
+ telegram: { label: 'Telegram', Icon: FaTelegram },
31
+ bluesky: { label: 'Bluesky', Icon: SiBluesky },
32
+ mastodon: { label: 'Mastodon', Icon: FaMastodon },
33
+ douban: { label: '豆瓣', Icon: SiDouban },
34
+ zhihu: { label: '知乎', Icon: SiZhihu },
35
+ copy: { label: 'Copy link', Icon: LuLink },
36
+ };
37
+
38
+ function getShareUrl(platform: Platform, url: string, title: string): string {
39
+ const eu = encodeURIComponent(url);
40
+ const et = encodeURIComponent(title);
41
+ const combined = encodeURIComponent(`${title} ${url}`);
42
+ switch (platform) {
43
+ case 'twitter': return `https://twitter.com/intent/tweet?text=${et}&url=${eu}`;
44
+ case 'facebook': return `https://www.facebook.com/sharer/sharer.php?u=${eu}`;
45
+ case 'linkedin': return `https://www.linkedin.com/sharing/share-offsite/?url=${eu}`;
46
+ case 'weibo': return `https://service.weibo.com/share/share.php?url=${eu}&title=${et}`;
47
+ case 'reddit': return `https://www.reddit.com/submit?url=${eu}&title=${et}`;
48
+ case 'hackernews': return `https://news.ycombinator.com/submitlink?u=${eu}&t=${et}`;
49
+ case 'telegram': return `https://t.me/share/url?url=${eu}&text=${et}`;
50
+ case 'bluesky': return `https://bsky.app/intent/compose?text=${combined}`;
51
+ case 'mastodon': return `https://mastodon.social/share?text=${combined}`;
52
+ case 'douban': return `https://www.douban.com/share/service?href=${eu}&name=${et}`;
53
+ case 'zhihu': return `https://www.zhihu.com/share?href=${eu}&type=text&title=${et}`;
54
+ case 'copy': return '';
55
+ }
56
+ }
57
+
58
+ export default function ShareBar({ url, title, className = '' }: ShareBarProps) {
59
+ const { t } = useLanguage();
60
+ const [copied, setCopied] = useState(false);
61
+
62
+ if (!siteConfig.share?.enabled) return null;
63
+ const configured = siteConfig.share?.platforms ?? [];
64
+ const platforms = configured.filter((p): p is Platform => p in PLATFORM_META);
65
+ if (platforms.length === 0) return null;
66
+
67
+ const handleCopy = async () => {
68
+ try {
69
+ await navigator.clipboard.writeText(url);
70
+ setCopied(true);
71
+ setTimeout(() => setCopied(false), 2000);
72
+ } catch {
73
+ // clipboard not available
74
+ }
75
+ };
76
+
77
+ const btnClass = 'inline-flex items-center justify-center w-8 h-8 rounded text-muted hover:text-accent hover:bg-muted/10 transition-colors';
78
+
79
+ return (
80
+ <div className={`flex flex-row flex-wrap gap-1 ${className}`}>
81
+ {platforms.map((platform) => {
82
+ const { label, Icon } = PLATFORM_META[platform];
83
+
84
+ if (platform === 'copy') {
85
+ const copyLabel = copied ? t('link_copied') : t('copy_link');
86
+ return (
87
+ <button
88
+ key={platform}
89
+ onClick={handleCopy}
90
+ title={copyLabel}
91
+ aria-label={copyLabel}
92
+ className={`${btnClass} ${copied ? 'text-accent' : ''}`}
93
+ >
94
+ {copied ? <LuCheck size={16} /> : <Icon size={16} />}
95
+ </button>
96
+ );
97
+ }
98
+
99
+ return (
100
+ <a
101
+ key={platform}
102
+ href={getShareUrl(platform, url, title)}
103
+ target="_blank"
104
+ rel="noopener noreferrer"
105
+ title={label}
106
+ aria-label={`Share on ${label}`}
107
+ className={`${btnClass} no-underline`}
108
+ >
109
+ <Icon size={16} />
110
+ </a>
111
+ );
112
+ })}
113
+ </div>
114
+ );
115
+ }
@@ -2,30 +2,21 @@
2
2
 
3
3
  import { useLanguage } from './LanguageProvider';
4
4
  import { TranslationKey } from '@/i18n/translations';
5
- import { resolveLocaleValue } from '@/lib/i18n';
6
5
 
7
6
  interface SimpleLayoutHeaderProps {
8
7
  title: string;
9
8
  excerpt?: string;
10
9
  titleKey?: TranslationKey;
11
10
  subtitleKey?: TranslationKey;
12
- titleOverride?: string | Record<string, string>;
13
- subtitleOverride?: string | Record<string, string>;
11
+ contentLocales?: Record<string, { content: string; title?: string; excerpt?: string }>;
14
12
  }
15
13
 
16
- export default function SimpleLayoutHeader({ title, excerpt, titleKey, subtitleKey, titleOverride, subtitleOverride }: SimpleLayoutHeaderProps) {
14
+ export default function SimpleLayoutHeader({ title, excerpt, titleKey, subtitleKey, contentLocales }: SimpleLayoutHeaderProps) {
17
15
  const { t, language } = useLanguage();
18
16
 
19
- const displayTitle = titleOverride
20
- ? resolveLocaleValue(titleOverride, language)
21
- : titleKey
22
- ? t(titleKey)
23
- : title;
24
- const displaySubtitle = subtitleOverride
25
- ? resolveLocaleValue(subtitleOverride, language)
26
- : subtitleKey
27
- ? t(subtitleKey)
28
- : excerpt;
17
+ const localeData = contentLocales?.[language];
18
+ const displayTitle = localeData?.title ?? (titleKey ? t(titleKey) : title);
19
+ const displaySubtitle = localeData?.excerpt ?? (subtitleKey ? t(subtitleKey) : excerpt);
29
20
 
30
21
  return (
31
22
  <header className="page-header">