Skip to content

Commit

Permalink
feat: add index.d.ts (namespace Docs)
Browse files Browse the repository at this point in the history
  • Loading branch information
crookse committed Jul 4, 2023
1 parent 6888692 commit 5d55149
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
16 changes: 16 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
declare namespace Docs {
namespace V2 {
type SidebarCategory = {
is_directory: boolean;
label: string;
path: string;
paths: SidebarCategory[];
};

type State = {
darkMode: string;
mobileViewport: boolean,
toggleDarkMode: () => void,
}
}
}
16 changes: 10 additions & 6 deletions pages/[...path_params].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Props = {
moduleVersions: string[];
pageModifiedTime: string;
redirectUri: string;
sideBarCategories: any;
sideBarCategories: Docs.V2.SidebarCategory[];
topBarModuleName: string;
};

Expand Down Expand Up @@ -189,9 +189,9 @@ export function getStaticProps({ params }) {
ret.props.markdown = fs.readFileSync(markdownFile, "utf-8");
} catch (error) {
if (
(env('app_env', 'production') !== 'production')
|| (env('app_process', null) !== 'build')
) {
(env("app_env", "production") !== "production") ||
(env("app_process", null) !== "build")
) {
console.log(`\nMarkdown Error\n`, error);
}
}
Expand Down Expand Up @@ -274,8 +274,12 @@ function getDirectoryTree(path, paths = []) {
return paths;
}

function getSideBarCategories(moduleName, version) {
function getSideBarCategories(
moduleName: string,
version: string,
): Docs.V2.SidebarCategory {
const tree = getDirectoryTree("docs");

const moduleVersions = tree[0].paths.filter((path) => {
return path.label.toLowerCase() == moduleName;
})[0];
Expand All @@ -287,7 +291,7 @@ function getSideBarCategories(moduleName, version) {
return moduleVersion.paths;
}

function getCategoryLabel(title) {
function getCategoryLabel(title): string {
const label = titleCase(title).replace(/-/g, " ");
return formatLabel(label);
}
2 changes: 1 addition & 1 deletion src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default function Layout(props) {
value,
);

// @ts-ignore
// @ts-ignore Don't really care about Prism typing
Prism.highlightAll();
setDarkMode(value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ const VersionsSelector = styled.select`

type Props = {
mobileViewport: boolean;
categories: any[];
categories: Docs.V2.SidebarCategory[];
isOpen: boolean;
moduleName: string;
moduleVersion: string;
moduleVersions: string[];
state: any;
state: Docs.V2.State;
};

export default function SideBar(props: Props) {
Expand Down
21 changes: 7 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"@/pages/*": [
"./pages/*"
],
"@/styles/*": [
"./styles/*"
],
"@/src/*": [
"./src/*"
],
"@/public/*": [
"./public/*"
]
"@/pages/*": ["./pages/*"],
"@/styles/*": ["./styles/*"],
"@/src/*": ["./src/*"],
"@/public/*": ["./public/*"]
},
"plugins": [
{
Expand All @@ -40,9 +32,10 @@
]
},
"include": [
"index.d.ts",
"next-env.d.ts",
"./src/**/*.ts",
"./pages/**/*.tsx",
"./src/**/*",
"./pages/**/*",
".next/types/**/*.ts"
],
"exclude": [
Expand Down

0 comments on commit 5d55149

Please sign in to comment.