···22import { z } from "astro/zod";
3344const sidebarTopicBadgeSchema = z.object({
55- text: z.union([z.string(), z.record(z.string())]),
66- variant: z.enum(["note", "danger", "success", "caution", "tip", "default"]).default("default"),
55+ text: z.union([z.string(), z.record(z.string())]),
66+ variant: z
77+ .enum(["note", "danger", "success", "caution", "tip", "default"])
88+ .default("default"),
79});
810911const sidebarTopicBaseSchema = z.object({
1010- /**
1111- * An optional badge to display next to the topic label.
1212- *
1313- * This option accepts the same configuration as the Starlight badge sidebar item configuration.
1414- * @see https://starlight.astro.build/guides/sidebar/#badges
1515- */
1616- badge: z
1717- .union([z.string(), sidebarTopicBadgeSchema])
1818- .transform((badge) =>
1919- typeof badge === "string" ? { variant: "default" as const, text: badge } : badge
2020- )
2121- .optional(),
2222- /**
2323- * The name of an optional icon to display before the topic label set to one of Starlight’s built-in icons.
2424- * @see https://starlight.astro.build/reference/icons/#all-icons
2525- */
2626- icon: z.string().optional(),
2727- /**
2828- * The topic label visible at the top of the sidebar.
2929- *
3030- * The value can be a string, or for multilingual sites, an object with values for each different locale. When using
3131- * the object form, the keys must be BCP-47 tags (e.g. en, fr, or zh-CN).
3232- */
3333- label: z.union([z.string(), z.record(z.string())]),
3434- /**
3535- * The link to the topic’s content which an be a relative link to local files or the full URL of an external page.
3636- *
3737- * For internal links, the link can either be a page included in the items array or a different page acting as the
3838- * topic’s landing page.
3939- */
4040- link: z.string(),
1212+ /**
1313+ * An optional badge to display next to the topic label.
1414+ *
1515+ * This option accepts the same configuration as the Starlight badge sidebar item configuration.
1616+ * @see https://starlight.astro.build/guides/sidebar/#badges
1717+ */
1818+ badge: z
1919+ .union([z.string(), sidebarTopicBadgeSchema])
2020+ .transform((badge) =>
2121+ typeof badge === "string"
2222+ ? { variant: "default" as const, text: badge }
2323+ : badge
2424+ )
2525+ .optional(),
2626+ /**
2727+ * The name of an optional icon to display before the topic label set to one of Starlight’s built-in icons.
2828+ * @see https://starlight.astro.build/reference/icons/#all-icons
2929+ */
3030+ icon: z.string().optional(),
3131+ /**
3232+ * The topic label visible at the top of the sidebar.
3333+ *
3434+ * The value can be a string, or for multilingual sites, an object with values for each different locale. When using
3535+ * the object form, the keys must be BCP-47 tags (e.g. en, fr, or zh-CN).
3636+ */
3737+ label: z.union([z.string(), z.record(z.string())]),
3838+ /**
3939+ * The link to the topic’s content which an be a relative link to local files or the full URL of an external page.
4040+ *
4141+ * For internal links, the link can either be a page included in the items array or a different page acting as the
4242+ * topic’s landing page.
4343+ */
4444+ link: z.string(),
4145});
42464347const sidebarTopicLinkSchema = sidebarTopicBaseSchema;
44484549const sidebarTopicGroupSchema = sidebarTopicBaseSchema.extend({
4646- /**
4747- * An optional unique identifier for the topic that can be used to associate content pages that are not listed in any
4848- * topic sidebar configuration with this topic.
4949- */
5050- id: z.string().optional(),
5151- /**
5252- * The sidebar items (links and subcategories) to display for this topic.
5353- *
5454- * The topic’s sidebar navigation items. This represents the sidebar displayed when the topic `link` page or any of
5555- * the pages configured in the `items` array is the current page.
5656- */
5757- items: z.any().array() as z.Schema<NonNullable<StarlightUserConfig["sidebar"]>>,
5050+ /**
5151+ * An optional unique identifier for the topic that can be used to associate content pages that are not listed in any
5252+ * topic sidebar configuration with this topic.
5353+ */
5454+ id: z.string().optional(),
5555+ /**
5656+ * The sidebar items (links and subcategories) to display for this topic.
5757+ *
5858+ * The topic’s sidebar navigation items. This represents the sidebar displayed when the topic `link` page or any of
5959+ * the pages configured in the `items` array is the current page.
6060+ */
6161+ items: z.any().array() as z.Schema<
6262+ NonNullable<StarlightUserConfig["sidebar"]>
6363+ >,
5864});
59656066export const StarlightSidebarTopicsDropdownConfigSchema = z
6161- .union([sidebarTopicGroupSchema, sidebarTopicLinkSchema])
6262- .array();
6767+ .union([sidebarTopicGroupSchema, sidebarTopicLinkSchema])
6868+ .array();
63696470export type StarlightSidebarTopicsDropdownUserConfig = z.input<
6565- typeof StarlightSidebarTopicsDropdownConfigSchema
7171+ typeof StarlightSidebarTopicsDropdownConfigSchema
6672>;
6773export type StarlightSidebarTopicsDropdownConfig = z.output<
6868- typeof StarlightSidebarTopicsDropdownConfigSchema
7474+ typeof StarlightSidebarTopicsDropdownConfigSchema
6975>;
70767177export type StarlightSidebarTopicsDropdownSharedConfig = (
7272- | (z.output<typeof sidebarTopicLinkSchema> & { type: "link" })
7373- | (Omit<z.output<typeof sidebarTopicGroupSchema>, "items"> & { type: "group" })
7878+ | (z.output<typeof sidebarTopicLinkSchema> & { type: "link" })
7979+ | (Omit<z.output<typeof sidebarTopicGroupSchema>, "items"> & {
8080+ type: "group";
8181+ })
7482)[];
···33import { AstroError } from "astro/errors";
4455export function throwPluginError(message: string, hint?: string): never {
66- throw new AstroError(
77- message,
88- hint ??
99- `See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-sidebar-topics-dropdown/issues/new/choose`
1010- );
66+ throw new AstroError(
77+ message,
88+ hint ??
99+ `See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/starlight-sidebar-topics-dropdown/issues/new/choose`
1010+ );
1111}
12121313export function overrideStarlightComponent(
1414- components: StarlightUserConfig["components"],
1515- logger: AstroIntegrationLogger,
1616- component: keyof NonNullable<StarlightUserConfig["components"]>
1414+ components: StarlightUserConfig["components"],
1515+ logger: AstroIntegrationLogger,
1616+ component: keyof NonNullable<StarlightUserConfig["components"]>
1717) {
1818- if (components?.[component]) {
1919- logger.warn(
2020- `It looks like you already have a \`${component}\` component override in your Starlight configuration.`
2121- );
2222- logger.warn(
2323- `To use \`starlight-sidebar-topics-dropdown\`, either remove your override or update it to render the content from \`starlight-sidebar-topics-dropdown/overrides/${component}.astro\`.`
2424- );
1818+ if (components?.[component]) {
1919+ logger.warn(
2020+ `It looks like you already have a \`${component}\` component override in your Starlight configuration.`
2121+ );
2222+ logger.warn(
2323+ `To use \`starlight-sidebar-topics-dropdown\`, either remove your override or update it to render the content from \`starlight-sidebar-topics-dropdown/overrides/${component}.astro\`.`
2424+ );
25252626- return {};
2727- }
2626+ return {};
2727+ }
28282929- return {
3030- [component]: `starlight-sidebar-topics-dropdown/overrides/${component}.astro`,
3131- };
2929+ return {
3030+ [component]: `starlight-sidebar-topics-dropdown/overrides/${component}.astro`,
3131+ };
3232}
···11import { z } from "astro/zod";
22export const topicSchema = z.object({
33- /**
44- * ID of the topic to associate with the current page if the page is not listed in any topic sidebar configuration.
55- *
66- * @see https://starlight-sidebar-topics.netlify.app/docs/guides/unlisted-pages/
77- */
88- topic: z.string().optional(),
33+ /**
44+ * ID of the topic to associate with the current page if the page is not listed in any topic sidebar configuration.
55+ *
66+ * @see https://starlight-sidebar-topics.netlify.app/docs/guides/unlisted-pages/
77+ */
88+ topic: z.string().optional(),
99});
1010export type TopicFrontmatterSchema = z.input<typeof topicSchema>;