-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
}; |
b94777b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: