starlight-sidebar-topics-dropdown 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/components/Topics.astro +4 -4
- package/components/starlight/Sidebar.astro +28 -0
- package/index.ts +11 -11
- package/{lib → libs}/content.ts +2 -2
- package/libs/locals.ts +14 -0
- package/{lib → libs}/plugin.ts +1 -1
- package/{lib → libs}/sidebar.ts +2 -2
- package/libs/starlight.ts +29 -0
- package/middleware.ts +43 -0
- package/overrides/Sidebar.astro +3 -36
- package/package.json +5 -4
- package/schema.ts +1 -1
- package/overrides/Pagination.astro +0 -19
- /package/{lib → libs}/config.ts +0 -0
- /package/{lib → libs}/i18n.ts +0 -0
- /package/{lib → libs}/pathname.ts +0 -0
- /package/{lib → libs}/vite.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# starlight-sidebar-topics-dropdown
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`3193771`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/31937716171b020f414ece6783c17181fbd5fdcf) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The Starlight Sidebar Topics Dropdown plugin no longer provides the same ["Unnested Sidebar" configuration](https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unnested-sidebar/) like before. Please adapt your `astro.config.mjs` with the up-to-date guide on [how to configure a "Unnested Sidebar"](https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unnested-sidebar/#configure-an-unnested-sidebar).
|
|
8
|
+
|
|
9
|
+
- [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`db10526`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/db10526d49aab3ac8619159d40968dbc4748c9a0) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now version `0.32.0`.
|
|
10
|
+
|
|
11
|
+
Please use the `@astrojs/upgrade` command to upgrade your project:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx @astrojs/upgrade
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- [#31](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/pull/31) [`db10526`](https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/commit/db10526d49aab3ac8619159d40968dbc4748c9a0) Thanks [@trueberryless](https://github.com/trueberryless)! - ⚠️ **BREAKING CHANGE:** The Starlight Sidebar Topics Dropdown plugin no longer [overrides](https://starlight.astro.build/guides/overriding-components/) the [`<Pagination>` component](https://starlight.astro.build/reference/overrides/#pagination). If you were manually rendering `starlight-sidebar-topics-dropdown/overrides/Pagination.astro` in a custom override, you can now remove it.
|
|
18
|
+
|
|
3
19
|
## 0.3.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/components/Topics.astro
CHANGED
|
@@ -6,7 +6,7 @@ import { getRelativeLocaleUrl } from 'astro:i18n'
|
|
|
6
6
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
7
7
|
import config from 'virtual:starlight-sidebar-topics-dropdown/config'
|
|
8
8
|
|
|
9
|
-
import type { StarlightSidebarTopicsDropdownSharedConfig } from '../
|
|
9
|
+
import type { StarlightSidebarTopicsDropdownSharedConfig } from '../libs/config'
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
current: StarlightSidebarTopicsDropdownSharedConfig[number]
|
|
@@ -98,9 +98,9 @@ function getTranslation(translations: Record<string, string>, link: string, desc
|
|
|
98
98
|
.starlight-sidebar-topics-dropdown-dropdown {
|
|
99
99
|
position: relative;
|
|
100
100
|
display: block;
|
|
101
|
-
width: calc(100% -
|
|
102
|
-
margin-
|
|
103
|
-
|
|
101
|
+
width: calc(100% - 2 * 2px);
|
|
102
|
+
margin-inline: 2px;
|
|
103
|
+
margin-top: 4px;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
.starlight-sidebar-topics-dropdown-button {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { StarlightSidebarTopicsDropdownLocalsSymbol, type StarlightSidebarTopicsDropdownLocals } from '../../libs/locals'
|
|
3
|
+
import Topics from '../Topics.astro'
|
|
4
|
+
const { entry } = Astro.locals.starlightRoute
|
|
5
|
+
// @ts-expect-error - See `libs/locals` for more information.
|
|
6
|
+
const currentTopic = Astro.locals[StarlightSidebarTopicsDropdownLocalsSymbol] as StarlightSidebarTopicsDropdownLocals
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
{entry['data'].template !== 'splash' && currentTopic && <Topics current={currentTopic.config} />}
|
|
10
|
+
|
|
11
|
+
<style is:global>
|
|
12
|
+
sl-sidebar-state-persist ul.top-level > li:not(:has(details)) {
|
|
13
|
+
margin-top: 0rem;
|
|
14
|
+
}
|
|
15
|
+
sl-sidebar-state-persist ul.top-level > li:has(details) {
|
|
16
|
+
margin-block: 0.5rem;
|
|
17
|
+
}
|
|
18
|
+
/* sl-sidebar-state-persist ul.top-level > li > a {
|
|
19
|
+
font-size: var(--sl-text-sm);
|
|
20
|
+
} */
|
|
21
|
+
sl-sidebar-state-persist ul.top-level > li > a[aria-current='page'] {
|
|
22
|
+
font-weight: 600;
|
|
23
|
+
}
|
|
24
|
+
sl-sidebar-state-persist ul.top-level > li > a[aria-current='false'] {
|
|
25
|
+
font-weight: 400;
|
|
26
|
+
color: var(--sl-color-gray-2);
|
|
27
|
+
}
|
|
28
|
+
</style>
|
package/index.ts
CHANGED
|
@@ -6,14 +6,14 @@ import type {
|
|
|
6
6
|
import {
|
|
7
7
|
StarlightSidebarTopicsDropdownConfigSchema,
|
|
8
8
|
type StarlightSidebarTopicsDropdownUserConfig,
|
|
9
|
-
} from "./
|
|
10
|
-
import { overrideStarlightComponent, throwPluginError } from "./
|
|
11
|
-
import { vitePluginStarlightSidebarTopicsDropdown } from "./
|
|
9
|
+
} from "./libs/config";
|
|
10
|
+
import { overrideStarlightComponent, throwPluginError } from "./libs/plugin";
|
|
11
|
+
import { vitePluginStarlightSidebarTopicsDropdown } from "./libs/vite";
|
|
12
12
|
|
|
13
13
|
export type {
|
|
14
14
|
StarlightSidebarTopicsDropdownConfig,
|
|
15
15
|
StarlightSidebarTopicsDropdownUserConfig,
|
|
16
|
-
} from "./
|
|
16
|
+
} from "./libs/config";
|
|
17
17
|
|
|
18
18
|
export default function starlightSidebarTopicsDropdownPlugin(
|
|
19
19
|
userConfig: StarlightSidebarTopicsDropdownUserConfig
|
|
@@ -34,8 +34,9 @@ export default function starlightSidebarTopicsDropdownPlugin(
|
|
|
34
34
|
return {
|
|
35
35
|
name: "starlight-sidebar-topics-dropdown-plugin",
|
|
36
36
|
hooks: {
|
|
37
|
-
setup({
|
|
37
|
+
"config:setup"({
|
|
38
38
|
addIntegration,
|
|
39
|
+
addRouteMiddleware,
|
|
39
40
|
command,
|
|
40
41
|
config: starlightConfig,
|
|
41
42
|
logger,
|
|
@@ -46,10 +47,14 @@ export default function starlightSidebarTopicsDropdownPlugin(
|
|
|
46
47
|
if (starlightConfig.sidebar) {
|
|
47
48
|
throwPluginError(
|
|
48
49
|
"It looks like you have a `sidebar` configured in your Starlight configuration. To use `starlight-sidebar-topics-dropdown`, create a new topic with your sidebar items.",
|
|
49
|
-
"Learn more about topic configuration at https://starlight-sidebar-topics-dropdown.
|
|
50
|
+
"Learn more about topic configuration at https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/configuration/"
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
addRouteMiddleware({
|
|
55
|
+
entrypoint: "starlight-sidebar-topics-dropdown/middleware",
|
|
56
|
+
});
|
|
57
|
+
|
|
53
58
|
const sidebar: StarlightUserConfig["sidebar"] = [];
|
|
54
59
|
|
|
55
60
|
for (const [index, topic] of config.entries()) {
|
|
@@ -65,11 +70,6 @@ export default function starlightSidebarTopicsDropdownPlugin(
|
|
|
65
70
|
logger,
|
|
66
71
|
"Sidebar"
|
|
67
72
|
),
|
|
68
|
-
...overrideStarlightComponent(
|
|
69
|
-
starlightConfig.components,
|
|
70
|
-
logger,
|
|
71
|
-
"Pagination"
|
|
72
|
-
),
|
|
73
73
|
},
|
|
74
74
|
sidebar,
|
|
75
75
|
});
|
package/{lib → libs}/content.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StarlightRouteData } from "@astrojs/starlight/route-data";
|
|
2
2
|
import type { TopicFrontmatterSchema } from "../schema";
|
|
3
3
|
export function isStarlightEntryWithTopic(
|
|
4
4
|
entry: StarlightEntry
|
|
@@ -9,7 +9,7 @@ export function isStarlightEntryWithTopic(
|
|
|
9
9
|
typeof (entry as StarlightEntryWithTopic).data.topic === "string"
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
|
-
export type StarlightEntry =
|
|
12
|
+
export type StarlightEntry = StarlightRouteData["entry"];
|
|
13
13
|
export type StarlightEntryWithTopic = StarlightEntry & {
|
|
14
14
|
data: TopicFrontmatterSchema;
|
|
15
15
|
};
|
package/libs/locals.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StarlightSidebarTopicsDropdownSharedConfig } from "./config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* We keep track of the current topic configuration using a variable stored using `Astro.locals` which will be reset for
|
|
5
|
+
* each new page. The value is tracked using an untyped symbol on purpose to avoid users to get autocomplete for it and
|
|
6
|
+
* avoid potential clashes with user-defined variables.
|
|
7
|
+
*/
|
|
8
|
+
export const StarlightSidebarTopicsDropdownLocalsSymbol = Symbol.for(
|
|
9
|
+
"starlight-sidebar-topics-dropdown:locals"
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export interface StarlightSidebarTopicsDropdownLocals {
|
|
13
|
+
config: StarlightSidebarTopicsDropdownSharedConfig[number];
|
|
14
|
+
}
|
package/{lib → libs}/plugin.ts
RENAMED
|
@@ -6,7 +6,7 @@ export function throwPluginError(message: string, hint?: string): never {
|
|
|
6
6
|
throw new AstroError(
|
|
7
7
|
message,
|
|
8
8
|
hint ??
|
|
9
|
-
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/
|
|
9
|
+
`See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/trueberryless-org/starlight-sidebar-topics-dropdown/issues/new/choose`
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
|
package/{lib → libs}/sidebar.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StarlightRouteData } from "@astrojs/starlight/route-data";
|
|
2
2
|
|
|
3
3
|
import type { StarlightSidebarTopicsDropdownSharedConfig } from "./config";
|
|
4
4
|
import { isStarlightEntryWithTopic, type StarlightEntry } from "./content";
|
|
@@ -196,7 +196,7 @@ function getTopicIdFromEntry(entry: StarlightEntry): string | undefined {
|
|
|
196
196
|
return isStarlightEntryWithTopic(entry) ? entry.data.topic : undefined;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
type SidebarEntry =
|
|
199
|
+
type SidebarEntry = StarlightRouteData["sidebar"][number];
|
|
200
200
|
|
|
201
201
|
interface SidebarTopic {
|
|
202
202
|
label: string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StarlightUserConfig } from "@astrojs/starlight/types";
|
|
2
|
+
import type { AstroIntegrationLogger } from "astro";
|
|
3
|
+
|
|
4
|
+
export function overrideStarlightComponent(
|
|
5
|
+
components: StarlightUserConfig["components"],
|
|
6
|
+
logger: AstroIntegrationLogger,
|
|
7
|
+
override: keyof NonNullable<StarlightUserConfig["components"]>,
|
|
8
|
+
component: string
|
|
9
|
+
) {
|
|
10
|
+
if (components?.[override]) {
|
|
11
|
+
logger.warn(
|
|
12
|
+
`It looks like you already have a \`${override}\` component override in your Starlight configuration.`
|
|
13
|
+
);
|
|
14
|
+
logger.warn(
|
|
15
|
+
`To use \`starlight-sidebar-topics-dropdown\`, either remove your override or update it to render the content from \`starlight-sidebar-topics-dropdown/components/${component}.astro\`.`
|
|
16
|
+
);
|
|
17
|
+
// if (component === "DynamicVersionBadge") {
|
|
18
|
+
// logger.warn(
|
|
19
|
+
// "Notice that the `DynamicVersionBadge` component must be rendered AFTER the original Starlight `SiteTitle` component in the DOM. This ensures proper layout and behavior within the application."
|
|
20
|
+
// );
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
[override]: `starlight-sidebar-topics-dropdown/overrides/${override}.astro`,
|
|
28
|
+
};
|
|
29
|
+
}
|
package/middleware.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defineRouteMiddleware } from "@astrojs/starlight/route-data";
|
|
2
|
+
import config from "virtual:starlight-sidebar-topics-dropdown/config";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
StarlightSidebarTopicsDropdownLocalsSymbol,
|
|
6
|
+
type StarlightSidebarTopicsDropdownLocals,
|
|
7
|
+
} from "./libs/locals";
|
|
8
|
+
import { throwPluginError } from "./libs/plugin";
|
|
9
|
+
import {
|
|
10
|
+
getCurrentTopic,
|
|
11
|
+
isTopicFirstPage,
|
|
12
|
+
isTopicLastPage,
|
|
13
|
+
} from "./libs/sidebar";
|
|
14
|
+
|
|
15
|
+
export const onRequest = defineRouteMiddleware((context) => {
|
|
16
|
+
const { starlightRoute } = context.locals;
|
|
17
|
+
const { entry, id, pagination, sidebar } = starlightRoute;
|
|
18
|
+
|
|
19
|
+
if (entry["data"].template !== "splash") {
|
|
20
|
+
const currentTopic = getCurrentTopic(config, sidebar, id, entry);
|
|
21
|
+
|
|
22
|
+
if (!currentTopic)
|
|
23
|
+
throwPluginError(
|
|
24
|
+
`Failed to find the topic for the \`${id}\` page.`,
|
|
25
|
+
`Either include this page in the sidebar configuration of the desired topic using the \`items\` property or to associate an unlisted page with a topic, use the \`topic\` frontmatter property and set it to the desired topic ID.
|
|
26
|
+
Learn more about unlisted pages in the ["Unlisted pages"](https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unlisted-pages/) guide.`
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
starlightRoute.sidebar = currentTopic.sidebar;
|
|
30
|
+
// @ts-expect-error - See `libs/locals` for more information.
|
|
31
|
+
context.locals[StarlightSidebarTopicsDropdownLocalsSymbol] = {
|
|
32
|
+
config: currentTopic.config,
|
|
33
|
+
} satisfies StarlightSidebarTopicsDropdownLocals;
|
|
34
|
+
|
|
35
|
+
if (isTopicFirstPage(sidebar, id)) {
|
|
36
|
+
pagination.prev = undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isTopicLastPage(sidebar, id)) {
|
|
40
|
+
pagination.next = undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
package/overrides/Sidebar.astro
CHANGED
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import Default from '@astrojs/starlight/components/Sidebar.astro'
|
|
3
|
-
import
|
|
4
|
-
import config from 'virtual:starlight-sidebar-topics-dropdown/config'
|
|
5
|
-
|
|
6
|
-
import Topics from '../components/Topics.astro'
|
|
7
|
-
import { throwPluginError } from '../lib/plugin'
|
|
8
|
-
import { getCurrentTopic, type Topic } from '../lib/sidebar'
|
|
9
|
-
|
|
10
|
-
const { id, entry, sidebar } = Astro.props
|
|
11
|
-
|
|
12
|
-
let currentSidebar = sidebar
|
|
13
|
-
let currentTopic: Topic | undefined = undefined
|
|
14
|
-
|
|
15
|
-
if (entry['data'].template !== 'splash') {
|
|
16
|
-
currentTopic = getCurrentTopic(config, sidebar, id, entry)
|
|
17
|
-
if (!currentTopic)
|
|
18
|
-
throwPluginError(
|
|
19
|
-
`Failed to find the topic for the \`${id}\` page.`,
|
|
20
|
-
`Either include this page in the sidebar configuration of the desired topic using the \`items\` property or to associate an unlisted page with a topic, use the \`topic\` frontmatter property and set it to the desired topic ID.
|
|
21
|
-
Learn more about unlisted pages in the ["Unlisted pages"](https://starlight-sidebar-topics.netlify.app/docs/guides/unlisted-pages/) guide.`,
|
|
22
|
-
)
|
|
23
|
-
currentSidebar = currentTopic.sidebar
|
|
24
|
-
}
|
|
3
|
+
import StarlightSidebarTopicsDropdownSidebar from '../components/starlight/Sidebar.astro'
|
|
25
4
|
---
|
|
26
5
|
|
|
27
|
-
|
|
28
|
-
<Default
|
|
29
|
-
|
|
30
|
-
{!currentTopic?.sidebarHasGroups &&
|
|
31
|
-
<style is:global>
|
|
32
|
-
sl-sidebar-state-persist summary {
|
|
33
|
-
display: none !important;
|
|
34
|
-
}
|
|
35
|
-
sl-sidebar-state-persist ul li {
|
|
36
|
-
margin-inline-start: 0;
|
|
37
|
-
border-inline-start: none;
|
|
38
|
-
}
|
|
39
|
-
</style>
|
|
40
|
-
}
|
|
6
|
+
<StarlightSidebarTopicsDropdownSidebar />
|
|
7
|
+
<Default><slot /></Default>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-sidebar-topics-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Starlight plugin to split your docs page into multiple subpages and switch between them with a dropdown menu in the sidebar.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"starlight",
|
|
@@ -24,14 +24,15 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./index.ts",
|
|
27
|
-
"./
|
|
27
|
+
"./components/Sidebar.astro": "./components/starlight/Sidebar.astro",
|
|
28
|
+
"./middleware": "./middleware.ts",
|
|
28
29
|
"./overrides/Sidebar.astro": "./overrides/Sidebar.astro",
|
|
29
30
|
"./schema": "./schema.ts",
|
|
30
31
|
"./package.json": "./package.json"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
|
-
"@astrojs/starlight": "^0.
|
|
34
|
-
"astro": "^5.
|
|
34
|
+
"@astrojs/starlight": "^0.32.1",
|
|
35
|
+
"astro": "^5.3.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"@astrojs/starlight": ">=0.30"
|
package/schema.ts
CHANGED
|
@@ -3,7 +3,7 @@ export const topicSchema = z.object({
|
|
|
3
3
|
/**
|
|
4
4
|
* ID of the topic to associate with the current page if the page is not listed in any topic sidebar configuration.
|
|
5
5
|
*
|
|
6
|
-
* @see https://starlight-sidebar-topics.
|
|
6
|
+
* @see https://starlight-sidebar-topics-dropdown.trueberryless.org/docs/guides/unlisted-pages/
|
|
7
7
|
*/
|
|
8
8
|
topic: z.string().optional(),
|
|
9
9
|
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Default from '@astrojs/starlight/components/Pagination.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
|
-
|
|
5
|
-
import { isTopicFirstPage, isTopicLastPage } from '../lib/sidebar'
|
|
6
|
-
|
|
7
|
-
const { id, pagination, sidebar } = Astro.props
|
|
8
|
-
let { prev, next } = pagination
|
|
9
|
-
|
|
10
|
-
if (isTopicFirstPage(sidebar, id)) {
|
|
11
|
-
prev = undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (isTopicLastPage(sidebar, id)) {
|
|
15
|
-
next = undefined
|
|
16
|
-
}
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
<Default {...Astro.props} pagination={{ prev, next }}><slot /></Default>
|
/package/{lib → libs}/config.ts
RENAMED
|
File without changes
|
/package/{lib → libs}/i18n.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/{lib → libs}/vite.ts
RENAMED
|
File without changes
|