File tree Expand file tree Collapse file tree 2 files changed +32
-21
lines changed
Expand file tree Collapse file tree 2 files changed +32
-21
lines changed Original file line number Diff line number Diff line change 11---
2- import type { CxxRevision , Language } from " @src/types" ;
3- import { getRevisions } from " @src/lib/revision" ;
2+ import type { CxxRevision } from " @src/types" ;
43
5- const pageRevision = Astro .locals .starlightRoute .entry .data .cppdoc ?.revision ;
6- const since = pageRevision ?.since as CxxRevision | undefined ;
7- const until = pageRevision ?.until as CxxRevision | undefined ;
8-
9- // This may look hacky, but we now infer whether the current page is for C or
10- // C++ by examining the page's path in the file system.
11- const path = Astro .locals .starlightRoute .entry .filePath ;
12- let language: Language ;
13- if (pageRevision ?.lang ) {
14- language = pageRevision .lang as Language ;
15- } else if (path .includes (" src/content/docs/cpp/" )) {
16- language = " C++" ;
17- } else {
18- language = " C" ;
4+ interface Props {
5+ revisions: CxxRevision [];
196}
207
21- const revisions = getRevisions ( language , { since , until }) ;
8+ const { revisions } = Astro . props ;
229---
2310
2411<select id =" revision-selector" class =" revision-selector" >
Original file line number Diff line number Diff line change 11---
22import Default from " starlight-heading-badges/components/HeadingBadgesTableOfContents.astro" ;
3- import RevisionSelector from " ../revision/RevisionSelector.astro" ;
3+ import RevisionSelector from " @components/revision/RevisionSelector.astro" ;
4+ import type { CxxRevision , Language } from " @src/types" ;
5+ import { getRevisions } from " @src/lib/revision" ;
6+
7+ const pageRevision = Astro .locals .starlightRoute .entry .data .cppdoc ?.revision ;
8+ const since = pageRevision ?.since as CxxRevision | undefined ;
9+ const until = pageRevision ?.until as CxxRevision | undefined ;
10+
11+ // This may look hacky, but we now infer whether the current page is for C or
12+ // C++ by examining the page's path in the file system.
13+ const path = Astro .locals .starlightRoute .entry .filePath ;
14+ let language: Language | undefined = undefined ;
15+ if (pageRevision ?.lang ) {
16+ language = pageRevision .lang as Language ;
17+ } else if (path .includes (" src/content/docs/cpp/" )) {
18+ language = " C++" ;
19+ } else if (path .includes (" src/content/docs/c/" )) {
20+ language = " C" ;
21+ }
22+
23+ const revisions = language && getRevisions (language , { since , until });
424---
525
6- <div class =" toc-revision-selector" >
7- <RevisionSelector />
8- </div >
26+ {
27+ revisions && revisions .length > 0 && (
28+ <div class = " toc-revision-selector" >
29+ <RevisionSelector revisions = { revisions } />
30+ </div >
31+ )
32+ }
933
1034<Default ><slot /></Default >
1135
You can’t perform that action at this time.
0 commit comments