@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
@@ -0,0 +1,123 @@
1
+ 'use client';
2
+
3
+ import { useState, useMemo } from 'react';
4
+ import { useLanguage } from '@/components/LanguageProvider';
5
+ import Link from 'next/link';
6
+ import Tag from '@/components/Tag';
7
+ import Pagination from '@/components/Pagination';
8
+
9
+ interface NoteItem {
10
+ slug: string;
11
+ date: string;
12
+ title: string;
13
+ excerpt: string;
14
+ tags: string[];
15
+ }
16
+
17
+ interface NoteContentProps {
18
+ notes: NoteItem[];
19
+ tags: Record<string, number>;
20
+ pagination?: {
21
+ currentPage: number;
22
+ totalPages: number;
23
+ basePath: string;
24
+ };
25
+ }
26
+
27
+ export default function NoteContent({ notes, tags, pagination }: NoteContentProps) {
28
+ const { t } = useLanguage();
29
+ const [selectedTag, setSelectedTag] = useState<string | null>(null);
30
+
31
+ const filteredNotes = useMemo(() => {
32
+ if (!selectedTag) return notes;
33
+ return notes.filter(n => n.tags.map(t => t.toLowerCase()).includes(selectedTag));
34
+ }, [notes, selectedTag]);
35
+
36
+ const sortedTags = Object.entries(tags).sort((a, b) => b[1] - a[1]);
37
+
38
+ function handleTagSelect(tag: string) {
39
+ setSelectedTag(prev => (prev === tag ? null : tag));
40
+ }
41
+
42
+ return (
43
+ <div className="flex gap-10">
44
+ {/* Tag sidebar */}
45
+ <aside className="hidden lg:block sticky top-20 self-start w-[280px] shrink-0">
46
+ <div className="border border-muted/20 rounded-lg p-4 space-y-1">
47
+ {sortedTags.length > 0 && (
48
+ <>
49
+ <p className="text-[10px] font-bold uppercase tracking-widest text-muted mb-3">{t('tags')}</p>
50
+ <button
51
+ onClick={() => setSelectedTag(null)}
52
+ className={`block w-full text-left text-sm px-2 py-1 rounded transition-colors ${!selectedTag ? 'text-accent font-medium' : 'text-muted hover:text-foreground'}`}
53
+ >
54
+ {t('all_notes')}
55
+ </button>
56
+ {sortedTags.map(([tag, count]) => (
57
+ <button
58
+ key={tag}
59
+ onClick={() => handleTagSelect(tag)}
60
+ className={`flex w-full items-center justify-between text-left text-sm px-2 py-1 rounded transition-colors ${selectedTag === tag ? 'text-accent font-medium' : 'text-muted hover:text-foreground'}`}
61
+ >
62
+ <span>{tag}</span>
63
+ <span className="text-xs opacity-50">{count}</span>
64
+ </button>
65
+ ))}
66
+ </>
67
+ )}
68
+ </div>
69
+ </aside>
70
+
71
+ {/* Note timeline */}
72
+ <div className="flex-1 min-w-0">
73
+ {selectedTag && (
74
+ <div className="flex items-center gap-2 mb-4 text-sm text-muted">
75
+ <span>{filteredNotes.length} / {notes.length}</span>
76
+ <button
77
+ onClick={() => setSelectedTag(null)}
78
+ className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-muted/20 text-xs hover:border-accent hover:text-accent transition-colors"
79
+ >
80
+ ✕ {t('clear')}
81
+ </button>
82
+ </div>
83
+ )}
84
+
85
+ {filteredNotes.length === 0 ? (
86
+ <p className="text-muted">{t('no_notes')}</p>
87
+ ) : (
88
+ <div className="space-y-0">
89
+ {filteredNotes.map(note => (
90
+ <article key={note.slug} className="relative pl-6 pb-8 border-l-2 border-muted/20 last:pb-0">
91
+ <div className="absolute -left-[5px] top-1.5 w-2 h-2 rounded-full bg-accent" />
92
+ <time className="text-xs font-mono text-accent">{note.date}</time>
93
+ <h3 className="mt-1 mb-2 font-serif text-xl font-bold text-heading">
94
+ <Link href={`/notes/${note.slug}`} className="no-underline hover:text-accent transition-colors">
95
+ {note.title}
96
+ </Link>
97
+ </h3>
98
+ <p className="text-sm text-muted leading-relaxed line-clamp-3">{note.excerpt}</p>
99
+ {note.tags.length > 0 && (
100
+ <div className="mt-2 flex flex-wrap gap-2">
101
+ {note.tags.map(tag => (
102
+ <Tag key={tag} tag={tag} variant="compact" />
103
+ ))}
104
+ </div>
105
+ )}
106
+ </article>
107
+ ))}
108
+ </div>
109
+ )}
110
+
111
+ {pagination && pagination.totalPages > 1 && (
112
+ <div className="mt-12">
113
+ <Pagination
114
+ currentPage={pagination.currentPage}
115
+ totalPages={pagination.totalPages}
116
+ basePath={pagination.basePath}
117
+ />
118
+ </div>
119
+ )}
120
+ </div>
121
+ </div>
122
+ );
123
+ }
@@ -0,0 +1,132 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect, type ReactNode } from 'react';
4
+ import Link from 'next/link';
5
+ import { useScrollY } from '@/hooks/useScrollY';
6
+ import type { BacklinkSource, Heading } from '@/lib/markdown';
7
+ import { useLanguage } from './LanguageProvider';
8
+
9
+ interface NoteSidebarProps {
10
+ headings: Heading[];
11
+ showToc: boolean;
12
+ backlinks: BacklinkSource[];
13
+ breadcrumb?: ReactNode;
14
+ }
15
+
16
+ export default function NoteSidebar({ headings, showToc, backlinks, breadcrumb }: NoteSidebarProps) {
17
+ const { t } = useLanguage();
18
+ const scrollY = useScrollY();
19
+ const [activeHeadingId, setActiveHeadingId] = useState('');
20
+ const [tocCollapsed, setTocCollapsed] = useState(false);
21
+
22
+ useEffect(() => {
23
+ if (!showToc || headings.length === 0) return;
24
+ const elements = headings
25
+ .map(h => document.getElementById(h.id))
26
+ .filter(Boolean) as HTMLElement[];
27
+ if (!elements.length) return;
28
+ const scrollPosition = scrollY + 100;
29
+ let current = elements[0];
30
+ for (const el of elements) {
31
+ if (el.offsetTop <= scrollPosition) current = el;
32
+ else break;
33
+ }
34
+ const rafId = requestAnimationFrame(() => { if (current) setActiveHeadingId(current.id); });
35
+ return () => cancelAnimationFrame(rafId);
36
+ }, [scrollY, headings, showToc]);
37
+
38
+ const scrollToHeading = (e: React.MouseEvent<HTMLAnchorElement>, id: string) => {
39
+ e.preventDefault();
40
+ const el = document.getElementById(id);
41
+ if (el) {
42
+ window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 80, behavior: 'smooth' });
43
+ history.pushState(null, '', `#${id}`);
44
+ }
45
+ };
46
+
47
+ return (
48
+ <aside 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">
49
+ {breadcrumb && <div className="mb-4">{breadcrumb}</div>}
50
+ {/* TOC */}
51
+ {showToc && headings.length > 0 && (
52
+ <nav
53
+ aria-label="Table of contents"
54
+ className={`mb-6 ${backlinks.length > 0 ? 'pb-6 border-b border-muted/10' : ''}`}
55
+ >
56
+ <div className="flex items-center justify-between mb-3">
57
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted">
58
+ {t('on_this_page')}
59
+ </span>
60
+ <button
61
+ onClick={() => setTocCollapsed(p => !p)}
62
+ className="text-muted hover:text-foreground transition-colors"
63
+ aria-label={tocCollapsed ? 'Expand' : 'Collapse'}
64
+ >
65
+ <svg
66
+ className={`w-3.5 h-3.5 transition-transform duration-200 ${tocCollapsed ? '' : 'rotate-180'}`}
67
+ fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}
68
+ >
69
+ <path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
70
+ </svg>
71
+ </button>
72
+ </div>
73
+ {!tocCollapsed && (
74
+ <ul className="space-y-0.5 border-l border-muted/15 animate-slide-down">
75
+ {headings.map(h => {
76
+ const isActive = h.id === activeHeadingId;
77
+ return (
78
+ <li key={h.id}>
79
+ <a
80
+ href={`#${h.id}`}
81
+ onClick={e => scrollToHeading(e, h.id)}
82
+ className={`block py-1 text-[13px] leading-snug no-underline transition-colors duration-200 ${
83
+ h.level === 3 ? 'pl-6' : 'pl-3'
84
+ } ${
85
+ isActive
86
+ ? 'text-accent font-medium border-l-2 border-accent -ml-px'
87
+ : 'text-foreground/70 hover:text-foreground'
88
+ }`}
89
+ >
90
+ {h.text}
91
+ </a>
92
+ </li>
93
+ );
94
+ })}
95
+ </ul>
96
+ )}
97
+ </nav>
98
+ )}
99
+
100
+ {/* Backlinks */}
101
+ {backlinks.length > 0 && (
102
+ <div>
103
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted block mb-3">
104
+ {t('backlinks')}
105
+ </span>
106
+ <div className="flex flex-col gap-3">
107
+ {backlinks.map(bl => (
108
+ <div key={`${bl.type}-${bl.slug}`} className="flex flex-col gap-0.5">
109
+ <div className="flex items-center gap-1.5 min-w-0">
110
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted/60 border border-muted/20 rounded px-1.5 py-0.5 shrink-0">
111
+ {bl.type}
112
+ </span>
113
+ <Link
114
+ href={bl.url}
115
+ className="text-sm text-heading hover:text-accent no-underline transition-colors truncate"
116
+ >
117
+ {bl.title}
118
+ </Link>
119
+ </div>
120
+ {bl.context && (
121
+ <p className="text-xs text-muted leading-relaxed line-clamp-2 pl-0.5">
122
+ &ldquo;{bl.context}&rdquo;
123
+ </p>
124
+ )}
125
+ </div>
126
+ ))}
127
+ </div>
128
+ </div>
129
+ )}
130
+ </aside>
131
+ );
132
+ }
@@ -0,0 +1,55 @@
1
+ import Link from 'next/link';
2
+ import { PostData } from '@/lib/markdown';
3
+ import { t } from '@/lib/i18n';
4
+
5
+ interface PostNavigationProps {
6
+ prev: PostData | null;
7
+ next: PostData | null;
8
+ }
9
+
10
+ export default function PostNavigation({ prev, next }: PostNavigationProps) {
11
+ if (!prev && !next) return null;
12
+
13
+ return (
14
+ <nav
15
+ className="mt-12 pt-12 border-t border-muted/20 grid grid-cols-1 sm:grid-cols-2 gap-3"
16
+ aria-label={t('post_navigation')}
17
+ >
18
+ {prev ? (
19
+ <Link
20
+ href={`/posts/${prev.slug}`}
21
+ className="group flex flex-col gap-1.5 p-4 rounded-xl border border-muted/15 hover:border-accent/30 hover:bg-accent/5 transition-all no-underline"
22
+ >
23
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted flex items-center gap-1.5">
24
+ <svg className="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
25
+ <path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
26
+ </svg>
27
+ {t('prev')}
28
+ </span>
29
+ <span className="text-sm font-serif font-semibold text-heading group-hover:text-accent transition-colors line-clamp-2 leading-snug">
30
+ {prev.title}
31
+ </span>
32
+ <span className="text-xs font-mono text-muted/60">{prev.date}</span>
33
+ </Link>
34
+ ) : <div />}
35
+
36
+ {next ? (
37
+ <Link
38
+ href={`/posts/${next.slug}`}
39
+ className="group flex flex-col gap-1.5 p-4 rounded-xl border border-muted/15 hover:border-accent/30 hover:bg-accent/5 transition-all no-underline sm:items-end sm:text-right"
40
+ >
41
+ <span className="text-[10px] font-sans font-bold uppercase tracking-widest text-muted flex items-center gap-1.5">
42
+ {t('next')}
43
+ <svg className="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
44
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
45
+ </svg>
46
+ </span>
47
+ <span className="text-sm font-serif font-semibold text-heading group-hover:text-accent transition-colors line-clamp-2 leading-snug">
48
+ {next.title}
49
+ </span>
50
+ <span className="text-xs font-mono text-muted/60">{next.date}</span>
51
+ </Link>
52
+ ) : <div />}
53
+ </nav>
54
+ );
55
+ }
@@ -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
  }