Skip to content

Commit 106be31

Browse files
committed
chore: fix typecheck
1 parent ab9ed1d commit 106be31

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

src/components/Toc.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { TocHeading } from '../utils/toc'
2+
import type { TocHeading } from '../utils/toc'
33
import TocItem from './TocItem.astro'
44
55
export interface Props {

src/components/TocItem.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import { TocHeading } from '../utils/toc'
2+
import type { TocHeading } from '../utils/toc'
33
44
export type Props = TocHeading
55

src/components/WrapperPost.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DraftContentNotice from './DraftContentNotice.astro'
88
import FallbackContentNotice from './FallbackContentNotice.astro'
99
import Toc from './Toc.astro'
1010
11-
const { entry, hasToc, headins } = Astro.props
11+
const { entry, hasToc, headings } = Astro.props
1212
const { data: frontmatter } = entry
1313
1414
let tweetUrl = ''
@@ -64,7 +64,7 @@ if (config.social?.mastodon) {
6464
{
6565
hasToc && (
6666
<section>
67-
<Toc headings={headins} />
67+
<Toc headings={headings} />
6868
</section>
6969
)
7070
}

src/routes/static/404.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const fallbackEntry: VitessePagesEntry = {
2727
head: [],
2828
subtitle: t('404.text'),
2929
draft: false,
30+
layoutFullWidth: false,
31+
tocAlwaysOn: false,
32+
inperson: false,
33+
recording: false,
34+
radio: false,
35+
video: false,
3036
},
3137
render: async () => ({
3238
Content: EmptyContent,

src/utils/route-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface VitesseRouteData extends Route {
1818
/** Site navigation sidebar entries for this page. */
1919
navBar: NavBarEntry[]
2020
hasToc: boolean
21-
headins: TocHeading[]
21+
headings: TocHeading[]
2222
}
2323

2424
/** Get the site title for a given language. */
@@ -59,6 +59,6 @@ export async function generateRouteData({
5959
siteTitleHref: getSiteTitleHref(locale),
6060
isFullWidthLayout: entry?.data.layoutFullWidth,
6161
hasToc,
62-
headins: tocHeading,
62+
headings: tocHeading,
6363
}
6464
}

src/utils/routing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ const normalizeIndexSlug = (slug: string): string => (slug === 'index' ? '' : sl
4949
/** All entries in the pages content collection. */
5050
const pages: VitessePagesEntry[] = (
5151
// eslint-disable-next-line antfu/no-top-level-await
52-
(await getCollection('pages', ({ data }: { data: any }): boolean => {
52+
(await getCollection('pages', ({ data }): boolean => {
5353
// In production, filter out drafts.
5454
return import.meta.env.MODE !== 'production' || data.draft === false
5555
})) ?? []
56-
).map(({ slug, ...entry }: { slug: string, [key: string]: any }) => ({
56+
).map(({ slug, ...entry }) => ({
5757
...entry,
5858
slug: normalizeIndexSlug(slug),
5959
}))

src/utils/vitesse-page.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ContentConfig, SchemaContext } from 'astro:content'
22
import type { VitessePagesEntry } from './routing'
3+
import type { TocHeading } from './toc'
34
import type { Prettify, RemoveIndexSignature } from './types'
45
import type { VitesseConfig, VitesseUserConfig } from './user-config'
56
import { z } from 'astro/zod'
@@ -23,7 +24,8 @@ import { slugToLocaleData, urlToSlug } from './slugs'
2324
* The frontmatter schema for Vitesse pages cannot include some properties which will be omitted
2425
* and some others needs to be refined to a stricter type.
2526
*/
26-
async function VitessePageFrontmatterSchema(context: SchemaContext): Promise<z.ZodEffects<z.ZodObject<any>>> {
27+
// eslint-disable-next-line ts/explicit-function-return-type
28+
async function VitessePageFrontmatterSchema(context: SchemaContext) {
2729
const userPagesSchema = await getUserPagesSchema()
2830
const schema = typeof userPagesSchema === 'function' ? userPagesSchema(context) : userPagesSchema
2931

@@ -58,7 +60,10 @@ async function VitessePageFrontmatterSchema(context: SchemaContext): Promise<z.Z
5860
* @see VitessePageFrontmatterSchema
5961
*/
6062
type VitessePageFrontmatter =
61-
z.input<Awaited<ReturnType<typeof VitessePageFrontmatterSchema>>>
63+
Omit<
64+
z.input<Awaited<ReturnType<typeof VitessePageFrontmatterSchema>>>,
65+
'navBar'
66+
>
6267

6368
/** Parse navBar prop to ensure it's valid. */
6469
function validateNavBarProp(navBarProp: VitesseUserConfig['navBar']): VitesseConfig['navBar'] {
@@ -75,9 +80,11 @@ function validateNavBarProp(navBarProp: VitesseUserConfig['navBar']): VitesseCon
7580
export type VitessePageProps = Prettify<
7681
// Remove the index signature from `Route`, omit undesired properties and make the rest optional.
7782
Partial<Omit<RemoveIndexSignature<PageProps>, 'entry' | 'entryMeta' | 'id' | 'locale' | 'slug'>> &
78-
{
83+
// Add the sidebar definitions for a Starlight page.
84+
Partial<Pick<VitesseRouteData, 'hasToc'>> & {
7985
navBar?: VitesseUserConfig['navBar']
80-
// And finally add the Vitesse page frontmatter properties in a `frontmatter` property.
86+
headings?: TocHeading[]
87+
// And finally add the Starlight page frontmatter properties in a `frontmatter` property.
8188
frontmatter: VitessePageFrontmatter
8289
}
8390
>
@@ -119,9 +126,6 @@ export async function generateVitessePageRouteData({
119126
collection: 'pages',
120127
data: {
121128
...pageFrontmatter,
122-
navBar: {
123-
attrs: {},
124-
},
125129
},
126130
}
127131
const entry = pagePagesEntry as unknown as VitessePagesEntry
@@ -140,6 +144,8 @@ export async function generateVitessePageRouteData({
140144
siteTitle: getSiteTitle(localeData.lang),
141145
siteTitleHref: getSiteTitleHref(localeData.locale),
142146
slug,
147+
hasToc: props.hasToc ?? false,
148+
headings: props.headings ?? [],
143149
}
144150
if (isFallback) {
145151
routeData.isFallback = true

0 commit comments

Comments
 (0)