@hutusi/amytis 1.6.0 → 1.8.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 (92) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/GEMINI.md +12 -2
  3. package/README.md +14 -0
  4. package/TODO.md +24 -16
  5. package/bun.lock +8 -3
  6. package/content/about.mdx +1 -0
  7. package/content/about.zh.mdx +21 -0
  8. package/content/flows/2026/02/05.md +0 -1
  9. package/content/flows/2026/02/10.mdx +2 -1
  10. package/content/flows/2026/02/15.md +2 -1
  11. package/content/flows/2026/02/18.mdx +2 -1
  12. package/content/flows/2026/02/20.md +15 -0
  13. package/content/links.mdx +42 -0
  14. package/content/links.zh.mdx +41 -0
  15. package/content/notes/algorithms-and-data-structures.mdx +51 -0
  16. package/content/notes/digital-garden-philosophy.mdx +36 -0
  17. package/content/notes/react-server-components.mdx +49 -0
  18. package/content/notes/tailwind-v4.mdx +45 -0
  19. package/content/notes/zettelkasten-method.mdx +33 -0
  20. package/content/posts/2026-02-20-i18n-routing-considerations.mdx +150 -0
  21. package/content/posts/multimedia-showcase/index.mdx +261 -0
  22. package/content/privacy.mdx +32 -0
  23. package/content/privacy.zh.mdx +32 -0
  24. package/docs/ARCHITECTURE.md +16 -0
  25. package/docs/CONTRIBUTING.md +11 -0
  26. package/docs/DIGITAL_GARDEN.md +64 -0
  27. package/package.json +8 -3
  28. package/scripts/copy-assets.ts +1 -1
  29. package/scripts/generate-knowledge-graph.ts +162 -0
  30. package/scripts/new-flow.ts +0 -5
  31. package/scripts/new-note.ts +53 -0
  32. package/site.config.ts +146 -44
  33. package/src/app/[slug]/page.tsx +0 -10
  34. package/src/app/archive/page.tsx +38 -10
  35. package/src/app/books/[slug]/page.tsx +18 -0
  36. package/src/app/flows/[year]/[month]/[day]/page.tsx +51 -31
  37. package/src/app/flows/[year]/[month]/page.tsx +15 -13
  38. package/src/app/flows/[year]/page.tsx +22 -15
  39. package/src/app/flows/page/[page]/page.tsx +3 -9
  40. package/src/app/flows/page.tsx +3 -8
  41. package/src/app/globals.css +41 -0
  42. package/src/app/graph/page.tsx +19 -0
  43. package/src/app/layout.tsx +47 -21
  44. package/src/app/notes/[slug]/page.tsx +128 -0
  45. package/src/app/notes/page/[page]/page.tsx +58 -0
  46. package/src/app/notes/page.tsx +31 -0
  47. package/src/app/page.tsx +134 -72
  48. package/src/app/posts/[slug]/page.tsx +8 -12
  49. package/src/app/search.json/route.ts +15 -1
  50. package/src/app/series/[slug]/page.tsx +18 -0
  51. package/src/app/subscribe/page.tsx +17 -0
  52. package/src/app/tags/[tag]/page.tsx +9 -26
  53. package/src/app/tags/page.tsx +3 -8
  54. package/src/components/AuthorCard.tsx +43 -0
  55. package/src/components/Backlinks.tsx +39 -0
  56. package/src/components/Comments.tsx +20 -4
  57. package/src/components/ExternalLinks.tsx +6 -2
  58. package/src/components/FlowCalendarSidebar.tsx +4 -2
  59. package/src/components/FlowContent.tsx +4 -3
  60. package/src/components/FlowHubTabs.tsx +50 -0
  61. package/src/components/FlowTimelineEntry.tsx +7 -9
  62. package/src/components/Footer.tsx +35 -26
  63. package/src/components/KnowledgeGraph.tsx +324 -0
  64. package/src/components/LanguageProvider.tsx +0 -5
  65. package/src/components/LanguageSwitch.tsx +117 -6
  66. package/src/components/LocaleSwitch.tsx +33 -0
  67. package/src/components/MarkdownRenderer.tsx +13 -2
  68. package/src/components/Navbar.tsx +266 -17
  69. package/src/components/NoteContent.tsx +123 -0
  70. package/src/components/NoteSidebar.tsx +132 -0
  71. package/src/components/PostNavigation.tsx +55 -0
  72. package/src/components/PostSidebar.tsx +172 -126
  73. package/src/components/ReadingProgressBar.tsx +6 -21
  74. package/src/components/RecentNotesSection.tsx +6 -11
  75. package/src/components/RelatedPosts.tsx +1 -1
  76. package/src/components/Search.tsx +29 -5
  77. package/src/components/SelectedBooksSection.tsx +12 -6
  78. package/src/components/ShareBar.tsx +115 -0
  79. package/src/components/SimpleLayoutHeader.tsx +5 -14
  80. package/src/components/SubscribePage.tsx +298 -0
  81. package/src/components/TagContentTabs.tsx +102 -0
  82. package/src/components/TagPageHeader.tsx +7 -13
  83. package/src/components/TagSidebar.tsx +142 -0
  84. package/src/components/TagsIndexClient.tsx +156 -0
  85. package/src/hooks/useScrollY.ts +41 -0
  86. package/src/i18n/translations.ts +105 -1
  87. package/src/layouts/PostLayout.tsx +40 -8
  88. package/src/layouts/SimpleLayout.tsx +53 -15
  89. package/src/lib/markdown.ts +347 -18
  90. package/src/lib/remark-wikilinks.ts +59 -0
  91. package/src/lib/search-utils.ts +2 -1
  92. package/src/components/TableOfContents.tsx +0 -158
