From 9517d8d561a65e417ffd2334a5bae10d9eb1a2ce Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Thu, 28 Sep 2023 15:38:50 +0100 Subject: [PATCH] Add CheerpJ version switcher (#18) --- astro.config.mjs | 11 ++++++ src/components/BlogPostPill.astro | 2 +- src/components/DocsSidebar.astro | 9 ++--- src/components/LatestBlogPostPill.astro | 8 ++++ src/components/ProductVersionSwitcher.astro | 39 +++++++++++++++++++ src/content/docs/cheerp/index.mdx | 5 ++- .../docs/cheerpj2/{index.md => index.mdx} | 36 ++++++++++------- src/content/docs/cheerpj3/index.mdx | 7 +++- .../docs/cheerpx/{index.md => index.mdx} | 21 ++++++---- src/lib/products.ts | 4 +- 10 files changed, 110 insertions(+), 32 deletions(-) create mode 100644 src/components/LatestBlogPostPill.astro create mode 100644 src/components/ProductVersionSwitcher.astro rename src/content/docs/cheerpj2/{index.md => index.mdx} (83%) rename src/content/docs/cheerpx/{index.md => index.mdx} (70%) diff --git a/astro.config.mjs b/astro.config.mjs index 6b37e72a..0a00a0c5 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,6 +8,7 @@ import svelte from "@astrojs/svelte"; import prefetch from "@astrojs/prefetch"; import astroExpressiveCode from "astro-expressive-code"; import remarkObsidianCallout from "remark-obsidian-callout"; +import { resolve } from "node:path"; const prod = process.env.NODE_ENV === "production"; // https://astro.build/config @@ -45,4 +46,14 @@ export default defineConfig({ inlineStylesheets: "always", }, trailingSlash: "never", + vite: { + resolve: { + alias: [ + { + find: "@", + replacement: resolve("./src/"), + }, + ], + }, + }, }); diff --git a/src/components/BlogPostPill.astro b/src/components/BlogPostPill.astro index 79e8f825..3126fedc 100644 --- a/src/components/BlogPostPill.astro +++ b/src/components/BlogPostPill.astro @@ -11,7 +11,7 @@ const { post } = Astro.props;
{post.data.shortTitle ?? post.data.title} diff --git a/src/components/DocsSidebar.astro b/src/components/DocsSidebar.astro index 25c83809..3094aac0 100644 --- a/src/components/DocsSidebar.astro +++ b/src/components/DocsSidebar.astro @@ -3,10 +3,9 @@ import type { NavDirectory } from "../lib/nav"; import { Icon } from "astro-icon"; import DocsSidebarNavEntry from "./DocsSidebarNavEntry.astro"; -import BlogPostPill from "./BlogPostPill.astro"; -import { latestFeaturedPost } from "../lib/blog"; import { productFromUrl as productFromUrl } from "../lib/products"; import { Image } from "astro:assets"; +import ProductVersionSwitcher from "./ProductVersionSwitcher.astro"; interface Props { directory: NavDirectory | undefined; @@ -37,8 +36,6 @@ const { directory } = Astro.props; }, ];*/ -const post = await latestFeaturedPost(Astro.url); - const product = productFromUrl(Astro.url); if (!product) { throw new Error(`unable to derive product from url: ${Astro.url.pathname}`); @@ -50,10 +47,10 @@ if (!product) { class="bg-stone-800 lg:bg-stone-900 fixed lg:sticky top-[65px] z-10 px-8 pb-8 w-full sm:w-80 h-[calc(100vh-4rem)] overflow-y-auto lg:text-sm" >
- + {product.name} - {post && } + {product.id.startsWith("cheerpj") && }