Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

og-image周りの表示を調整 #13

Merged
merged 4 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/assets/default_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ require("dotenv").config()
*/

module.exports = {
siteMetadata: {
title: '< カグラボ />',
author: {
name: 'yu-kgr',
summary: '学んだ事や趣味のことなどについて、何かとごちゃごちゃしがちな思考を整理するブログです。'
},
description: '学んだ事や趣味のことなどについて、何かとごちゃごちゃしがちな思考を整理するブログです。',
siteUrl: 'https://kglabo.com/',
social: {
twitter: 'yu_kgr',
},
},
/**
* Adding plugins to this array adds them to your Gatsby site.
*
Expand Down Expand Up @@ -60,7 +72,6 @@ module.exports = {
*/
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,

{
// See https://www.gatsbyjs.com/plugins/gatsby-plugin-manifest/?=gatsby-plugin-manifest
resolve: `gatsby-plugin-manifest`,
Expand Down
81 changes: 35 additions & 46 deletions src/components/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,36 @@ import { Helmet } from "react-helmet"
import { useStaticQuery, graphql } from "gatsby"

const Seo = ({ description, lang, meta, title }) => {
const { wp, wpUser } = useStaticQuery(
const { site, file } = useStaticQuery(
graphql`
query {
wp {
generalSettings {
site {
siteMetadata {
title
description
siteUrl
social {
twitter
}
}
}

# if there's more than one user this would need to be filtered to the main user
wpUser {
twitter: name
file(relativePath: {eq: "default_image.png"}) {
id
childImageSharp {
gatsbyImageData
}
}
}
`
)


const metaDescription = description || site.siteMetadata.description
const defaultTitle = site.siteMetadata.title

const metaDescription = description || wp.generalSettings?.description
const defaultTitle = wp.generalSettings?.title
const siteUrl = site.siteMetadata.siteUrl;
const ogp_image = file.childImageSharp.gatsbyImageData.images.fallback.src;
const defaultImage = `${siteUrl}${ogp_image}`;

return (
<Helmet
Expand All @@ -40,54 +50,33 @@ const Seo = ({ description, lang, meta, title }) => {
title={title}
titleTemplate={defaultTitle ? `%s | ${defaultTitle}` : null}
meta={[
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: wpUser?.twitter || ``,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
{ name: `description`, content: metaDescription },
{ property: `og:title`, content: title },
{ property: `og:description`, content: metaDescription },
{ property: "og:image", content: defaultImage },
{ property: `og:type`, content: `website` },
{ name: `twitter:card`, content: `summary_large_image` },
{ name: `twitter:creator`, content: site.siteMetadata.social.twitter },
{ name: `twitter:title`, content: title },
{ name: `twitter:description`, content: metaDescription },
].concat(meta)}
/>
)
}
};

Seo.defaultProps = {
lang: `en`,
lang: `ja`,
meta: [],
description: ``,
}
image: null,
};

Seo.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
}
image: PropTypes.string,
};

export default Seo
export default Seo;
3 changes: 1 addition & 2 deletions src/templates/blog-post-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const BlogIndex = ({
data,
pageContext: { nextPagePath, previousPagePath },
}) => {
const posts = data.allWpPost.nodes
const posts = data.allWpPost.nodes;

if (!posts.length) {
return (
Expand Down Expand Up @@ -206,7 +206,6 @@ export const pageQuery = graphql`
name
}
}

featuredImage {
node {
altText
Expand Down