@@ -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,6 @@ import { useLanguage } from './LanguageProvider';
6
6
  export interface RecentNoteItem {
7
7
  slug: string;
8
8
  date: string;
9
- title: string;
10
9
  excerpt: string;
11
10
  }
12
11
 
@@ -38,16 +37,12 @@ export default function RecentNotesSection({ notes }: RecentNotesSectionProps) {
38
37
  {notes.map(note => (
39
38
  <div key={note.slug} className="relative pl-6 pb-6 border-l-2 border-muted/20 last:pb-0">
40
39
  <div className="absolute -left-[5px] top-1.5 w-2 h-2 rounded-full bg-accent" />
41
- <div className="flex items-baseline gap-3 mb-1">
42
- <time className="text-xs font-mono text-accent shrink-0">{note.date}</time>
43
- <Link
44
- href={`/flows/${note.slug}`}
45
- className="text-base font-serif font-bold text-heading hover:text-accent transition-colors no-underline truncate"
46
- >
47
- {note.title}
48
- </Link>
49
- </div>
50
- <p className="text-sm text-muted line-clamp-2 pl-0">{note.excerpt}</p>
40
+ <Link href={`/flows/${note.slug}`} className="no-underline group">
41
+ <time className="text-sm font-mono text-accent group-hover:text-accent/70 transition-colors">{note.date}</time>
42
+ </Link>
43
+ {note.excerpt && (
44
+ <p className="mt-1.5 text-sm text-muted line-clamp-2">{note.excerpt}</p>
45
+ )}
51
46
  </div>
52
47
  ))}
53
48
  </div>
@@ -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,20 @@ 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
+ ...(siteConfig.features?.notes?.enabled !== false ? ['Note' as ContentType] : []),
29
+ ];
30
+
31
+ const CONTENT_TYPE_FEATURE: Record<Exclude<ContentType, 'All'>, keyof typeof siteConfig.features> = {
32
+ Post: 'posts',
33
+ Flow: 'flows',
34
+ Book: 'books',
35
+ Note: 'notes',
36
+ };
22
37
  const RECENT_KEY = 'amytis-recent-searches';
23
38
  const MAX_RECENT = 5;
24
39
  const MAX_RESULTS = 8;
