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

Pre-rendered seo #46

Merged
merged 10 commits into from
May 21, 2020
816 changes: 780 additions & 36 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"postbuild": "react-snap",
"test": "node scripts/test.js",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
Expand Down Expand Up @@ -147,6 +148,8 @@
]
},
"devDependencies": {
"react-helmet": "^6.0.0",
"react-snap": "^1.23.0",
"responsive-loader": "^1.2.0",
"sharp": "^0.25.3"
}
Expand Down
8 changes: 4 additions & 4 deletions src/BlobField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useHistory } from "react-router-dom";
import config from "src/config";
import paper from "paper";

import style from "./style.module.scss";
import './style-blobs.css';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This managed to fix the styling when the user enters the homepage from and external link or by typing in the address bar.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very strange that this would happen here and not break the other components that use css modules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly my thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't reproduce this. I renamed style-blobs.css to style.module.css, removed blobs- from the style names. and then

import {
  wrapper,
  popover,
} from './style.module.css';

in the index.js and then className={wrapper} etc and the correct styles are being applied. It does appear as style_wrapper__1dMCn but that's just the generated name from the css modules. The content of the class is accurate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or was this only happening on Production? Just realized that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is happening in production. Also I have temporarily fixed it by removing the class assignment on PageHeader. Have a look at the last commit when you can 7767417

import Blobs from "./blobs";

import ArtistNav from "../Components/ArtistNav/";
Expand Down Expand Up @@ -105,9 +105,9 @@ export default function BlobField({ collapsed = false }) {

return (
<div
className={style.wrapper}
className='blobs-wrapper'
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again fixing styling when entering the homepage from an external link or by typing in the address bar. #46 (comment)

ref={wrapperEl}
style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
// style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>
<ArtistNav />
<canvas ref={animationEl}/>
Expand All @@ -122,7 +122,7 @@ export default function BlobField({ collapsed = false }) {
: "NEARREST NEIGHBOR"}
</div>
)}
<div className={style.popover} style={popoverStyle}>
<div className='blobs-popover' style={popoverStyle}>
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{collapsed && activeArtist ? activeArtist.name.toUpperCase() : ""}
</div>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/BlobField/style.module.scss → src/BlobField/style-blobs.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
.wrapper {
.blobs-wrapper {
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from SASS to pure CSS #46 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you try this with the modules in place? I'm wondering if it was actually sass that was breaking it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna give it a try and report back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No success :(

I found:

There's also the following in my console during dev preview:

Warning: Expected server HTML to contain a matching <div> in <div>.
    in div (at App/index.js:10)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App/index.js:9)
    in Unknown (at src/index.js:17)
    in StrictMode (at src/index.js:16)
console.<computed> @ index.js:1

Wondering if this has to do with that lingering "," but figuring it out is way over my head and my react knowledge.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. i can take a look after the lecture tonight

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey managed to narrow down the issue to PageHeader component's outermost div. Removing the className on this element fixes the problem. But no matter how hard I tried to add the class back, be it through pure css, having the css in the public folder and linking in html, sass, etc, it kept messing up the bg titles after returning to homepage from an artist page. I hope this helps.

7767417

display: flex;
height: 100%;
justify-content: center;
flex-direction: column;
position: relative;
width: 100%;
svg, canvas {
position: fixed;
bottom: 0;
// left: 0;
right: 0;
// top: 0;
z-index: 999;
}
}

.blobs-wrapper > svg, canvas {
position: fixed;
bottom: 0;
/* left: 0; */
right: 0;
/* top: 0; */
z-index: 999;
}

