From 6216c3051e94b46a8e04cd88416be79552ffb8d6 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 2 Jan 2023 20:23:53 +0400 Subject: [PATCH] Add guide detail page --- src/components/GuideHeader.astro | 42 ++++++++++++++++++++++++++++++++ src/lib/guide.ts | 12 +++++---- src/pages/guides.astro | 23 ----------------- src/pages/guides/[guideId].astro | 32 ++++++++++++++++++++++++ src/pages/guides/index.astro | 23 +++++++++++++++++ src/styles/prism.css | 4 +-- 6 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 src/components/GuideHeader.astro delete mode 100644 src/pages/guides.astro create mode 100644 src/pages/guides/[guideId].astro create mode 100644 src/pages/guides/index.astro diff --git a/src/components/GuideHeader.astro b/src/components/GuideHeader.astro new file mode 100644 index 000000000..ac0085350 --- /dev/null +++ b/src/components/GuideHeader.astro @@ -0,0 +1,42 @@ +--- +import type { GuideFileType } from '../lib/guide'; + +export interface Props { + guide: GuideFileType; +} + +const { guide } = Astro.props; +const { frontmatter } = guide; +const { author } = frontmatter; +--- + +
+
+ +

+ {frontmatter.title} +

+ +
+
diff --git a/src/lib/guide.ts b/src/lib/guide.ts index 57cc6a5ac..e5d2f9f67 100644 --- a/src/lib/guide.ts +++ b/src/lib/guide.ts @@ -1,4 +1,4 @@ -import type { MarkdownFileType } from "./file"; +import type { MarkdownFileType } from './file'; export interface GuideFrontmatter { title: string; @@ -13,11 +13,11 @@ export interface GuideFrontmatter { description: string; }; isNew: boolean; - type: "visual" | "textual"; + type: 'visual' | 'textual'; date: string; sitemap: { priority: number; - changefreq: "daily" | "weekly" | "monthly" | "yealry"; + changefreq: 'daily' | 'weekly' | 'monthly' | 'yealry'; }; tags: string[]; } @@ -33,7 +33,9 @@ export type GuideFileType = MarkdownFileType & { * @returns unique guide identifier */ function guidePathToId(filePath: string): string { - return filePath.replace("/src/guides/", "").replace(".md", ""); + const fileName = filePath.split('/').pop() || ''; + + return fileName.replace('.md', ''); } /** @@ -41,7 +43,7 @@ function guidePathToId(filePath: string): string { * @returns Promisifed guide files */ export async function getAllGuides(): Promise { - const guides = await import.meta.glob("/src/guides/*.md", { + const guides = await import.meta.glob('/src/guides/*.md', { eager: true, }); diff --git a/src/pages/guides.astro b/src/pages/guides.astro deleted file mode 100644 index abd3799c1..000000000 --- a/src/pages/guides.astro +++ /dev/null @@ -1,23 +0,0 @@ ---- -import GuideListItem from "../components/GuideListItem.astro"; -import SimplePageHeader from "../components/SimplePageHeader.astro"; -import BaseLayout from "../layouts/BaseLayout.astro"; -import { getAllGuides } from "../lib/guide"; - -const guides = await getAllGuides(); ---- - - - - -
-
-
- {guides.map((guide) => )} -
-
-
-
diff --git a/src/pages/guides/[guideId].astro b/src/pages/guides/[guideId].astro new file mode 100644 index 000000000..be0bb32f2 --- /dev/null +++ b/src/pages/guides/[guideId].astro @@ -0,0 +1,32 @@ +--- +import GuideHeader from '../../components/GuideHeader.astro'; +import BaseLayout from '../../layouts/BaseLayout.astro'; +import { getAllGuides, GuideFileType } from '../../lib/guide'; +import '../../styles/prism.css'; + +export interface Props { + guide: GuideFileType; +} + +export async function getStaticPaths() { + const guides = await getAllGuides(); + + return guides.map((guide) => ({ + params: { guideId: guide.id }, + props: { guide }, + })); +} + +const { guideId } = Astro.params; +const { guide } = Astro.props; +--- + + + + +
+
+ +
+
+
diff --git a/src/pages/guides/index.astro b/src/pages/guides/index.astro new file mode 100644 index 000000000..e0f3961c5 --- /dev/null +++ b/src/pages/guides/index.astro @@ -0,0 +1,23 @@ +--- +import GuideListItem from '../../components/GuideListItem.astro'; +import SimplePageHeader from '../../components/SimplePageHeader.astro'; +import BaseLayout from '../../layouts/BaseLayout.astro'; +import { getAllGuides } from '../../lib/guide'; + +const guides = await getAllGuides(); +--- + + + + +
+
+
+ {guides.map((guide) => )} +
+
+
+
diff --git a/src/styles/prism.css b/src/styles/prism.css index 699c9741b..0cb989e89 100644 --- a/src/styles/prism.css +++ b/src/styles/prism.css @@ -44,8 +44,8 @@ code:not([class]) { padding: 2px 4px; font-family: 'Operator Mono', 'Fira Code', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; font-size: .875rem; - background-color: #FAFAFA; - border: 1px solid #EAEAEA; + /* background-color: #FAFAFA; + border: 1px solid #EAEAEA; */ border-radius: 4px; }