livemark 0.18.0 → 0.20.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/build/actions/config/define.d.ts +12 -0
- package/build/components/Layout.js +6 -4
- package/build/components/Sidebar.js +7 -3
- package/build/components/SidebarArticles.js +3 -2
- package/build/components/SiteLink.d.ts +12 -0
- package/build/components/SiteLink.js +27 -0
- package/build/components/SiteTitle.d.ts +3 -1
- package/build/components/SiteTitle.js +12 -4
- package/build/content/article.d.ts +9 -0
- package/build/helpers/section.d.ts +53 -0
- package/build/helpers/section.js +43 -1
- package/build/helpers/section.unit.js +91 -2
- package/build/models/config.d.ts +36 -0
- package/build/models/section.d.ts +24 -0
- package/build/models/section.js +4 -1
- package/package.json +1 -1
- package/source/components/Layout.tsx +10 -5
- package/source/components/Sidebar.tsx +9 -2
- package/source/components/SidebarArticles.tsx +2 -1
- package/source/components/SiteLink.tsx +46 -0
- package/source/components/SiteTitle.tsx +12 -4
- package/source/helpers/section.ts +42 -0
- package/source/helpers/section.unit.ts +111 -0
- package/source/models/section.ts +3 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { describe, expect, it } from "vite-plus/test"
|
|
2
|
+
import type { Section } from "../models/section.ts"
|
|
2
3
|
import {
|
|
4
|
+
activeSiteLink,
|
|
5
|
+
activeSiteSection,
|
|
3
6
|
customSectionActive,
|
|
4
7
|
matchSection,
|
|
5
8
|
partitionBySection,
|
|
@@ -111,3 +114,111 @@ describe("customSectionActive", () => {
|
|
|
111
114
|
expect(customSectionActive("/about#top", "/about/team/")).toBe(true)
|
|
112
115
|
})
|
|
113
116
|
})
|
|
117
|
+
|
|
118
|
+
describe("activeSiteSection", () => {
|
|
119
|
+
const docs: Section = {
|
|
120
|
+
type: "article",
|
|
121
|
+
title: "Docs",
|
|
122
|
+
prefix: "/",
|
|
123
|
+
position: "header",
|
|
124
|
+
}
|
|
125
|
+
const blog: Section = {
|
|
126
|
+
type: "blog",
|
|
127
|
+
title: "Blog",
|
|
128
|
+
prefix: "/blog/",
|
|
129
|
+
position: "header",
|
|
130
|
+
}
|
|
131
|
+
const apiCustom: Section = {
|
|
132
|
+
type: "custom",
|
|
133
|
+
title: "API",
|
|
134
|
+
url: "/api/v2",
|
|
135
|
+
position: "header",
|
|
136
|
+
}
|
|
137
|
+
const githubCustom: Section = {
|
|
138
|
+
type: "custom",
|
|
139
|
+
title: "GitHub",
|
|
140
|
+
url: "https://github.com/example/repo",
|
|
141
|
+
position: "header",
|
|
142
|
+
}
|
|
143
|
+
const homeCustom: Section = {
|
|
144
|
+
type: "custom",
|
|
145
|
+
title: "Home",
|
|
146
|
+
url: "/",
|
|
147
|
+
position: "header",
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
it("should return the routed section matching by prefix", () => {
|
|
151
|
+
expect(activeSiteSection("/blog/post/", [docs, blog])?.title).toBe("Blog")
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it("should return the custom section matching by internal url", () => {
|
|
155
|
+
expect(activeSiteSection("/api/v2/users/", [docs, apiCustom])?.title).toBe(
|
|
156
|
+
"API",
|
|
157
|
+
)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it("should pick the longest match among overlapping prefixes", () => {
|
|
161
|
+
expect(activeSiteSection("/blog/post/", [docs, blog])?.title).toBe("Blog")
|
|
162
|
+
expect(activeSiteSection("/api/v2/foo/", [docs, apiCustom])?.title).toBe(
|
|
163
|
+
"API",
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it("should ignore custom sections with absolute URLs", () => {
|
|
168
|
+
expect(activeSiteSection("/anything/", [githubCustom])).toBeUndefined()
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it("should match custom URL `/` only on the home page", () => {
|
|
172
|
+
expect(activeSiteSection("/", [homeCustom])?.title).toBe("Home")
|
|
173
|
+
expect(activeSiteSection("/about/", [homeCustom])).toBeUndefined()
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it("should let routed `/` match descendants while custom `/` does not", () => {
|
|
177
|
+
expect(activeSiteSection("/about/", [docs, homeCustom])?.title).toBe("Docs")
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it("should return undefined when no section matches", () => {
|
|
181
|
+
expect(activeSiteSection("/anything/", [blog, apiCustom])).toBeUndefined()
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
describe("activeSiteLink", () => {
|
|
186
|
+
const docs: Section = {
|
|
187
|
+
type: "article",
|
|
188
|
+
title: "Docs",
|
|
189
|
+
prefix: "/",
|
|
190
|
+
position: "header",
|
|
191
|
+
}
|
|
192
|
+
const blog: Section = {
|
|
193
|
+
type: "blog",
|
|
194
|
+
title: "Blog",
|
|
195
|
+
prefix: "/blog/",
|
|
196
|
+
position: "header",
|
|
197
|
+
siteLink: "/blog/",
|
|
198
|
+
}
|
|
199
|
+
const externalCustom: Section = {
|
|
200
|
+
type: "custom",
|
|
201
|
+
title: "GitHub",
|
|
202
|
+
url: "/github",
|
|
203
|
+
position: "header",
|
|
204
|
+
siteLink: "https://github.com/example/repo",
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
it("should default to '/' when no section matches", () => {
|
|
208
|
+
expect(activeSiteLink("/anything/", [blog])).toBe("/")
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
it("should default to '/' when matching section has no siteLink", () => {
|
|
212
|
+
expect(activeSiteLink("/about/", [docs])).toBe("/")
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("should return the matching section's siteLink", () => {
|
|
216
|
+
expect(activeSiteLink("/blog/post/", [blog])).toBe("/blog/")
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it("should support absolute URLs as the siteLink", () => {
|
|
220
|
+
expect(activeSiteLink("/github/", [externalCustom])).toBe(
|
|
221
|
+
"https://github.com/example/repo",
|
|
222
|
+
)
|
|
223
|
+
})
|
|
224
|
+
})
|
package/source/models/section.ts
CHANGED
|
@@ -4,6 +4,9 @@ const BaseSection = z.object({
|
|
|
4
4
|
icon: z.string().optional(),
|
|
5
5
|
title: z.string(),
|
|
6
6
|
position: z.enum(["header", "sidebar"]).default("header"),
|
|
7
|
+
siteTitle: z.string().optional(),
|
|
8
|
+
siteDescription: z.string().optional(),
|
|
9
|
+
siteLink: z.string().optional(),
|
|
7
10
|
})
|
|
8
11
|
|
|
9
12
|
/** Default section: renders articles. */
|