.popover{
.blobs-popover{
position: fixed;
z-index: 9999;
transform: translate(0, -50%);
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ProjectHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './style.module.css';

const ProjectHeader = ({artistName, title, materials, link, children}) => (
<div className={container}>
<div>
<h3 className={headerArtist}>{artistName}</h3>
<h2 className={headerTitle}>{title}</h2>
<div className={headerMaterials} dangerouslySetInnerHTML={{__html: materials}} />
Expand Down
106 changes: 106 additions & 0 deletions src/Components/Seo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// https://github.com/stereobooster/react-snap/blob/master/doc/recipes.md
// From https://github.com/stereobooster/an-almost-static-stack/blob/react-snap/src/components/Seo.js
import React from 'react';
import PropTypes from 'prop-types';
import {Helmet} from "react-helmet";

const absoluteUrl = path => `https://deploy-preview-46--kind-tesla-a088c1.netlify.app/${path}`;
const seoImageURL = file => `https://deploy-preview-46--kind-tesla-a088c1.netlify.app${file}`;

const getMetaTags = ({
title, description, url, contentType, published, updated, category, tags, twitter, image,
}) => {
const metaTags = [
{ itemprop: 'name', content: title },
{ itemprop: 'description', content: description ? description : 'Online MFA show for 2020 DMA grads.'},
{ name: 'description', content: description ? description : 'Online MFA show for 2020 DMA grads.'},
{ name: 'twitter:site', content: twitter},
{ name: 'twitter:title', content: `${title} | NEARREST NEIGHBOR` },
{ name: 'twitter:description', content: description },
{ name: 'twitter:creator', content: twitter},
{ property: 'og:title', content: `${title} | NEARREST NEIGHBOR` },
{ property: 'og:type', content: contentType }, //https://ogp.me/#types
{ property: 'og:url', content: url },
{ property: 'og:description', content: description },
{ property: 'og:site_name', content: 'NEARREST NEIGHBOR' },
{ property: 'og:locale', content: 'en_EN' },
// { name: 'fb:app_id', content: '<FB App ID>' },
];

if (published) metaTags.push({ name: 'article:published_time', content: published });
if (updated) metaTags.push({ name: 'article:modified_time', content: updated });
if (category) metaTags.push({ name: 'article:section', content: category });
if (tags) metaTags.push({ name: 'article:tag', content: tags });
if (image) {
metaTags.push({ itemprop: 'image', content: seoImageURL(image) });
metaTags.push({ name: 'twitter:image:src', content: seoImageURL(image) });
metaTags.push({ property: 'og:image', content: seoImageURL(image) });
metaTags.push({ name: 'twitter:card', content: 'summary_large_image' });
} else {
metaTags.push({ name: 'twitter:card', content: 'summary' });
}

return metaTags;
};

const getHtmlAttributes = ({
schema
}) => {
let result = {
lang: 'en',
};
if (schema) {
result = {
...result,
itemscope: undefined,
itemtype: `http://schema.org/${schema}`,
}
}
return result;
}

getHtmlAttributes.propTypes = {
schema: PropTypes.string,
};

const Seo = ({
schema, title, description, path, contentType, published, updated, category, tags, twitter, image
}) => (
<Helmet
htmlAttributes={getHtmlAttributes({
schema,
})}
title={ `${title} | NEARREST NEIGHBOR`}
link={[
{ rel: 'canonical', href: absoluteUrl(path) },
]}
meta={getMetaTags({
title,
description,
contentType,
url: absoluteUrl(path),
published,
updated,
category,
tags,
twitter,
image: image ? image.images[image.images.length - 1].path : 'FALLBACKIMAGE'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FALLBACKIMAGE needs to be changed to default image later on.

})}
/>
);

Seo.propTypes = {
schema: PropTypes.string,
title: PropTypes.string,
description: PropTypes.string,
path: PropTypes.string,
contentType: PropTypes.string,
published: PropTypes.string,
updated: PropTypes.string,
category: PropTypes.string,
tags: PropTypes.array,
twitter: PropTypes.string,
image: PropTypes.object,
};

export default Seo;
4 changes: 2 additions & 2 deletions src/Containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default () => (
<Suspense fallback={<div />}>
<Switch>
{
config.artists.map(({slug, component}) => {
config.artists.map(({slug, component}, i) => {
const Comp = lazy(() => import(`../../work/${component}`));
return (
<Route path={`/${slug}`} key={slug}>
<Comp />
<Comp config={config.artists[i]}/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the config data to the artist component to automatically infer the path and title.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this will do what is intended. Lazy is used to code split the bundle, so each artist has their own js file instead of loading them all at once. Or is this just to pass the SEO metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to just pass the SEO data from the config to the component. I'm not sure if what I'm doing is right. But the styling issue existed even when I had the metadata hardcoded with this file unmodified.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird. lets see how removing sass goes and then i can poke around if you want. If the site is going to be static though you could remove the lazy stuff entirely since it won't help too much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like snap supports webpack chunks. Is this what Lazy uses? Based on what I know snap is only semi-static and still depends on being hydrated, generating the most basic html needed for pre-rendering. Wonder if chunks help in this regard. Also glancing over the generated artist htmls I see a lot of xxxxx.chunk.js

</Route>
)
})
Expand Down
2 changes: 2 additions & 0 deletions src/Containers/App/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ body {
font-family: sans-serif;
font-weight: 700;
line-height: initial;
margin-top: 50vh;
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again fixing styling when entering the homepage from and external link or by typing in the address bar. Translation is to accommodate centering in the absence of
style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
#46 (comment)

transform: translateY(-50%);
}

.blobs {
Expand Down
29 changes: 23 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@ import ReactDOM from 'react-dom';
import App from './Containers/App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// ReactDOM.render(
// <React.StrictMode>
// <App />
// </React.StrictMode>,
// document.getElementById('root')
// );

const rootElement = document.getElementById("root");
if (rootElement.hasChildNodes()) {
ReactDOM.hydrate(
<React.StrictMode>
<App />,
</React.StrictMode>,
rootElement
);
} else {
ReactDOM.render(
<React.StrictMode>
<App />,
</React.StrictMode>,
rootElement
);
}

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
Expand Down
111 changes: 64 additions & 47 deletions src/work/BenLerchin.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,69 @@
import React from 'react';
import React from "react";

import Artist from '../Containers/Artist';
import ProjectCover from '../Components/ProjectCover';
import ProjectHeader from '../Components/ProjectHeader';
import ArtistBio from '../Components/ArtistBio';
import ProjectColumns, { Column } from '../Components/ProjectColumns';
import Image from '../Components/Image';
import Vimeo from '../Components/VideoVimeo'
import Artist from "../Containers/Artist";
import ProjectCover from "../Components/ProjectCover";
import ProjectHeader from "../Components/ProjectHeader";
import ArtistBio from "../Components/ArtistBio";
import ProjectColumns, { Column } from "../Components/ProjectColumns";
import Image from "../Components/Image";
import Vimeo from "../Components/VideoVimeo";

import BenImage from './assets/BenLerchin-yimby-cover.jpg';
import Placeholder from './assets/placeholder.png';
import BenImage from "./assets/BenLerchin-yimby-cover.jpg";
import Placeholder from "./assets/placeholder.png";

export default function() {
return (
<Artist>
<ProjectHeader
artistName="Ben Lerchin"
title="Yes, in my Backyard"
materials="10 minute video"
link="http://benlerchin.com"
/>
<ProjectCover>
<Image
img={BenImage}
alt='Still from video. A gray industrial concrete and metal box is in the foreground, with the text
import Seo from "../Components/Seo";
export default function (config) {
return (
<Artist>
<Seo
title={config.config.name}
description="Scelerisque venenatis nibh fames ad quam feugiat leo commodo vitae sed lacus."
path={config.config.slug}
image={BenImage}
/>
<ProjectHeader
artistName="Ben Lerchin"
title="Yes, in my Backyard"
materials="10 minute video"
link="http://benlerchin.com"
/>
<ProjectCover>
<Image
img={BenImage}
alt='Still from video. A gray industrial concrete and metal box is in the foreground, with the text
"MILE 103" obliquely visible. Low brush growth is seen in the near background, behind which a number
of wind turbines are visible.'
/>
</ProjectCover>
<ProjectColumns>
<Column>
<Vimeo
url="https://player.vimeo.com/video/TK?color=ffffff&amp;title=0&amp;byline=0&amp;portrait=0"
/>
</Column>
</ProjectColumns>
<ProjectColumns>
<Column>
<p>
Semi-satirical mockumentary reframing Los Angeles' infrastructure as a tourist destination for nature-lovers.
</p>
</Column>
</ProjectColumns>
<ArtistBio>
<p>
Ben Lerchin is an artist and technologist who works with software, photography, and digital fabrication. Their practice deals extensively with the relationship between the photographic image and the American West. Reflecting on the uneasy experience of living between the city and the wilderness, my work attempts to reconcile a networked, industrialized lifestyle with the unstable ground under our feet. It is an attempt to erase boundaries with the natural world, and to see it not as victim nor antagonist, but as co-conspirator and friend. Using digital photographic processes, Ben embeds a polyphony of viewpoints into three dimensional forms reminiscent of the landscape from which they emerge, showing sites of resource management in relation to the people that depend on them.
</p>
</ArtistBio>
</Artist>
);
}
/>
</ProjectCover>
<ProjectColumns>
<Column>
<Vimeo url="https://player.vimeo.com/video/TK?color=ffffff&amp;title=0&amp;byline=0&amp;portrait=0" />
</Column>
</ProjectColumns>
<ProjectColumns>
<Column>
<p>
Semi-satirical mockumentary reframing Los Angeles' infrastructure as
a tourist destination for nature-lovers.
</p>
</Column>
</ProjectColumns>
<ArtistBio>
<p>
Ben Lerchin is an artist and technologist who works with software,
photography, and digital fabrication. Their practice deals extensively
with the relationship between the photographic image and the American
West. Reflecting on the uneasy experience of living between the city
and the wilderness, my work attempts to reconcile a networked,
industrialized lifestyle with the unstable ground under our feet. It
is an attempt to erase boundaries with the natural world, and to see
it not as victim nor antagonist, but as co-conspirator and friend.
Using digital photographic processes, Ben embeds a polyphony of
viewpoints into three dimensional forms reminiscent of the landscape
from which they emerge, showing sites of resource management in
relation to the people that depend on them.
</p>
</ArtistBio>
</Artist>
);
}
Loading