Skip to content

Commit

Permalink
fix(gatsby): ssr with script
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoirelacoste committed Sep 7, 2021
1 parent 70034c9 commit 76090f6
Show file tree
Hide file tree
Showing 5 changed files with 1,297 additions and 3,237 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ yarn-error.log
/src/app/website/.cache
/src/app/website/node_modules
/src/app/website/public
/src/app/website/static/script/profiles/
41 changes: 36 additions & 5 deletions src/app/website/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,46 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const React = require('react');

exports.onRenderBody = ({ setHeadComponents, pathname }) => {
console.log('pathname', pathname);
console.log(pathname === 'fr/profiles' && 'coucou');
setHeadComponents([
exports.onRenderBody = ({
pathname,
setPreBodyComponents,
setPostBodyComponents
}) => {
const profilesRegex = new RegExp('profiles', 'g');
console.warn(
"!!, Le path n'est généré que au PROD build sur Gatsby",
'profilesRegex.test(pathname)',
pathname,
profilesRegex.test(pathname)
);
setPreBodyComponents([<div key={1} id={'root'} />]);
setPostBodyComponents([
<script
key={1}
src="https://code.createjs.com/1.0.0/createjs.min.js"
type="text/javascript"
/>,
<script key={1} src="/script/animation.js" type="text/javascript" />
<script key={2} src="/script/animation.js" type="text/javascript" />,
<script
key={3}
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"
type="text/javascript"
/>,
<script
key={4}
src="https://cdn.jsdelivr.net/npm/[email protected]/bundled.js"
type="text/javascript"
/>,
<script
key={5}
src="https://cdn.jsdelivr.net/npm/[email protected]/find.min.js"
type="text/javascript"
/>,
<script key={6} src="/script/bulle-extension.js" type="text/javascript" />,
<script
key={7}
src="/script/profiles/js/profiles.bundle.js"
type="text/javascript"
/>
]);
};
4 changes: 2 additions & 2 deletions src/app/website/src/components/seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ interface SeoProps {
| { name: string; content: unknown; property?: undefined }
| { property: string; content: unknown; name?: undefined }
>;
title: string;
title?: string;
}

function Seo({ description, lang, meta, title }: SeoProps) {
function Seo({ description, lang, meta, title = 'Dis Moi' }: SeoProps) {
const { site } = useStaticQuery(
graphql`
query {
Expand Down
Loading

0 comments on commit 76090f6

Please sign in to comment.