+
@@ -95,10 +96,12 @@ function ErrorComponent({ versionsList }: Props) {
);
}
-export default ErrorComponent;
+export default Error;
-export async function getServerSideProps() {
+export async function getStaticProps(context: GetServerSidePropsContext) {
try {
+ const version = context.params.version as string;
+
const versionsList: Array> = getVersionsList();
return {
@@ -109,4 +112,4 @@ export async function getServerSideProps() {
notFound: true,
};
}
-}
+}
\ No newline at end of file
diff --git a/public/_redirects b/public/_redirects
new file mode 100644
index 000000000..7690a0a0a
--- /dev/null
+++ b/public/_redirects
@@ -0,0 +1,3 @@
+/v1.1.x/ /v1.1.x 200
+/v1.2.x/ /v1.2.x 200
+/v1.3.x/ /v1.3.x 200
\ No newline at end of file
diff --git a/public/globals.css b/public/globals.css
index dcb57a066..d2dda3bcc 100644
--- a/public/globals.css
+++ b/public/globals.css
@@ -85,8 +85,6 @@ p {
h1 {
font-size: 32px;
- padding-bottom: 16px;
- border-bottom: 1px solid var(--default-border-color);
line-height: 38px;
}
diff --git a/tsconfig.json b/tsconfig.json
index abcd0b03c..eeee15473 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,6 +16,6 @@
"jsx": "preserve",
"typeRoots": ["./types"]
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "app.config.js"],
"exclude": ["node_modules"]
}
diff --git a/types/index.d.ts b/types/index.d.ts
index 54d7f11c6..60a9777e6 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1,7 +1,33 @@
-export {};
+import { ResultData } from "../components/Search/ResultItem/ResultItem.interface";
+
+interface PageFindOptions {
+ element?: string;
+ bundlePath?: string;
+ baseUrl?: string;
+ bundlePath?: string;
+ excerptLength?: number;
+ highlightParam?: string;
+ indexWeight?: number;
+ debounceTimeoutMs?: number;
+ mergeFilter?: { resource?: string };
+ showImages?: boolean;
+}
declare global {
interface Window {
initial: any;
+ pageFind: Record<
+ string,
+ {
+ options?: (PageFindOptions) => Promise;
+ preload: (text: string) => void;
+ search?: (text: string) => Promise<{
+ results: {
+ id: string;
+ data: () => Promise;
+ }[];
+ }>;
+ }
+ >;
}
}
diff --git a/utils/CommonUtils.ts b/utils/CommonUtils.ts
index 8012cbfc9..4166f3d41 100644
--- a/utils/CommonUtils.ts
+++ b/utils/CommonUtils.ts
@@ -1,7 +1,8 @@
-import Markdoc from "@markdoc/markdoc";
+import Markdoc, { Node } from "@markdoc/markdoc";
import { isEmpty, startCase } from "lodash";
import * as icons from "react-icons/md";
import { HeadingObject } from "../components/PageLayouts/APIPageLayout/APIPageSideNav/APIPageSideNav";
+import { SelectOption } from "../components/SelectDropdown/SelectDropdown";
import { DEFAULT_VERSION } from "../constants/version.constants";
import { MenuItem, UrlParams } from "../interface/common.interface";
@@ -59,6 +60,24 @@ export const fetchMenuList = async (version?: string) => {
}
};
+export const fetchVersionsList = async () => {
+ try {
+ const response = await fetch(`/api/getVersionsList`, {
+ method: "GET",
+ });
+
+ const parsedResponse: Array> = await response.json();
+
+ if (response.status === 200) {
+ return parsedResponse;
+ } else {
+ return [];
+ }
+ } catch (error) {
+ return [];
+ }
+};
+
export const materialDesignIcon = (icon: string) => {
// Checking whether the icon name passed has prefix 'Md' applied already
// i.e. 'MdCircle' for 'circle' icon
@@ -80,7 +99,7 @@ export const getFormattedPartials = (
if (isEmpty(partialsObject)) {
return {};
}
- const formattedPartialsObj = {};
+ const formattedPartialsObj: Record = {};
Object.entries(partialsObject).forEach(([key, value]) => {
formattedPartialsObj[key] = Markdoc.parse(value);
diff --git a/utils/SlugUtils.ts b/utils/SlugUtils.ts
index e5463b8cc..06a101792 100644
--- a/utils/SlugUtils.ts
+++ b/utils/SlugUtils.ts
@@ -105,34 +105,6 @@ export const getReturnObjectForValidVersion = ({
}
}
- // If the file is not found in the content folder
- if (notFound) {
- // Check if the version is present in the existing versions list
- const isVersionPresent = versionsList.some(
- (versionOption) => versionOption.value === version
- );
-
- // If the version is present in versions list, return 404
- if (isVersionPresent) {
- return { notFound };
- }
-
- // If the version is not present in versions list,
- // check if the major version is present.
- // Ex. If v1.4.8 is in the URL and v1.4.8 is not in versions list but v1.4.x is so match the 1.4
- // and redirect to the respective version URL in this case to v1.4.x
- const majorVersionMatch = getMajorVersionMatch(versionsList, version);
-
- return {
- redirect: {
- permanent: false,
- destination: `/${
- majorVersionMatch?.value ?? "latest" // If major version match is not present, redirect to latest
- }/${pathWithoutVersion}`,
- },
- };
- }
-
// Get the last element of the array to find the MD file
const fileContents = fs.readFileSync(filename, "utf8");
const { content, data } = matter(fileContents);
@@ -150,8 +122,9 @@ export const getReturnObjectForValidVersion = ({
slug,
versionsList,
partials,
- pageTitle: data.title,
+ pageTitle: data.title ?? "",
pageDescription: data.description ?? "",
+ weight: data.weight ?? "0",
},
};
}