Skip to content

Commit c63a9ce

Browse files
committed
fix: create custom normalizePath function
1 parent c30704f commit c63a9ce

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

apps/website/src/utils/docs.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ interface GetDocument {
3030
document: string;
3131
}
3232

33+
const normalizePath = (path: string): string => {
34+
return path.replace(/\\/g, "/");
35+
};
36+
3337
const allDocs = allDocsArray.filter(
3438
(doc, index, self) =>
3539
index ===
@@ -39,9 +43,9 @@ const allDocs = allDocsArray.filter(
3943
);
4044

4145
const getDocument = ({ folder, document }: GetDocument): Doc | undefined => {
42-
const normalizedDocument = document.replace(/\\/g, "/");
46+
const normalizedDocument = normalizePath(document);
4347
const doc = allDocs.find((doc) => {
44-
const normalizedPath = doc._meta.path.replace(/\\/g, "/");
48+
const normalizedPath = normalizePath(doc._meta.path);
4549
return doc.folder === folder && normalizedPath === normalizedDocument;
4650
});
4751
if (!doc) {
@@ -76,4 +80,10 @@ const getGeneralDocument = (document: string): Doc | undefined => {
7680
return { ...doc, tableOfContents };
7781
};
7882

79-
export { getDocument, getDocsByFolder, getGeneralDocument };
83+
export {
84+
allDocs,
85+
normalizePath,
86+
getDocument,
87+
getDocsByFolder,
88+
getGeneralDocument,
89+
};

0 commit comments

Comments
 (0)