Skip to content

Commit ca63d0c

Browse files
refactor(DocLink): allow absolute path and src
1 parent 6626017 commit ca63d0c

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/components/DocLink.astro

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
import { getLinkToKey } from "../lib/doc-index";
33
44
interface Props {
5-
dest: string;
5+
src: string;
66
}
77
8-
const { dest } = Astro.props;
9-
const rawLink = await getLinkToKey(dest);
8+
const { src } = Astro.props;
9+
const rawLink = await getLinkToKey(src);
1010
1111
const missing = rawLink === undefined;
1212
const link = rawLink ?? "";
1313
---
1414

1515
{
1616
missing ? (
17-
<span class="doc-link missing" title={`${dest} (missing)`}>
17+
<span class="doc-link missing" title={`${src} (missing)`}>
1818
<slot />
1919
</span>
2020
) : (
21-
<a class="doc-link" href={link} title={dest}>
21+
<a class="doc-link" href={link} title={src}>
2222
<slot />
2323
</a>
2424
)

src/content/docs/cpp/language/basic_concepts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Revision } from "@components/revision";
1212

1313
This section provides definitions for the specific terminology and the concepts used when describing the C++ programming language.
1414

15-
A C++ program is a sequence of text files (typically header and source files) that contain <Missing>declarations</Missing>. They undergo <Missing>translation</Missing> to become an executable program, which is executed when the C++ implementation calls its <DocLink dest="cpp.lang.main">main function</DocLink>.
15+
A C++ program is a sequence of text files (typically header and source files) that contain <Missing>declarations</Missing>. They undergo <Missing>translation</Missing> to become an executable program, which is executed when the C++ implementation calls its <DocLink src="/cpp/language/main_function">main function</DocLink>.
1616

1717
Certain words in a C++ program have special meaning, and these are known as <Missing>keywords</Missing>. Others can be used as <Missing>identifiers</Missing>. <Missing>Comments</Missing> are ignored during translation. C++ programs also contain <Missing>literals</Missing>, the values of characters inside them are determined by <Missing>character sets and encodings</Missing>. Certain characters in the program have to be represented with <Missing>escape sequences</Missing>.
1818

src/content/docs/development/guide/doc-everything.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,24 @@ cppdoc:
290290
While a page can have multiple doc keys, each unique doc key can only be associated to at most one page.
291291
</Aside>
292292

293-
The `DocLink` component allows you to render an inline link to the page associated with the specified doc key.
293+
The `DocLink` component allows you to render an inline link to the page associated with the specified doc key. You can also specify the destination page by its absolute path.
294294

295295
```mdx
296296
import DocLink from "@components/DocLink.astro";
297297

298298
Check out
299-
<DocLink key="cpp.library.utilities.move">this page</DocLink>
299+
<DocLink src="cpp.library.utilities.move">this page</DocLink>
300+
for more information about `std::move`.
301+
302+
Check out
303+
<DocLink src="/cpp/library/utilities/move">this page</DocLink>
300304
for more information about `std::move`.
301305
```
302306

303307
<Card title="Preview">
304-
Check out <DocLink key="cpp.library.utilities.move">this page</DocLink> for detailed information about `std::move`.
308+
Check out <DocLink src="cpp.library.utilities.move">this page</DocLink> for detailed information about `std::move`.
309+
310+
Check out <DocLink src="/cpp/library/utilities/move">this page</DocLink> for more information about `std::move`.
305311
</Card>
306312

307313
<Aside type="tip">

src/lib/doc-index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ async function getOrBuildKeyIndex(): Promise<Map<string, string>> {
5757
*/
5858
export async function getLinkToKey(key: string): Promise<string | undefined> {
5959
const index = await getOrBuildKeyIndex();
60-
if (key.startsWith("/")) {
61-
if (Object.values(index).some(slug => `/${slug}/` === key || `/${slug}` === key))
60+
if (key?.startsWith("/")) {
61+
if (index.values().some(slug => `/${slug}/` === key || `/${slug}` === key))
6262
return key;
6363
else
6464
return undefined;

0 commit comments

Comments
 (0)