Skip to content

Commit

Permalink
fix(seo): trying to improve image on SEO
Browse files Browse the repository at this point in the history
  • Loading branch information
ggdaltoso committed Oct 8, 2021
1 parent 9e0f16a commit e92171d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { Helmet } = require('react-helmet');

exports.onRenderBody = ({
setHeadComponents,
setHtmlAttributes,
setBodyAttributes,
}) => {
const helmet = Helmet.renderStatic();

setHtmlAttributes(helmet.htmlAttributes.toComponent());
setBodyAttributes(helmet.bodyAttributes.toComponent());

setHeadComponents([
helmet.title.toComponent(),
helmet.link.toComponent(),
helmet.meta.toComponent(),
helmet.noscript.toComponent(),
helmet.script.toComponent(),
helmet.style.toComponent(),
]);
};

exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents();

headComponents.sort((x, y) => {
if (x.props && x.props['data-react-helmet']) {
return -1;
} else if (y.props && y.props['data-react-helmet']) {
return 1;
}
return 0;
});

replaceHeadComponents(headComponents);
};

0 comments on commit e92171d

Please sign in to comment.