Communitygithub.com

目录(ToC)系统

设计并实现一个系统化的页面内导航框架,通过滚动同步的链接,让用户在长格式内容中定位并直接跳转到文档各部分。

目录(ToC)系统 是什么?

目录(ToC)系统是一个专注于页面内导航的AI Agent技能,旨在解决长格式内容中的"滚动疲劳"问题。它通过提供页面结构的持续可视化地图,帮助用户理解当前上下文,并即时跳转到特定章节。该技能适用于文档、技术指南、长篇文章、复杂着陆页及政策页面等场景。它支持多种布局模式(如持久侧边栏、内联摘要、粘性页眉),并集成了滚动监听(Scroll-Spy)机制,实现活动状态与视口的实时同步。此外,系统还包含响应式适配、可访问性(ARIA标准)、决策规则(如三层深度限制)以及验证标准,确保导航体验既高效又符合无障碍设计规范。该技能可集成到Claude Code、Cursor等AI编程助手中,为开发者提供从内容审核到最终实现的完整框架。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/coastdigitalgroup/coastai-skills/tree/HEAD/website-design/table-of-contents-system

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

目录(ToC)系统 是做什么的?

目的

目录(ToC)系统提供了一种为单页或文档设计页面内导航菜单的方法。它解决了长格式内容中的“滚动疲劳”问题,通过持续展示页面层次结构的可视地图,让用户了解其当前上下文,并能够在不迷失位置的情况下直接跳转到特定章节。

使用场景

  • 文档和技术指南: 浏览标题和子标题的深层层次结构。
  • 长篇文章和博客帖子: 为 2000 字以上的编辑内容提供路线图。
  • 复杂的着陆页: 帮助用户在功能、定价和常见问题解答部分之间跳转。
  • 法律和政策页面: 浏览密集的条款和编号部分。
  • 资源中心: 在单个页面上组织大量的链接或工具列表。

何时不使用

  • 短内容(少于 3 个部分): 如果整个页面可以在两次滚动内浏览完毕,则添加目录会产生不必要的视觉噪音。
  • 主导航: 不要使用目录在不同的页面之间移动,应使用 site-navigation-system。
  • 线性向导: 对于用户必须遵循固定顺序的逐步流程,请使用 step-progress-system。
  • 极简主义营销: 目标是实现单一、不间断的叙事流程,不提供转移注意力的内容。

输入

  1. 标题层级: 页面上的 <h2> 到 <h4> 标签的映射。
  2. 布局上下文: 可用的水平空间(侧边栏 vs 内联)。
  3. 滚动容器: 滚动发生在 body 上还是特定的溢出容器上?
  4. 品牌令牌: 来自设计系统的间距、排版和“活动”状态颜色。

输出

  1. 目录结构规范: 列表项、缩进级别和“活动”指示器的视觉定义。
  2. 滚动监听蓝图: 当用户滚动时,“活动”状态如何更新的逻辑。
  3. 响应式适配图: 目录如何从桌面侧边栏转换为移动实用工具(例如,粘性页眉或底部抽屉)。
  4. 寻路规范: 平滑滚动行为和焦点管理的定义。

工作流程

1. 审核文档大纲

提取标题结构。清晰的目录依赖于逻辑上的 h1 -> h2 -> h3 递进。

  • 主级别: 通常从 <h2> 标签派生。
  • 次级别: 从 <h3> 标签派生(缩进)。
  • 第三级别: 除非文档非常密集,否则很少在目录中显示;考虑默认折叠这些级别。

2. 选择布局模式

根据页面布局选择空间安排:

  • 持久侧边栏(右侧/左侧): 最适合宽屏(桌面)。始终保持地图可见。
  • 内联摘要: 放置在文章顶部。最适合移动设备或中等长度的内容,无需“粘性”。
  • 粘性页眉/浮动栏: 仅在滚动过首屏后出现的简化版本。

3. 建立视觉层次结构(级别)

应用 visual-hierarchy-system 来表示深度:

  • 缩进: 使用一致的水平内边距(例如,每级别 --space-s)来显示父子关系。
  • 排版: 对子级别(h3)使用比主级别(h2)更小的字号或更柔和的颜色。
  • 指示器: 在列表的左侧/右侧使用垂直“进度线”来视觉连接项目。

4. 设计滚动监听(活动)状态

目录必须与用户的视口保持同步:

  • 活动链接: 高亮显示与当前位于视口顶部的章节相对应的链接。
  • “活动线”效果: 如果使用垂直线,请为标记设置动画,使其滑动到活动项目的位置。
  • 反馈延迟: 确保活动状态快速(<100ms)更新,但包含一个小的缓冲,以防止在标题之间滚动时闪烁。

5. 规划响应式寻路

侧边栏通常在移动设备上消失;请提供替代方案:

  • 移动目录触发器: 屏幕顶部或底部的粘性按钮(例如,“在此部分中”),用于打开抽屉。
  • 渐进式显示: 在粘性栏中仅显示当前的 <h2>,并带有展开完整列表的箭头。

