Slide 33
Slide 33 text
WP-API で記事を取得して、個別記事を生成
posts/[slug].astro
---
const { slug } = Astro.params;
const res = await fetch(`https://[wp-url]/wp-json/wp/v2/posts?slug=${slug}&_embed`)
const [post] = await res.json();
export async function getStaticPaths() {
const data = await fetch("https://[wp-url]/news/wp-json/wp/v2/posts?_embed")
const posts = await data.json();
return posts.map(({slug}) => ({
params: { slug },
}));
}
---
33