gatsby-starter-blog に excerpt を表示する

May 04, 2022[Gatsby][gatsby-starter-blog]

gatsby-starter-blog のデフォルトでは一覧に本文の一部が表示されるようになっているが、以前使用していた gatsby-blog-mdx では frontmatter に excerpt というものがあり区別されていて、今回もそれをやりたい、という話。

一覧ページを作るための src/pages/index.js を見てみると以下のようになっていて、 frontmatter に description という項目を追加すると目的が達成できそうなことがわかった。

<section>
    <p
    dangerouslySetInnerHTML={{
        __html: post.frontmatter.description || post.excerpt,
    }}
    itemProp="description"
    />
</section>
---
description: この記事はこういう話です
---

でけた!


Profile picture

Written by hamcb