HiDeoo / starlight-blog

Starlight plugin to add a blog to your documentation
https://starlight-blog-docs.vercel.app
MIT License
159 stars 21 forks source link

Conflict with starlight-utils plugin #95

Open gdisk opened 13 hours ago

gdisk commented 13 hours ago

Describe the bug

hello,i want to use this plugin with starlight-utils plugin at the same time, but when i use them together, it seems can not work correctly。codes like below:

// astro.config.mjs
import starlightUtils from "@lorenzo_lewis/starlight-utils";
import starlightBlog from 'starlight-blog'

const starlightBlogPlugin = starlightBlog({
  title: "My Blog",
  prefix: "blogs",
  postCount: 10, 
  recentPostCount: 10, 
  authors: {
    authors1: {
      name: "authors1"
    },
    authors2: {
      name: "authors2",
    },
  }
});

const starlightUtilsPlugin = starlightUtils({
  multiSidebar: {
    switcherStyle: "dropdown",
  }
});

export default defineConfig({
  ...
  integrations: [
      starlight({
        ...
        plugins: [
          starlightImageZoom(),
          starlightUtilsPlugin,
          starlightBlogPlugin,
        ],
     })
  ]

bug details:

  1. when plugins config use starlightBlogPlugin before starlightUtilsPlugin , multiSidebar can not work, all sidebas while show;
  2. when plugins config use starlightUtilsPlugin before starlightBlogPlugin , and visit /blogs, the sidebar is the first item in configured sidebar, and not the sidebar generated by starlightBlogPlugin.

can you help me? so thanks!

To Reproduce

  1. open the page

Expected behavior

both docs sidebar and blogs sidebar works well.

How often does this bug happen?

Every time

System Info

No response

Additional Context

No response

HiDeoo commented 13 hours ago

Thanks for the report :raised_hands:

Component overrides composition in plugins is a bit tricky right now and in this specific case pretty difficult to fix. There is ongoing work in Starlight to refactor the locator the location of route data (from props to a middleware) which will make it easier for plugins to change route data without having to override some component.

When this refactor is done and released in Starlight itself, most of the work currently being done in the blog Sidebar component override will no longer be necessary which will make it easier to compose plugins. I'm actively following this work and will update this plugin as soon as the refactor is released.

gdisk commented 1 hour ago

thanks for reply!

anywhere, i resolved the problem by custom the sidebar in startlight, here is the code:

// astro.config.mjs
import starlightBlog from 'starlight-blog'
import starlightImageZoom from 'starlight-image-zoom';
import starlightUtils from "@lorenzo_lewis/starlight-utils";

export const BLOG_PREFIX = "blogs";

export default defineConfig({
  ...
  integrations: [
    starlight({
      title: "iDOC",
      logo: {
        src: "./src/assets/logo.svg",
      },
      plugins: [
        starlightImageZoom(),
        starlightUtils({
            multiSidebar: {
         switcherStyle: "dropdown",
            },
        }),
        starlightBlog({
        title: "My Blog",
            prefix: BLOG_PREFIX,
    }),
      ],
      components: {
        Sidebar: "./src/components/Sidebar.astro",
      },
      ...
    }),
    ...
  ],
});
// Sidebar.astro
---
import type { Props } from "@astrojs/starlight/props";
import BlogSidebar from "starlight-blog/overrides/Sidebar.astro";
import MultiSidebar from "@lorenzo_lewis/starlight-utils/components/Sidebar.astro";
import { BLOG_PREFIX } from "astro.config.mjs";
const { slug } = Astro.props;
const isBlog = slug.startsWith(BLOG_PREFIX);
---

{
    isBlog && (
        <BlogSidebar {...Astro.props}>
            <slot />
        </BlogSidebar>
    )
}
{
    !isBlog && (
        <MultiSidebar {...Astro.props}>
            <slot />
        </MultiSidebar>
    )
}