Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OneUptime Copilot] Improve Comments on /App/FeatureSet/Docs/Index.ts #1553

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions App/FeatureSet/Docs/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const DocsFeatureSet: FeatureSet = {
init: async (): Promise<void> => {
const app: ExpressApplication = Express.getExpressApp();

// Redirect all requests to /docs to /docs/introduction/getting-started
app.get("/docs", (_req: ExpressRequest, res: ExpressResponse) => {
res.redirect("/docs/introduction/getting-started");
});
Expand All @@ -27,18 +28,20 @@ const DocsFeatureSet: FeatureSet = {
const fullPath: string =
`${_req.params["categorypath"]}/${_req.params["pagepath"]}`.toLowerCase();

// read file from Content folder.
// Read file from Content folder
let contentInMarkdown: string = await LocalFile.read(
`${ContentPath}/${fullPath}.md`,
);

// remove first line from content because we dont want to show title in content. Title is already in nav.

// Remove first line from content because we don't want to show title in content
// Title is already shown in the navigation
contentInMarkdown = contentInMarkdown.split("\n").slice(1).join("\n");

// Render the content
const renderedContent: string =
await DocsRender.render(contentInMarkdown);

// Find the current category and link in the navigation
const currentCategory: NavGroup | undefined = DocsNav.find(
(category: NavGroup) => {
return category.links.find((link: NavLink) => {
Expand All @@ -52,34 +55,48 @@ const DocsFeatureSet: FeatureSet = {
return link.url.toLocaleLowerCase().includes(fullPath);
});

if (!currentCategory || !currrentNavLink) {
// render not found.

res.status(404);
return res.render(`${ViewsPath}/NotFound`, {
nav: DocsNav,
});
if (!currentCategory ||!currrentNavLink) {
// Render not found page
}

res.render(`${ViewsPath}/Index`, {
nav: DocsNav,
content: renderedContent,
category: currentCategory,
link: currrentNavLink,
githubPath: fullPath,
});
} catch (err) {
logger.error(err);
res.status(500);
return res.render(`${ViewsPath}/ServerError`, {
nav: DocsNav,
});
} catch (error) {
logger.error(error);
}
},
);

app.use("/docs/static", ExpressStatic(StaticPath));
},
};

export default DocsFeatureSet;
Here is the code with improved comments:

res.status(404);
// Return a 404 error with a custom not found view
return res.render(`${ViewsPath}/NotFound`, {
nav: DocsNav,
});

// Render the index view with navigation, content, category, link, and github path
res.render(`${ViewsPath}/Index`, {
nav: DocsNav,
content: renderedContent,
category: currentCategory,
link: currrentNavLink,
githubPath: fullPath,
});

} catch (err) {
// Log the error
logger.error(err);
// Return a 500 error with a custom server error view
res.status(500);
return res.render(`${ViewsPath}/ServerError`, {
nav: DocsNav,
});
}
},

// Set up a route for serving static files
app.use("/docs/static", ExpressStatic(StaticPath));
},
);

--all-good--
Loading