Skip to content

Commit

Permalink
Merge pull request #208 from varya/preview-hidden-image
Browse files Browse the repository at this point in the history
feat: hidden image for preview
  • Loading branch information
varya committed Aug 24, 2024
2 parents a7ac8f8 + fee3b03 commit 7fd2621
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
29 changes: 24 additions & 5 deletions src/components/Seo/Seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import PropTypes from "prop-types";
import config from "@content/meta/config";
import Helmet from "react-helmet";

const getImageUrl = ({ data, cover }) => {
const pageCover = ((data || {}).frontmatter || {}).cover;
const image =
pageCover && pageCover.childImageSharp
? pageCover.childImageSharp.gatsbyImageData
: cover || config.siteImage;

return config.siteUrl + image;
};

const Seo = ({ data, title, description, keywords, cover, location }) => {
const pageTitle = ((data || {}).frontmatter || {}).title;
const dataDescription =
Expand All @@ -27,11 +37,7 @@ const Seo = ({ data, title, description, keywords, cover, location }) => {
fullTitle = title;
}

const image = pageCover && pageCover.childImageSharp
? pageCover.childImageSharp.gatsbyImageData
: cover || config.siteImage;

const imageUrl = config.siteUrl + image;
const imageUrl = getImageUrl({ data, cover });
const url = config.siteUrl + "/" + config.pathPrefix + pageSlug;

const pageKeywords = keywords || config.defaultKeywords;
Expand Down Expand Up @@ -90,3 +96,16 @@ Seo.propTypes = {
};

export default Seo;

export const SeoImage = ({ data, cover }) => {
const imageUrl = getImageUrl({ data, cover });
return (
<img
src={imageUrl}
width="0"
height="0"
alt="Preview image"
aria-hidden="true"
/>
);
};
2 changes: 1 addition & 1 deletion src/components/Seo/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "./Seo";
export { default, SeoImage } from "./Seo";
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as PrevNextNav } from "./PrevNextNav";
export { default as ProjectRoles } from "./ProjectRoles";
export { default as Section } from "./Section";
export { default as Seo } from "./Seo";
export { SeoImage } from "./Seo";
export { default as SocialLinks } from "./SocialLinks";
export { default as Step } from "./Step";
export { default as Timetable } from "./Timetable";
Expand Down
3 changes: 2 additions & 1 deletion src/templates/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import PropTypes from "prop-types";
import { Box } from "grommet";
import { Hero } from "@components";
import { Layout } from "@components";
import { Seo } from "@components";
import { Seo, SeoImage } from "@components";

export const Page = (props) => {
const { children, hero, seo, location } = props;
const { props: heroProps, content } = { ...hero };
return (
<Layout location={location}>
<SeoImage {...seo} />
{seo && <Seo {...seo} location={location} defer={false} />}
{hero && (
<Hero align="center" justify="between" {...heroProps}>
Expand Down

0 comments on commit 7fd2621

Please sign in to comment.