mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-06 20:57:45 +00:00
fix: Update type for getPages function (#491)
* Fix getPages type * Even more precise type --------- Co-authored-by: MacFJA <macfja@gmail.com>
This commit is contained in:
7
src/lib/Mdsvx.d.ts
vendored
Normal file
7
src/lib/Mdsvx.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export type RecipeMetadata = {
|
||||||
|
title: string;
|
||||||
|
layout: string;
|
||||||
|
date: string;
|
||||||
|
children?: Array<unknown>;
|
||||||
|
};
|
||||||
|
export type EventMetadata = { title: string; layout: string; date: string };
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { getPages } from '../pageList';
|
import { getPages } from '../pageList';
|
||||||
|
import type { SvxMetadata } from '../pageList';
|
||||||
|
import type { EventMetadata } from '$lib/Mdsvx';
|
||||||
|
|
||||||
export async function load() {
|
export async function load() {
|
||||||
const events = await getPages(import.meta.glob('./**/*.svx'));
|
const events = await getPages<EventMetadata>(
|
||||||
|
import.meta.glob<SvxMetadata<EventMetadata>>('./**/*.svx')
|
||||||
|
);
|
||||||
|
|
||||||
if (events) {
|
if (events) {
|
||||||
events.sort((a, b) => Date.parse(b.date) - Date.parse(a.date));
|
events.sort((a, b) => Date.parse(b.date) - Date.parse(a.date));
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export async function getPages(
|
export type SvxMetadata<T extends object> = { metadata: T };
|
||||||
metaGlob: Array<string>
|
|
||||||
): Promise<Array<{ [key: string]: string; filename: string; path: string; title?: string }>> {
|
export async function getPages<T extends object>(
|
||||||
|
metaGlob: Record<string, () => Promise<SvxMetadata<T>>> // Should be `ReturnType<vite.ImportGlobFunction>` but the ast function overload is pick, which is the wrong one
|
||||||
|
): Promise<Array<T & { filename: string; path: string }>> {
|
||||||
const pages = await Promise.all(
|
const pages = await Promise.all(
|
||||||
Object.entries(metaGlob).map(async ([fullPath, page]) => {
|
Object.entries(metaGlob).map(async ([fullPath, page]) => {
|
||||||
const { metadata } = await page();
|
const { metadata } = await page();
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import '$styles/highlight.css';
|
import '$styles/highlight.css';
|
||||||
import { getPages } from '../pageList';
|
import { getPages } from '../pageList';
|
||||||
|
import type { SvxMetadata } from '../pageList';
|
||||||
|
import type { RecipeMetadata } from '$lib/Mdsvx';
|
||||||
|
|
||||||
export async function load() {
|
export async function load() {
|
||||||
const pages = (await getPages(import.meta.glob('./**/*.svx'))).map((element) => ({
|
const pages = (
|
||||||
|
await getPages<RecipeMetadata>(import.meta.glob<SvxMetadata<RecipeMetadata>>('./**/*.svx'))
|
||||||
|
).map((element) => ({
|
||||||
...element,
|
...element,
|
||||||
path: '/recipes' + element.path.substring(1)
|
path: '/recipes' + element.path.substring(1)
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user