File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 11---
2- import { getLinkToKey } from " ../lib/doc-index " ;
2+ import { isLinkMissing , normalizeLink } from " ../lib/doc-link " ;
33
44interface Props {
55 src: string ;
66 section? : string ;
77}
88
99const { src, section } = Astro .props ;
10- const rawLink = await getLinkToKey (src );
1110
12- const missing = rawLink === undefined ;
13- const link = rawLink ? rawLink + (section ? " #" + section : " " ) : " " ;
11+ const missing = await isLinkMissing ( src ) ;
12+ const link = normalizeLink ( src ) + (section ? " #" + section : " " );
1413---
1514
1615{
Original file line number Diff line number Diff line change 1+ import { getEntry } from "astro:content" ;
2+
3+ function getIdFromLink ( link : string ) : string {
4+ if ( link . startsWith ( "/" ) ) {
5+ link = link . slice ( 1 ) ;
6+ }
7+ if ( link . endsWith ( "/" ) ) {
8+ link = link . slice ( 0 , - 1 ) ;
9+ }
10+ return link ;
11+ }
12+
13+ export function normalizeLink ( link : string ) : string {
14+ if ( ! link . startsWith ( "/" ) ) {
15+ link = "/" + link ;
16+ }
17+ if ( ! link . endsWith ( "/" ) ) {
18+ link = link + "/" ;
19+ }
20+ return link ;
21+ }
22+
23+ export async function isLinkMissing ( link : string ) : Promise < boolean > {
24+ const id = getIdFromLink ( link ) ;
25+ const entry = await getEntry ( "docs" , id ) ;
26+ return entry === undefined ;
27+ }
You can’t perform that action at this time.
0 commit comments