决策规则

  • “三级”限制: 永远不要在目录中显示超过 3 个深度级别。如果内容更深,则简化目录以仅关注 h2 和 h3。
  • 缩进优先于图标: 使用缩进来显示层次结构,而不是项目符号或图标,这会使密集的文本列表变得杂乱。
  • 活动状态的唯一性: 目录中一次只能有一个项目处于“活动”状态。
  • 粘性阈值: 目录只有在到达视口顶部时才应变为粘性(固定),而不是在页面加载时立即固定。
  • 点击跳转: 单击目录链接必须使用“平滑滚动”,以防止迷失方向,并且必须更新 URL 哈希(#section-id)以便分享。

约束条件

  • 可访问性: 目录必须包含在带有 aria-label="Table of contents" 的 <nav> 中。活动链接必须使用 aria-current="true"(或 aria-current="location")。确保在通过 Tab 键浏览链接时焦点环可见。
  • 对比度: 活动和非活动状态必须满足 WCAG AA(4.5:1)要求。
  • 响应式: 在移动设备上,目录不得与主要文本内容重叠;应使用抽屉或可切换的部分。
  • 内容同步: 目录中的链接文本应与标题文本完全匹配(或者是清晰可辨的缩写版本)。

常见失败模式

  • “过时”状态: 由于滚动监听触发点设置得过高或过低,目录高亮显示了错误的章节。
  • 内容遮挡: 粘性目录覆盖了它本应帮助用户阅读的文本。
  • 深度过载: 显示每一个 h4 和 h5,使目录比视口还长,需要自己的滚动条(避免嵌套滚动条)。
  • 缺少 ID: 由于标题缺少匹配的 id 属性而导致链接无法工作。
  • 返回按钮失效: 跳转到章节时未更新 URL 哈希,导致用户无法使用浏览器的“返回”按钮返回到目录。

验证标准

  • h2 和 h3 级别之间存在清晰的视觉层次结构(缩进)。
  • 滚动监听能随着用户滚动正确高亮显示活动章节。
  • 单击链接会平滑滚动到正确的章节。
  • 单击目录链接后会更新 URL 哈希。
  • 目录包含在 <nav aria-label="Table of contents"> 地标中。
  • 活动状态可通过 aria-current 访问。
  • 定义了特定于移动设备的寻路模式(例如,抽屉或粘性栏)。
  • 显示的层次结构不超过 3 个级别。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for progressive disclosure using accordions, ensuring structural integrity, visual affordances, and accessibility across different content densities and devices.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for long-form content, managing readability, vertical rhythm, and information density to ensure a superior reading experience.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for informational elements that communicate state (Badges) and categorization (Tags) with clarity and accessibility.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for non-overlay notifications, managing global announcements and contextual inline alerts to communicate system states without interrupting the user's flow.

coastdigitalgroup/coastai-skills

Design and implement a systematic, asymmetrical bento-grid layout framework to organize diverse content types cohesively while maintaining strict visual hierarchy, logical focus order, and responsive flexibility.

coastdigitalgroup/coastai-skills

Design a responsive, mobile-first bottom navigation bar and persistent action dock system for mobile websites and web applications, establishing spatial anchors, tab bar anatomy, badge indicators, thumb-zone ergonomics, safe area inset handling, active/inactive state contrast, and desktop responsive adaptation rules.

coastdigitalgroup/coastai-skills

Design a mobile-first bottom sheet overlay system with configurable detents, drag affordances, safe area padding, responsive desktop modal/popover adaptation, and WCAG AA accessibility compliance.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for secondary navigation trails that provide orientation, context, and one-click access to parent levels in deep information architectures.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for buttons and interactive triggers, managing visual hierarchy, variant logic, and action grouping to ensure clear intent and accessible interaction.

coastdigitalgroup/coastai-skills

Design a systematic framework for date and time selection, managing calendar grids, range pickers, and scheduling interfaces to ensure precision and accessibility.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for modular content containers that maintain hierarchy, structural integrity, and action alignment across variable content and responsive viewports.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for horizontal discovery components, managing navigation affordances, scroll behavior, and accessibility to ensure effective content density without compromising usability.

coastdigitalgroup/coastai-skills

Design a systematic, highly accessible, and developer-friendly UI layout framework for code blocks, snippet showcases, multi-file code tabs, line-highlighting, diff views, and syntax token contrast in technical documentation and developer platforms.

coastdigitalgroup/coastai-skills

Design a systematic framework for global command menus (Cmd+K panels) that combines keyboard-driven navigation, command execution, and shortcut discovery into an accessible, responsive overlay.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for threaded conversations, managing nesting depths, action hierarchies, and community signaling to foster engagement and readability.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for side-by-side comparison interfaces, managing high attribute density and responsive complexity to support informed decision-making.

coastdigitalgroup/coastai-skills

Design and implement a systematic framework for user privacy, managing consent banners, preference centers, and persistent privacy controls to balance legal compliance with user trust.

coastdigitalgroup/coastai-skills

Design and implement a systematic, highly accessible, and responsive visual layout framework for conversational chat widgets, live chat boxes, and chatbot panels that ensures clear message scannability, native focus flow, and seamless mobile keyboard adaptation.

coastdigitalgroup/coastai-skills

Design a systematic, accessible, and high-conversion framework for custom select dropdowns and comboboxes, defining anatomy, states, search-filtering, and responsive mobile-adaptive patterns.

coastdigitalgroup/coastai-skills

Design and implement a systematic color palette that ensures WCAG 2.2 accessibility compliance. Trigger this skill when asked to define brand colors, create UI themes, or establish a visual system for a website.

相关技能