@hutusi/amytis 1.5.6 → 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 (65) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/CLAUDE.md +3 -2
  3. package/GEMINI.md +13 -6
  4. package/README.md +1 -1
  5. package/TODO.md +21 -76
  6. package/bun.lock +18 -3
  7. package/content/about.mdx +1 -0
  8. package/content/about.zh.mdx +21 -0
  9. package/content/flows/2026/02/20.md +16 -0
  10. package/content/links.mdx +42 -0
  11. package/content/links.zh.mdx +41 -0
  12. package/content/posts/2026-02-20-i18n-routing-considerations.mdx +150 -0
  13. package/content/posts/multimedia-showcase/index.mdx +261 -0
  14. package/content/privacy.mdx +32 -0
  15. package/content/privacy.zh.mdx +32 -0
  16. package/docs/ARCHITECTURE.md +11 -2
  17. package/docs/CONTRIBUTING.md +4 -2
  18. package/docs/deployment.md +9 -1
  19. package/eslint.config.mjs +2 -0
  20. package/package.json +5 -4
  21. package/public/next-image-export-optimizer-hashes.json +0 -3
  22. package/scripts/copy-assets.ts +1 -1
  23. package/site.config.ts +126 -44
  24. package/src/app/[slug]/page.tsx +0 -10
  25. package/src/app/archive/page.tsx +38 -10
  26. package/src/app/books/[slug]/page.tsx +18 -0
  27. package/src/app/flows/[year]/[month]/[day]/page.tsx +21 -4
  28. package/src/app/layout.tsx +48 -21
  29. package/src/app/page.tsx +135 -72
  30. package/src/app/posts/[slug]/page.tsx +6 -12
  31. package/src/app/search.json/route.ts +4 -0
  32. package/src/app/series/[slug]/page.tsx +18 -0
  33. package/src/app/subscribe/page.tsx +17 -0
  34. package/src/app/tags/[tag]/page.tsx +9 -26
  35. package/src/app/tags/page.tsx +3 -8
  36. package/src/components/AuthorCard.tsx +43 -0
  37. package/src/components/Comments.tsx +20 -4
  38. package/src/components/ExternalLinks.tsx +6 -2
  39. package/src/components/Footer.tsx +35 -26
  40. package/src/components/LanguageProvider.tsx +0 -5
  41. package/src/components/LanguageSwitch.tsx +117 -6
  42. package/src/components/LocaleSwitch.tsx +33 -0
  43. package/src/components/Navbar.tsx +31 -8
  44. package/src/components/PostNavigation.tsx +55 -0
  45. package/src/components/PostSidebar.tsx +172 -126
  46. package/src/components/ReadingProgressBar.tsx +6 -21
  47. package/src/components/RelatedPosts.tsx +1 -1
  48. package/src/components/Search.tsx +420 -70
  49. package/src/components/SelectedBooksSection.tsx +12 -6
  50. package/src/components/ShareBar.tsx +115 -0
  51. package/src/components/SimpleLayoutHeader.tsx +5 -14
  52. package/src/components/SubscribePage.tsx +298 -0
  53. package/src/components/TagContentTabs.tsx +103 -0
  54. package/src/components/TagPageHeader.tsx +7 -13
  55. package/src/components/TagSidebar.tsx +142 -0
  56. package/src/components/TagsIndexClient.tsx +156 -0
  57. package/src/hooks/useScrollY.ts +41 -0
  58. package/src/i18n/translations.ts +110 -2
  59. package/src/layouts/PostLayout.tsx +34 -7
  60. package/src/layouts/SimpleLayout.tsx +53 -15
  61. package/src/lib/markdown.ts +71 -15
  62. package/src/lib/search-utils.test.ts +163 -0
  63. package/src/lib/search-utils.ts +39 -0
  64. package/src/types/pagefind.d.ts +42 -0
  65. 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 => (