@@ -29,12 +44,14 @@ const TYPE_LABEL_KEYS: Record<Exclude<ContentType, 'All'>, TranslationKey> = {
29
44
  Post: 'search_type_post',
30
45
  Flow: 'search_type_flow',
31
46
  Book: 'search_type_book',
47
+ Note: 'search_type_note',
32
48
  };
33
49
 
34
50
  const TYPE_STYLES: Record<string, string> = {
35
51
  Flow: 'border-accent/30 text-accent',
36
52
  Book: 'border-foreground/30 text-foreground/60',
37
53
  Post: 'border-muted/30 text-muted',
54
+ Note: 'border-emerald-400/30 text-emerald-600 dark:text-emerald-400',
38
55
  };
39
56
 
40
57
  // ─── Helpers ──────────────────────────────────────────────────────────────────
@@ -101,7 +118,14 @@ export default function Search() {
101
118
  const [isUnavailable, setIsUnavailable] = useState(false);
102
119
  const searchRef = useRef<HTMLDivElement>(null);
103
120
  const inputRef = useRef<HTMLInputElement>(null);
104
- const { t, tWith } = useLanguage();
121
+ const { t, tWith, language } = useLanguage();
122
+
123
+ const getTypeLabel = (type: Exclude<ContentType, 'All'>): string => {
124
+ const featureKey = CONTENT_TYPE_FEATURE[type];
125
+ const featureName = siteConfig.features?.[featureKey]?.name;
126
+ if (featureName) return resolveLocaleValue(featureName, language);
127
+ return t(TYPE_LABEL_KEYS[type]);
128
+ };
105
129
 
106
130
  // True while debounce is pending — suppress "no results" flash
107
131
  const isTyping = query.length > 0 && query !== debouncedQuery;
@@ -172,7 +196,7 @@ export default function Search() {
172
196
 
173
197
  // Count per type for tab badges
174
198
  const typeCounts = useMemo(() => {
175
- const counts: Record<ContentType, number> = { All: allResults.length, Post: 0, Flow: 0, Book: 0 };
199
+ const counts: Record<ContentType, number> = { All: allResults.length, Post: 0, Flow: 0, Book: 0, Note: 0 };
176
200
  for (const r of allResults) counts[r.type]++;
177
201
  return counts;
178
202
  }, [allResults]);
@@ -348,7 +372,7 @@ export default function Search() {
348
372
  : 'text-muted hover:text-foreground hover:bg-muted/5'
349
373
  }`}
350
374
  >
351
- {type === 'All' ? t('search_all') : t(TYPE_LABEL_KEYS[type])}
375
+ {type === 'All' ? t('search_all') : getTypeLabel(type)}
352
376
  <span className="ml-1 text-[10px] opacity-60">{typeCounts[type]}</span>
353
377
  <span className="hidden sm:inline ml-1 text-[9px] opacity-30">⌥{i + 1}</span>
354
378
  </button>
@@ -379,7 +403,7 @@ export default function Search() {
379
403
  <span className="text-[10px] font-mono text-muted/60">{result.date}</span>
380
404
  )}
381
405
  <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])}
406
+ {getTypeLabel(result.type)}
383
407
  </span>
384
408
  </div>
385
409
  </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">
@@ -0,0 +1,298 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import Image from 'next/image';
5
+ import Link from 'next/link';
6
+ import { useLanguage } from './LanguageProvider';
7
+ import { siteConfig } from '../../site.config';
8
+ import { LuCheck, LuCopy, LuExternalLink, LuGithub, LuMail } from 'react-icons/lu';
9
+
10
+ // ─── Platform SVG icons ────────────────────────────────────────────────────────
11
+
12
+ function RssIcon() {
13
+ return (
14
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
15
+ <path d="M6.18 15.64a2.18 2.18 0 0 1 2.18 2.18C8.36 19.01 7.38 20 6.18 20 4.98 20 4 19.01 4 17.82a2.18 2.18 0 0 1 2.18-2.18M4 4.44A15.56 15.56 0 0 1 19.56 20h-2.83A12.73 12.73 0 0 0 4 7.27V4.44m0 5.66a9.9 9.9 0 0 1 9.9 9.9h-2.83A7.07 7.07 0 0 0 4 12.93V10.1z" />
16
+ </svg>
17
+ );
18
+ }
19
+
20
+ function TelegramIcon() {
21
+ return (
22
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
23
+ <path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z" />
24
+ </svg>
25
+ );
26
+ }
27
+
28
+ function WechatIcon() {
29
+ return (
30
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
31
+ <path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-7.062-6.122zm-3.518 3.507c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982z" />
32
+ </svg>
33
+ );
34
+ }
35
+
36
+ function SubstackIcon() {
37
+ return (
38
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
39
+ <path d="M22.539 8.242H1.46V5.406h21.08v2.836zM1.46 10.812V24L12 18.11 22.54 24V10.812H1.46zM22.54 0H1.46v2.836h21.08V0z" />
40
+ </svg>
41
+ );
42
+ }
43
+
44
+ function XIcon() {
45
+ return (
46
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
47
+ <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.742l7.775-8.906L2.003 2.25H8.08l4.261 5.628 5.903-5.628zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
48
+ </svg>
49
+ );
50
+ }
51
+
52
+ // ─── Shared card wrapper ───────────────────────────────────────────────────────
53
+
54
+ interface CardProps {
55
+ icon: React.ReactNode;
56
+ title: string;
57
+ description: string;
58
+ children: React.ReactNode;
59
+ wide?: boolean;
60
+ }
61
+
62
+ function SubscribeCard({ icon, title, description, children, wide }: CardProps) {
63
+ return (
64
+ <div className={`rounded-2xl border border-muted/20 bg-muted/5 p-6 space-y-4${wide ? ' md:col-span-2' : ''}`}>
65
+ <div className="flex items-center gap-3">
66
+ <div className="w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center text-accent flex-shrink-0">
67
+ {icon}
68
+ </div>
69
+ <h2 className="font-serif font-bold text-xl text-heading">{title}</h2>
70
+ </div>
71
+ <p className="text-sm text-muted/70 leading-relaxed">{description}</p>
72
+ {children}
73
+ </div>
74
+ );
75
+ }
76
+
77
+ // ─── Main component ────────────────────────────────────────────────────────────
78
+
79
+ export default function SubscribePage() {
80
+ const { t } = useLanguage();
81
+ const [copied, setCopied] = useState(false);
82
+
83
+ const { baseUrl, social, subscribe } = siteConfig;
84
+ const feedUrl = `${baseUrl}/feed.xml`;
85
+ const enc = encodeURIComponent(feedUrl);
86
+
87
+ const rssReaders = [
88
+ { name: 'Follow', url: `https://app.follow.is/add?url=${enc}` },
89
+ { name: 'Feedly', url: `https://feedly.com/i/subscription/feed/${enc}` },
90
+ { name: 'Inoreader', url: `https://www.inoreader.com/?add_feed=${enc}` },
91
+ { name: 'NewsBlur', url: `https://newsblur.com/?url=${enc}` },
92
+ { name: 'The Old Reader', url: `https://theoldreader.com/feeds/subscribe?url=${enc}` },
93
+ ];
94
+
95
+ const hasSubstack = !!subscribe?.substack;
96
+ const hasEmail = !!subscribe?.email;
97
+ const hasTelegram = !!subscribe?.telegram;
98
+ const hasWechat = !!subscribe?.wechat?.qrCode;
99
+ const hasNewsletter = hasSubstack || hasEmail;
100
+
101
+ const handleCopy = async () => {
102
+ try {
103
+ await navigator.clipboard.writeText(feedUrl);
104
+ setCopied(true);
105
+ setTimeout(() => setCopied(false), 2000);
106
+ } catch {
107
+ // fallback: select text — clipboard API may not be available in all contexts
108
+ }
109
+ };
110
+
111
+ return (
112
+ <div className="max-w-3xl">
113
+ {/* Page header */}
114
+ <header className="page-header">
115
+ <h1 className="page-title">{t('subscribe')}</h1>
116
+ <p className="page-subtitle">{t('subscribe_subtitle')}</p>
117
+ </header>
118
+
119
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-5">
120
+
121
+ {/* ── RSS Feed ── always visible */}
122
+ <SubscribeCard
123
+ wide
124
+ icon={<RssIcon />}
125
+ title={t('rss_readers')}
126
+ description={t('rss_description')}
127
+ >
128
+ {/* Reader quick-subscribe links */}
129
+ <div className="flex flex-wrap gap-2">
130
+ {rssReaders.map(({ name, url }) => (
131
+ <a
132
+ key={name}
133
+ href={url}
134
+ target="_blank"
135
+ rel="noopener noreferrer"
136
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-lg border border-muted/20 bg-background hover:border-accent hover:text-accent transition-colors no-underline"
137
+ >
138
+ {name}
139
+ <LuExternalLink className="w-3 h-3 opacity-50" />
140
+ </a>
141
+ ))}
142
+ </div>
143
+
144
+ {/* Feed URL with copy button */}
145
+ <div className="flex items-center gap-2 mt-1 px-3 py-2.5 rounded-lg bg-muted/5 border border-muted/15">
146
+ <code className="text-xs font-mono text-muted/60 flex-1 truncate">{feedUrl}</code>
147
+ <button
148
+ onClick={handleCopy}
149
+ className="flex-shrink-0 flex items-center gap-1.5 text-xs text-muted/60 hover:text-accent transition-colors"
150
+ aria-label={t('copy_feed_url')}
151
+ >
152
+ {copied
153
+ ? <><LuCheck className="w-3.5 h-3.5 text-accent" /><span className="text-accent">{t('feed_url_copied')}</span></>
154
+ : <><LuCopy className="w-3.5 h-3.5" /><span>{t('copy_feed_url')}</span></>
155
+ }
156
+ </button>
157
+ </div>
158
+ </SubscribeCard>
159
+
160
+ {/* ── Email / Substack ── conditional */}
161
+ {hasNewsletter && (
162
+ <SubscribeCard
163
+ icon={hasSubstack ? <SubstackIcon /> : <LuMail className="w-5 h-5" />}
164
+ title={t('email_newsletter')}
165
+ description={t('email_newsletter_description')}
166
+ >
167
+ {hasSubstack && (
168
+ <a
169
+ href={subscribe!.substack}
170
+ target="_blank"
171
+ rel="noopener noreferrer"
172
+ className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg bg-accent/10 text-accent hover:bg-accent/20 transition-colors no-underline"
173
+ >
174
+ <SubstackIcon />
175
+ {t('subscribe_on_substack')}
176
+ <LuExternalLink className="w-3.5 h-3.5 opacity-60" />
177
+ </a>
178
+ )}
179
+ {!hasSubstack && hasEmail && (
180
+ <a
181
+ href={subscribe!.email}
182
+ target="_blank"
183
+ rel="noopener noreferrer"
184
+ className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg bg-accent/10 text-accent hover:bg-accent/20 transition-colors no-underline"
185
+ >
186
+ <LuMail className="w-4 h-4" />
187
+ {t('subscribe_via_email')}
188
+ <LuExternalLink className="w-3.5 h-3.5 opacity-60" />
189
+ </a>
190
+ )}
191
+ </SubscribeCard>
192
+ )}
193
+
194
+ {/* ── Telegram ── conditional */}
195
+ {hasTelegram && (
196
+ <SubscribeCard
197
+ icon={<TelegramIcon />}
198
+ title={t('telegram_channel')}
199
+ description={t('telegram_channel_description')}
200
+ >
201
+ <a
202
+ href={subscribe!.telegram}
203
+ target="_blank"
204
+ rel="noopener noreferrer"
205
+ className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg bg-accent/10 text-accent hover:bg-accent/20 transition-colors no-underline"
206
+ >
207
+ <TelegramIcon />
208
+ {t('join_channel')}
209
+ <LuExternalLink className="w-3.5 h-3.5 opacity-60" />
210
+ </a>
211
+ </SubscribeCard>
212
+ )}
213
+
214
+ {/* ── WeChat Official Account ── conditional */}
215
+ {hasWechat && (
216
+ <SubscribeCard
217
+ icon={<WechatIcon />}
218
+ title={t('wechat_official')}
219
+ description={t('wechat_description')}
220
+ >
221
+ <div className="flex flex-col items-start gap-3">
222
+ <div className="w-36 h-36 rounded-xl border border-muted/20 overflow-hidden bg-white flex items-center justify-center">
223
+ <Image
224
+ src={subscribe!.wechat!.qrCode}
225
+ alt={subscribe?.wechat?.account || 'WeChat QR Code'}
226
+ width={144}
227
+ height={144}
228
+ className="object-contain"
229
+ />
230
+ </div>
231
+ {subscribe?.wechat?.account && (
232
+ <p className="text-sm font-mono text-muted/60">{subscribe.wechat.account}</p>
233
+ )}
234
+ <p className="text-xs text-muted/50 italic">{t('scan_qr_code')}</p>
235
+ </div>
236
+ </SubscribeCard>
237
+ )}
238
+
239
+ {/* ── Social connections ── always visible if social links exist */}
240
+ {(social?.twitter || social?.github || social?.email) && (
241
+ <SubscribeCard
242
+ wide={!hasNewsletter && !hasTelegram && !hasWechat}
243
+ icon={
244
+ <svg viewBox="0 0 24 24" className="w-5 h-5" fill="currentColor" aria-hidden="true">
245
+ <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zM12 0C8.741 0 8.333.014 7.053.072 2.695.272.273 2.69.073 7.052.014 8.333 0 8.741 0 12c0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98C8.333 23.986 8.741 24 12 24c3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98C15.668.014 15.259 0 12 0zm0 5.838a6.162 6.162 0 1 0 0 12.324 6.162 6.162 0 0 0 0-12.324zM12 16a4 4 0 1 1 0-8 4 4 0 0 1 0 8zm6.406-11.845a1.44 1.44 0 1 0 0 2.881 1.44 1.44 0 0 0 0-2.881z" />
246
+ </svg>
247
+ }
248
+ title={t('social_connections')}
249
+ description="Follow along on social platforms for updates, discussions, and more."
250
+ >
251
+ <div className="flex flex-wrap gap-2">
252
+ {social?.twitter && (
253
+ <a
254
+ href={social.twitter}
255
+ target="_blank"
256
+ rel="noopener noreferrer"
257
+ className="inline-flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg border border-muted/20 bg-background hover:border-accent hover:text-accent transition-colors no-underline"
258
+ >
259
+ <XIcon />
260
+ Twitter / X
261
+ </a>
262
+ )}
263
+ {social?.github && (
264
+ <a
265
+ href={social.github}
266
+ target="_blank"
267
+ rel="noopener noreferrer"
268
+ className="inline-flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg border border-muted/20 bg-background hover:border-accent hover:text-accent transition-colors no-underline"
269
+ >
270
+ <LuGithub className="w-4 h-4" />
271
+ GitHub
272
+ </a>
273
+ )}
274
+ {social?.email && (
275
+ <a
276
+ href={social.email}
277
+ className="inline-flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg border border-muted/20 bg-background hover:border-accent hover:text-accent transition-colors no-underline"
278
+ >
279
+ <LuMail className="w-4 h-4" />
280
+ Email
281
+ </a>
282
+ )}
283
+ </div>
284
+ </SubscribeCard>
285
+ )}
286
+
287
+ </div>
288
+
289
+ {/* Tip note about RSS */}
290
+ <p className="mt-10 text-xs text-muted/50 text-center">
291
+ RSS is an open standard — no account required. Copy the feed URL into any reader app.{' '}
292
+ <Link href="/feed.xml" className="hover:text-accent transition-colors" target="_blank">
293
+ View raw feed →
294
+ </Link>
295
+ </p>
296
+ </div>
297
+ );
298
+ }