From b7237cc2dc818125643d186975aca13bffa44663 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Tue, 24 Jan 2023 02:11:38 +0400 Subject: [PATCH] Toipc pages rendering --- .../content/minimize-iframes.md | 1 + src/lib/best-practice-topic.ts | 10 ++--- .../[bestPracticeId]/[...topicId].astro | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/best-practices/frontend-performance/content/minimize-iframes.md create mode 100644 src/pages/best-practices/[bestPracticeId]/[...topicId].astro diff --git a/src/best-practices/frontend-performance/content/minimize-iframes.md b/src/best-practices/frontend-performance/content/minimize-iframes.md new file mode 100644 index 000000000..9a3ffca75 --- /dev/null +++ b/src/best-practices/frontend-performance/content/minimize-iframes.md @@ -0,0 +1 @@ +# Sup \ No newline at end of file diff --git a/src/lib/best-practice-topic.ts b/src/lib/best-practice-topic.ts index 208e8c17d..13cced97e 100644 --- a/src/lib/best-practice-topic.ts +++ b/src/lib/best-practice-topic.ts @@ -15,7 +15,7 @@ function generateTopicUrl(filePath: string) { .replace(/\.md$/, ''); // Remove `.md` from the end of file } -interface TopicFileType { +export interface BestPracticeTopicFileType { url: string; heading: string; file: MarkdownFileType; @@ -27,12 +27,12 @@ interface TopicFileType { * Gets all the topic files available for all the best practices * @returns Hashmap containing the topic slug and the topic file content */ -async function getTopicFiles(): Promise> { +export async function getAllBestPracticeTopicFiles(): Promise> { const contentFiles = await import.meta.glob('/src/best-practices/*/content/**/*.md', { eager: true, }); - const mapping: Record = {}; + const mapping: Record = {}; for (let filePath of Object.keys(contentFiles)) { const fileContent: MarkdownFileType = contentFiles[filePath] as any; @@ -63,8 +63,8 @@ async function getTopicFiles(): Promise> { * * @returns Promise */ -export async function getTopicsByBestPracticeId(bestPracticeId: string): Promise { - const topicFileMapping = await getTopicFiles(); +export async function getTopicsByBestPracticeId(bestPracticeId: string): Promise { + const topicFileMapping = await getAllBestPracticeTopicFiles(); const allTopics = Object.values(topicFileMapping); return allTopics.filter((topic) => topic.bestPracticeId === bestPracticeId); diff --git a/src/pages/best-practices/[bestPracticeId]/[...topicId].astro b/src/pages/best-practices/[bestPracticeId]/[...topicId].astro new file mode 100644 index 000000000..a06c049f1 --- /dev/null +++ b/src/pages/best-practices/[bestPracticeId]/[...topicId].astro @@ -0,0 +1,40 @@ +--- +import BaseLayout from '../../../layouts/BaseLayout.astro'; +import { BestPracticeTopicFileType, getAllBestPracticeTopicFiles } from '../../../lib/best-practice-topic'; + +export async function getStaticPaths() { + const topicPathMapping = await getAllBestPracticeTopicFiles(); + + return Object.keys(topicPathMapping).map((topicSlug) => { + const topicDetails = topicPathMapping[topicSlug]; + const bestPracticeId = topicDetails.bestPracticeId; + const topicId = topicSlug.replace(`/${bestPracticeId}/`, ''); + + return { + params: { + topicId, + bestPracticeId, + }, + props: topicDetails, + }; + }); +} + +const { topicId } = Astro.params; +const { file, bestPracticeId, bestPractice, heading } = Astro.props as BestPracticeTopicFileType; +--- + + +
+
+
+ +
+
+
+