mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-12 10:30:09 +02:00
DOCUMENTATION: Use relative links instead of absolute links (#2521)
This commit is contained in:
+17
-22
@@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import { Link } from "@mui/material";
|
||||
import { defaultNsApiPage, externalUrlOfNsApiPage, useNavigator } from "../React/Documentation";
|
||||
import { relativeUrlOfNsApiPage, useNavigator } from "../React/Documentation";
|
||||
import { CorruptibleText } from "../React/CorruptibleText";
|
||||
import { Player } from "@player";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
@@ -11,26 +11,6 @@ export const A = (props: React.PropsWithChildren<{ href?: string }>): React.Reac
|
||||
const navigator = useNavigator();
|
||||
const href = props.href ?? "";
|
||||
|
||||
const onClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||
navigator.navigate(href, event.ctrlKey);
|
||||
};
|
||||
if (href === externalUrlOfNsApiPage) {
|
||||
return (
|
||||
<Link
|
||||
onClick={(event) => {
|
||||
navigator.navigate(defaultNsApiPage, event.ctrlKey);
|
||||
}}
|
||||
color={Settings.theme.info}
|
||||
sx={{
|
||||
textDecorationThickness: "3px",
|
||||
textUnderlineOffset: "5px",
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
if (isSpoiler(href)) {
|
||||
return (
|
||||
<span
|
||||
@@ -43,8 +23,23 @@ export const A = (props: React.PropsWithChildren<{ href?: string }>): React.Reac
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const onClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||
navigator.navigate(href, event.ctrlKey);
|
||||
};
|
||||
// In the in-game doc viewer, links are highlighted with an underline, but the color is the same as the normal text.
|
||||
// In order to improve the discoverability of NS API documentation and external links, we change the text color and
|
||||
// make the underline stand out a bit more.
|
||||
const sx =
|
||||
href.includes(relativeUrlOfNsApiPage) || href.startsWith("https://") || href.startsWith("http://")
|
||||
? {
|
||||
textDecorationThickness: "3px",
|
||||
textUnderlineOffset: "5px",
|
||||
color: Settings.theme.info,
|
||||
}
|
||||
: {};
|
||||
return (
|
||||
<Link onClick={onClick} component="button" variant="body1" fontSize="inherit">
|
||||
<Link onClick={onClick} component="button" variant="body1" fontSize="inherit" sx={sx}>
|
||||
{props.children}
|
||||
</Link>
|
||||
);
|
||||
|
||||
@@ -27,9 +27,7 @@ export const defaultNsApiPage = asFilePath("nsDoc/bitburner.ns.md");
|
||||
* If we move or rename "bitburner.ns.md", we must update this constant, "defaultNsApiPage", "openDocExternally", and
|
||||
* the URL in src/Documentation/doc/en/index.md.
|
||||
*/
|
||||
export const externalUrlOfNsApiPage =
|
||||
"https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.ns.md";
|
||||
export const prefixOfHttpUrlOfNsDocs = "https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/";
|
||||
export const relativeUrlOfNsApiPage = "../../../../markdown/bitburner.ns.md";
|
||||
|
||||
const prefixOfRelativeUrlOfNSDoc = "../../../../markdown/bitburner.";
|
||||
|
||||
@@ -120,11 +118,7 @@ export function openDocExternally(path: string): void {
|
||||
* - Relative URL from NS docs to other NS docs (e.g., click the links in NS docs viewer): Open "./bitburner.ns.cloud.md" from "nsDoc/bitburner.ns.md"
|
||||
* - Internal NS docs (e.g., choose a dropdown option in DocumentationAutocomplete): nsDoc/bitburner.ns.md
|
||||
* - Internal non-NS docs: help/getting_started.md
|
||||
* - HTTP URL:
|
||||
* - Point to NS docs. Some non-NS docs pages include links to NS docs. For example: basic/scripts.md has a
|
||||
* link to https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.ns.flags.md. In
|
||||
* these cases, the link always points to a file at https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/
|
||||
* - Point to other places.
|
||||
* - HTTP URL
|
||||
*/
|
||||
export function convertNavigatorHref(
|
||||
href: string,
|
||||
@@ -150,15 +144,12 @@ export function convertNavigatorHref(
|
||||
// Internal NS docs
|
||||
path = asFilePath(href);
|
||||
} else if (href.startsWith("https://") || href.startsWith("http://")) {
|
||||
// TODO: Remove this case after converting all these links to relative links.
|
||||
// HTTP URL pointing to NS docs.
|
||||
// Convert https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.foo.md to nsDoc/bitburner.foo.md
|
||||
if (href.startsWith(prefixOfHttpUrlOfNsDocs)) {
|
||||
path = asFilePath(`nsDoc/${href.replace(prefixOfHttpUrlOfNsDocs, "")}`);
|
||||
} else {
|
||||
// HTTP URL pointing to other places.
|
||||
return { path: href, forceOpenExternally: true };
|
||||
}
|
||||
// There are 2 types of HTTP URLs:
|
||||
// - URL pointing to NS docs (e.g., https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.foo.md)
|
||||
// - URL pointing to other places (e.g., https://github.com/bitburner-official/bitburner-src, MDN, other websites)
|
||||
// Most URLs pointing to NS docs were converted to relative links. There are rare/historical usages of links
|
||||
// pointing to our own docs that still use this format, and we're OK with them being external links.
|
||||
return { path: href, forceOpenExternally: true };
|
||||
} else {
|
||||
// Internal non-NS docs
|
||||
path = resolveFilePath("./" + href, currentPage);
|
||||
|
||||
Reference in New Issue
Block a user