Skip to content

Commit d2e4554

Browse files
authored
1 parent 90e48f5 commit d2e4554

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

src/components/Toc.tsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use client';
22

3-
import {useCallback, useEffect, useState} from 'react';
4-
import Link from 'next/link';
53
import 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';
98
import { BugIcon } from './icons/BugIcon';
9+
import { Globe } from './icons/Globe';
10+
import { PencilIcon } from './icons/PencilIcon';
1011

1112
interface 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"

src/components/icons/Globe.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export function Globe({ className }: { className?: string }) {
2+
return (
3+
<svg
4+
xmlns="http://www.w3.org/2000/svg"
5+
width="24"
6+
height="24"
7+
viewBox="0 0 24 24"
8+
fill="none"
9+
stroke="currentColor"
10+
strokeWidth="2"
11+
strokeLinecap="round"
12+
strokeLinejoin="round"
13+
className={className}
14+
>
15+
<circle cx="12" cy="12" r="10" />
16+
<path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
17+
<path d="M2 12h20" />
18+
</svg>
19+
);
20+
}

0 commit comments

Comments
 (0)