11'use client' ;
22
3- import { useCallback , useEffect , useState } from 'react' ;
4- import Link from 'next/link' ;
53import clsx from 'clsx' ;
6- import { useParams } from 'next/navigation'
7- import { allPosts } from 'contentlayer/generated'
8- import { PencilIcon } from './icons/PencilIcon' ;
4+ import { allPosts } from 'contentlayer/generated' ;
5+ import Link from 'next/link' ;
6+ import { useParams } from 'next/navigation' ;
7+ import { useCallback , useEffect , useState } from 'react' ;
98import { BugIcon } from './icons/BugIcon' ;
9+ import { Globe } from './icons/Globe' ;
10+ import { PencilIcon } from './icons/PencilIcon' ;
1011
1112interface Heading {
1213 level : number ;
@@ -23,11 +24,11 @@ type ParamsType = {
2324 slug : string [ ] ;
2425}
2526
26- export function TableOfContents ( { headings} : Props ) {
27+ export function TableOfContents ( { headings } : Props ) {
2728 let [ currentSection , setCurrentSection ] = useState ( headings [ 0 ] ?. id ) ;
2829 const [ path , setPath ] = useState ( '' )
2930 const params : ParamsType = useParams ( )
30-
31+
3132 let getHeadings = useCallback ( ( headings : Heading [ ] ) => {
3233 return headings
3334 . map ( heading => {
@@ -42,15 +43,15 @@ export function TableOfContents({headings}: Props) {
4243 window . scrollY +
4344 el . getBoundingClientRect ( ) . top -
4445 scrollMt ;
45- return { id : heading . id , top} ;
46+ return { id : heading . id , top } ;
4647 }
4748 } )
48- . filter ( ( x ) : x is { id : string ; top : number } => x !== null ) ;
49+ . filter ( ( x ) : x is { id : string ; top : number } => x !== null ) ;
4950 } , [ ] ) ;
50-
51+
5152 useEffect ( ( ) => {
5253 const path = params . slug . join ( '/' ) ;
53-
54+
5455 if ( allPosts ) {
5556 const post = allPosts . find ( post => post . _raw . flattenedPath === path ) ;
5657 if ( post ) {
@@ -81,7 +82,7 @@ export function TableOfContents({headings}: Props) {
8182 setCurrentSection ( current ) ;
8283 }
8384
84- window . addEventListener ( 'scroll' , onScroll , { passive : true } ) ;
85+ window . addEventListener ( 'scroll' , onScroll , { passive : true } ) ;
8586 onScroll ( ) ;
8687
8788 return ( ) => {
@@ -156,6 +157,17 @@ export function TableOfContents({headings}: Props) {
156157 Edit this page on GitHub
157158 </ a >
158159 </ div >
160+ < div className = "flex items-center mt-2 text-sm" >
161+ < a
162+ href = { `https://sourcegraph.com/` }
163+ target = "_blank"
164+ rel = "noopener noreferrer"
165+ className = "flex items-center text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
166+ >
167+ < Globe className = "mr-1 h-4 w-4" />
168+ Go to Sourcegraph.com
169+ </ a >
170+ </ div >
159171 < div className = "flex items-center mt-2 text-sm" >
160172 < a
161173 href = "https://community.sourcegraph.com"
0 commit comments