mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-02 05:47:14 +02:00
fdafa191ac
This refactors getPage so that the same code can be used as part of openDocExternally. This is necessary, since looking things up in AllPages is potentially required to determine which language-version of the external page to link to.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { AllPages } from "./pages";
|
|
import { EventEmitter } from "../utils/EventEmitter";
|
|
|
|
export const resolvePage = (title: string): { pageName: string | null; pageContent: string } => {
|
|
const lang = new Intl.Locale(navigator.language).language;
|
|
const fallbackLang = "en"; // For untranslated languages
|
|
let pageContent = null;
|
|
let pageName = null;
|
|
if (!title.startsWith("nsDoc")) {
|
|
pageName = lang + "/" + title;
|
|
pageContent = AllPages[pageName];
|
|
if (pageContent == null) {
|
|
pageName = fallbackLang + "/" + title;
|
|
pageContent = AllPages[pageName];
|
|
}
|
|
}
|
|
if (pageContent == null) {
|
|
pageName = title;
|
|
pageContent = AllPages[title];
|
|
}
|
|
if (pageContent == null) {
|
|
const errorMessage = `Cannot find ${title} page.`;
|
|
console.error(errorMessage);
|
|
return { pageName: null, pageContent: errorMessage };
|
|
}
|
|
return { pageName, pageContent };
|
|
};
|
|
|
|
export const getPage = (title: string): string => {
|
|
return resolvePage(title).pageContent;
|
|
};
|
|
|
|
export const DocumentationPopUpEvents = new EventEmitter<[string | undefined]>();
|
|
|
|
export function openDocumentationPopUp(path: string): void {
|
|
DocumentationPopUpEvents.emit(path);
|
|
}
|