Skip to content

Commit

Permalink
🎨 カスタムフックス練習
Browse files Browse the repository at this point in the history
  • Loading branch information
koma0504 committed Jun 29, 2021
1 parent 6847340 commit b94777b
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/pages/portfolio/[id].jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Footer } from "../../components/Footer/Footer";
import { Header } from "../../components/Header/Header";
import styles from "./portfolio.module.scss";

// pages/blog/[id].js
export default function BlogId({ blog }) {
return (
<div className="body">
<Header title={blog.title} />
<main className={styles.main}>
<h1 className={styles.title}>{blog.title}</h1>
<div
dangerouslySetInnerHTML={{
__html: `${blog.body}`,
}}
className={styles.post}
/>
</main>
<Footer />
</div>
);
}

// 静的生成のためのパスを指定します
export const getStaticPaths = async () => {
const key = {
headers: { "X-API-KEY": process.env.API_KEY },
};
const data = await fetch(
"https://ratio-observatory.microcms.io/api/v1/contents",
key
)
.then((res) => res.json())
.catch(() => null);
const paths = data.contents.map((content) => `/portfolio/${content.id}`);
return { paths, fallback: false };
};

// データをテンプレートに受け渡す部分の処理を記述します
export const getStaticProps = async (context) => {
const id = context.params.id;
const key = {
headers: { "X-API-KEY": process.env.API_KEY },
};
const data = await fetch(
"https://ratio-observatory.microcms.io/api/v1/contents/" + id,
key
)
.then((res) => res.json())
.catch(() => null);
return {
props: {
blog: data,
},
};
};

1 comment on commit b94777b

@vercel
Copy link

@vercel vercel bot commented on b94777b Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.