Skip to content

Commit 4292e66

Browse files
authored
chore: now DocLink works without keys (#79)
1 parent d24153e commit 4292e66

File tree

16 files changed

+91
-146
lines changed

16 files changed

+91
-146
lines changed

astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import starlightHeadingBadges from "starlight-heading-badges";
1010
export default defineConfig({
1111
site: process.env.CPPDOC_SITE,
1212
base: process.env.CPPDOC_BASE,
13-
trailingSlash: "never",
13+
trailingSlash: "always",
1414
integrations: [
1515
starlight({
1616
title: "CppDoc",

src/components/DocLink.astro

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
---
2-
import { getLinkToKey } from "../lib/doc-index";
2+
import { isLinkMissing, normalizeLink } from "../lib/doc-link";
33
44
interface Props {
5-
src: string;
5+
dest: string;
66
section?: string;
77
}
88
9-
const { src, section } = Astro.props;
10-
const rawLink = await getLinkToKey(src);
9+
const { dest, section } = Astro.props;
1110
12-
const missing = rawLink === undefined;
13-
const link = rawLink ? rawLink + (section ? "#" + section : "") : "";
11+
const missing = await isLinkMissing(dest);
12+
const link = normalizeLink(dest) + (section ? "#" + section : "");
1413
---
1514

1615
{
1716
missing ? (
18-
<span class="doc-link missing" title={`${src} (missing)`}>
17+
<span class="doc-link missing" title={`${dest} (missing)`}>
1918
<slot />
2019
</span>
2120
) : (
22-
<a class="doc-link" href={link} title={src}>
21+
<a class="doc-link" href={link} title={dest}>
2322
<slot />
2423
</a>
2524
)

src/components/NamedReq.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ interface Props {
99
}
1010
1111
const { name, bold, displayName, nolink } = Astro.props;
12-
const src = `/cpp/named_req/${name}`;
12+
const dest = `/cpp/named_req/${name}`;
1313
1414
const text = displayName ?? name;
1515
1616
const As = nolink ? Fragment : DocLink;
17-
const asProps = nolink ? {} : { src };
17+
const asProps = nolink ? {} : { dest };
1818
---
1919

2020
<As {...asProps}>

src/components/header/Header.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export interface Props {
1111
1212
const { lang, name, displayName, nolink } = Astro.props;
1313
const langPrefix = lang == "C" ? "/c" : "/cpp";
14-
const src = `${langPrefix}/library/headers/${name}`;
14+
const dest = `${langPrefix}/library/headers/${name}`;
1515
1616
const extension = lang === "C" ? ".h" : "";
1717
const text = displayName ?? `<${name}${extension}>`;
1818
1919
const As = nolink ? Fragment : DocLink;
20-
const asProps = nolink ? {} : { src };
20+
const asProps = nolink ? {} : { dest };
2121
---
2222

2323
<As {...asProps}>

src/content/docs/c/comment.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ Comments serve as a sort of in-code documentation. When inserted into a program,
1414
1) Often known as "C-style" or "multi-line" comments.
1515
2) Often known as "C++-style" or "single-line" comments.
1616

17-
All comments are removed from the program at <DocLink src="/c/language/translation_phases">translation phase 3</DocLink> by replacing each comment with a single whitespace character.
17+
All comments are removed from the program at <DocLink dest="/c/language/translation_phases">translation phase 3</DocLink> by replacing each comment with a single whitespace character.
1818

1919
### C-style
2020

2121
C-style comments are usually used to comment large blocks of text or small fragments of code; however, they can be used to comment single lines. To insert text as a C-style comment, simply surround the text with `/*` and `*/`. C-style comments tell the compiler to ignore all content between `/*` and `*/`. Although it is not part of the C standard, `/**` and `**/` are often used to indicate documentation blocks; this is legal because the second asterisk is simply treated as part of the comment.
2222

23-
Except within a <DocLink src="/c/language/character_constant">character constant</DocLink>, a <DocLink src="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `/*` introduce a comment. The contents of such a comment are examined only to identify multibyte characters and to find the characters `*/` that terminate the comment. C-style comments cannot be nested.
23+
Except within a <DocLink dest="/c/language/character_constant">character constant</DocLink>, a <DocLink dest="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `/*` introduce a comment. The contents of such a comment are examined only to identify multibyte characters and to find the characters `*/` that terminate the comment. C-style comments cannot be nested.
2424

2525
<RevisionBlock since="C99">
2626

2727
### C++-style
2828

2929
C++-style comments are usually used to comment single lines of text or code; however, they can be placed together to form multi-line comments. To insert text as a C++-style comment, simply precede the text with `//` and follow the text with the new line character. C++-style comments tell the compiler to ignore all content between `//` and a new line.
3030

31-
Except within a <DocLink src="/c/language/character_constant">character constant</DocLink>, a <DocLink src="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `//` introduce a comment that includes all multibyte characters up to, but not including, the next new-line character. The contents of such a comment are examined only to identify multibyte characters and to find the new-line character that terminates the comment. C++-style comments can be nested:
31+
Except within a <DocLink dest="/c/language/character_constant">character constant</DocLink>, a <DocLink dest="/c/language/string_literal">string literal</DocLink>, or a comment, the characters `//` introduce a comment that includes all multibyte characters up to, but not including, the next new-line character. The contents of such a comment are examined only to identify multibyte characters and to find the new-line character that terminates the comment. C++-style comments can be nested:
3232

3333
```c
3434
// y = f(x); // invoke algorithm
@@ -53,7 +53,7 @@ A C++-style comment may appear within a C-style comment; this is a mechanism for
5353

5454
### Notes
5555

56-
Because comments <DocLink src="/c/language/translation_phases">are removed</DocLink> before the preprocessor stage, a macro cannot be used to form a comment and an unterminated C-style comment doesn't spill over from an #include'd file.
56+
Because comments <DocLink dest="/c/language/translation_phases">are removed</DocLink> before the preprocessor stage, a macro cannot be used to form a comment and an unterminated C-style comment doesn't spill over from an #include'd file.
5757

5858
```c
5959
/* An attempt to use a macro to form a comment. */
@@ -151,6 +151,6 @@ Hello, again
151151

152152
<DescList>
153153
<Desc>
154-
<DocLink slot="item" src="/cpp/comments">C++ documentation</DocLink> for <span>Comments</span>
154+
<DocLink slot="item" dest="/cpp/comments">C++ documentation</DocLink> for <span>Comments</span>
155155
</Desc>
156156
</DescList>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import DocLink from "@components/DocLink.astro";
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 <DocLink src="/c/language/declarations">declarations</DocLink>. They undergo <DocLink src="/c/language/translation_phases">translation</DocLink> to become an executable program, which is executed when the OS calls its <DocLink src="/c/language/main_function">main function</DocLink> (unless it is itself the OS or another *freestanding* program, in which case the entry point is implementation-defined).
15+
A C program is a sequence of text files (typically header and source files) that contain <DocLink dest="/c/language/declarations">declarations</DocLink>. They undergo <DocLink dest="/c/language/translation_phases">translation</DocLink> to become an executable program, which is executed when the OS calls its <DocLink dest="/c/language/main_function">main function</DocLink> (unless it is itself the OS or another *freestanding* program, in which case the entry point is implementation-defined).
1616

17-
Certain words in a C program have special meaning, they are <DocLink src="/c/keyword">keywords</DocLink>. Others can be used as <DocLink src="/c/language/identifier">identifiers</DocLink>, which may be used to identify <DocLink src="/c/language/object">objects</DocLink>, <DocLink src="/c/language/functions">functions</DocLink>, <DocLink src="/c/language/struct">struct</DocLink>, <DocLink src="/c/language/union">union</DocLink>, or <DocLink src="/c/language/enum">enumeration</DocLink> tags, their members, <DocLink src="/c/language/typedef">typedef</DocLink> names, <DocLink src="/c/language/statements">labels</DocLink>, or <DocLink src="/c/preprocessor/replace">macros</DocLink>.
17+
Certain words in a C program have special meaning, they are <DocLink dest="/c/keyword">keywords</DocLink>. Others can be used as <DocLink dest="/c/language/identifier">identifiers</DocLink>, which may be used to identify <DocLink dest="/c/language/object">objects</DocLink>, <DocLink dest="/c/language/functions">functions</DocLink>, <DocLink dest="/c/language/struct">struct</DocLink>, <DocLink dest="/c/language/union">union</DocLink>, or <DocLink dest="/c/language/enum">enumeration</DocLink> tags, their members, <DocLink dest="/c/language/typedef">typedef</DocLink> names, <DocLink dest="/c/language/statements">labels</DocLink>, or <DocLink dest="/c/preprocessor/replace">macros</DocLink>.
1818

19-
Each identifier (other than macro) is only valid within a part of the program called its <DocLink src="/c/language/scope">scope</DocLink> and belongs to one of four kinds of <DocLink src="/c/language/name_space">name spaces</DocLink>. Some identifiers have <DocLink src="/c/language/storage_duration">linkage</DocLink> which makes them refer to the same entities when they appear in different scopes or translation units.
19+
Each identifier (other than macro) is only valid within a part of the program called its <DocLink dest="/c/language/scope">scope</DocLink> and belongs to one of four kinds of <DocLink dest="/c/language/name_space">name spaces</DocLink>. Some identifiers have <DocLink dest="/c/language/storage_duration">linkage</DocLink> which makes them refer to the same entities when they appear in different scopes or translation units.
2020

21-
Definitions of functions include sequences of <DocLink src="/c/language/statements">statements</DocLink> and <DocLink src="/c/language/declarations">declarations</DocLink>, some of which include <DocLink src="/c/language/expressions">expressions</DocLink>, which specify the computations to be performed by the program.
21+
Definitions of functions include sequences of <DocLink dest="/c/language/statements">statements</DocLink> and <DocLink dest="/c/language/declarations">declarations</DocLink>, some of which include <DocLink dest="/c/language/expressions">expressions</DocLink>, which specify the computations to be performed by the program.
2222

23-
<DocLink src="/c/language/declarations">Declarations</DocLink> and <DocLink src="/c/language/expressions">expressions</DocLink> create, destroy, access, and manipulate <DocLink src="/c/language/object">objects</DocLink>. Each <DocLink src="/c/language/object">object</DocLink>, <DocLink src="/c/language/functions">function</DocLink>, and <DocLink src="/c/language/expressions">expression</DocLink> in C is associated with a <DocLink src="/c/language/type">type</DocLink>.
23+
<DocLink dest="/c/language/declarations">Declarations</DocLink> and <DocLink dest="/c/language/expressions">expressions</DocLink> create, destroy, access, and manipulate <DocLink dest="/c/language/object">objects</DocLink>. Each <DocLink dest="/c/language/object">object</DocLink>, <DocLink dest="/c/language/functions">function</DocLink>, and <DocLink dest="/c/language/expressions">expression</DocLink> in C is associated with a <DocLink dest="/c/language/type">type</DocLink>.

0 commit comments

Comments
 (0)