Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import starlightHeadingBadges from "starlight-heading-badges";
export default defineConfig({
site: process.env.CPPDOC_SITE,
base: process.env.CPPDOC_BASE,
trailingSlash: "never",
trailingSlash: "always",
integrations: [
starlight({
title: "CppDoc",
Expand Down
7 changes: 3 additions & 4 deletions src/components/DocLink.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
import { getLinkToKey } from "../lib/doc-index";
import { isLinkMissing, normalizeLink } from "../lib/doc-link";
interface Props {
src: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this property to something like dest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this property to something like dest?

OK! All existing mdx doc files need to change the property used in DocLink too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build will fail until all <DocLink src=...> is substituted by <DocLink dest=...>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build will fail until all <DocLink src=...> is substituted by <DocLink dest=...>

All occurrences are replaced.

section?: string;
}
const { src, section } = Astro.props;
const rawLink = await getLinkToKey(src);
const missing = rawLink === undefined;
const link = rawLink ? rawLink + (section ? "#" + section : "") : "";
const missing = await isLinkMissing(src);
const link = normalizeLink(src) + (section ? "#" + section : "");
---

{
Expand Down
5 changes: 3 additions & 2 deletions src/content/docs/development/migration/guideline.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ sidebar:
---

import { Aside } from "@astrojs/starlight/components";
import DocLink from "@components/DocLink.astro"

This document gives guidelines to migrate content from cppreference to CppDoc.

<Aside type="tip">
For a more detailed guideline about writing CppDoc contents, please check out the [development guideline](../guide).
For a more detailed guideline about writing CppDoc contents, please check out the <DocLink src="/development/guide">development guideline</DocLink>.
</Aside>

<Aside type="note">
Expand All @@ -35,4 +36,4 @@ The `since` and `until` fields are both optional.

## Cross References

Cross references are links within a CppDoc page that point to another CppDoc page. Please make sure all cross references are established using the [`DocLink` component](../guide/doc-everything#link-to-another-cppdoc-page).
Cross references are links within a CppDoc page that point to another CppDoc page. Please make sure all cross references are established using the <DocLink src="/development/guide/doc-everything" section="link-to-another-cppdoc-page">`DocLink` component</DocLink>.
80 changes: 0 additions & 80 deletions src/lib/doc-index.ts

This file was deleted.

27 changes: 27 additions & 0 deletions src/lib/doc-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getEntry } from "astro:content";

function getIdFromLink(link: string): string {
if (link.startsWith("/")) {
link = link.slice(1);
}
if (link.endsWith("/")) {
link = link.slice(0, -1);
}
return link;
}

export function normalizeLink(link: string): string {
if (!link.startsWith("/")) {
link = "/" + link;
}
if (!link.endsWith("/")) {
link = link + "/";
}
return link;
}

export async function isLinkMissing(link: string): Promise<boolean> {
const id = getIdFromLink(link);
const entry = await getEntry("docs", id);
return entry === undefined;
}