-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch all content from markdown files #294
Comments
Here is a simple setup that will get you what you want // src/routes/blog/_posts.ts
import { basename, dirname } from "path";
export type Post = {
slug: string;
title: string;
excerpt: string;
isPublished: boolean;
publishedOn: string;
updatedOn: string;
};
const modules = import.meta.globEager("/content/posts/**/*.svelte.md");
export const posts: Post[] = Object.entries(modules).map(([filepath, module]) => {
const slug = basename(dirname(filepath));
const { metadata } = module;
const { html } = module.default.render();
return {
slug,
html,
...metadata,
};
}); // src/routes/blog/index.json.ts
import type { EndpointOutput } from "@sveltejs/kit";
import { posts } from "./_posts";
export async function get(): Promise<EndpointOutput> {
return {
body: JSON.stringify(posts),
};
} This sets up an endpoint |
It works. Thanks! |
Hi Michael. I have a question about your example if you don't mind me asking. I am trying to understand how you got the following line to work in your page data file:
It works for me within a svelte component with a reactive declaration, but when I try to place it in my page data file, I get the following error messages on the client side:
The data does appear in my server console though. |
I get the same intermittent error as @deep-research. Will try moving the code as suggested. |
Hi,
I'm a newbie. I'm tring to build an infinite scrolling homepage for my blog with SvelteKit and MDsveX. I need to fetch all the content from the .svx/.md files, not only the metadata. I've tried some methods (for example this one or other similar with
import.meta.glob
but with I only fetch the metadata and not the whole html.May you help me?
Thanks
The text was updated successfully, but these errors were encountered: