Replies: 2 comments 2 replies
-
Another thing. I can use markdown not only for pages but also for components. But when I import such a component and have TypeScript enabled, I get "JSX element type '...' does not have any construct or call signatures.ts(2604)". |
Beta Was this translation helpful? Give feedback.
-
One way to do this kind of thing in SvelteKit is to use a server route. In that server route we could fetch some JSON like this: // in this example content is an array of 'blocks'
const response = {
name: 'hello',
id: 0123,
author: 'Franklin',
content: [{
id: 0,
type: 'text',
value: 'hello i am text'
},
{
id: 0,
type: 'mdsvex',
value: '> some quote'
}
} In the JSON endpoint you would need to fetch this JSON and then process it, the processing could look something like this: import { compile } from "mdsvex";
async function transform({ name, id, author, content }) {
// `compile` returns a promise, so we need to await it
const transformed = Promise.all(
content.map(async ({ id, type, value }) => ({
id,
type,
value: type === "mdsvex" ? await compile(value) : value,
}))
);
return {
name,
id,
author,
content: transformed,
};
} And then in your component after you fetch this data you can loop over the content blocks and handle them appropriately, using If any of those If you end up with a Svelte component instead of HTML in those content blocks then you will need to I hope this helps a little! |
Beta Was this translation helpful? Give feedback.
-
I am getting markdown and json files from a headless cms. The json files can also have markdown in values and frontmatter in markdown files has sometimes, too.
What would you suggest is a good way to use that with SvelteKit? Single markdown pages are not the problem. But if I have a json file with markdown as value, can I somehow use your library to parse that markdown to HTML? Or even better, can I somehow create Svelte components from markdown and json files and then combine them?
For example, I have several different content blocks. They come as json files with maybe markdown values in some fields, some are pure values. Then there is a page content that can use those components and bring them in a certain order. That page could be a markdown file.
Beta Was this translation helpful? Give feedback.
All reactions