Skip to content

feat(misc) Add OG and Twitter metadata #2414

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

Merged
merged 1 commit into from
Aug 1, 2018
Merged
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
13 changes: 12 additions & 1 deletion src/server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Site from './components/Site/Site';

// Import Images
import Favicon from './favicon.ico';
import Logo from './assets/logo-on-white-bg.svg';

// Define bundles (previously used `Object.values(locals.assets)`) but
// can't retrieve from there anymore due to separate compilation.
Expand All @@ -23,6 +24,7 @@ const bundles = [
export default locals => {
let { assets } = locals.webpackStats.compilation;
let title = getPageTitle(locals.content, locals.path);
let description = 'webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.';

return ReactDOMServer.renderToString(
<StaticRouter location={locals.path} context={{}}>
Expand All @@ -32,7 +34,16 @@ export default locals => {
<meta name="theme-color" content="#2B3A42" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
<meta name="description" content="webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset." />
<meta name="description" content={ description } />
<meta property="og:site_name" content="webpack" />
<meta property="og:type" content="website" />
<meta property="og:title" content={ title } />
<meta property="og:description" name="description" content={ description } />
<meta property="og:image" content={ Logo } />
<meta property="twitter:card" content="summary" />
<meta property="twitter:site" content="@webpack" />
<meta property="twitter:creator" content="@webpack" />
<meta property="twitter:domain" content="https://webpack.js.org/" />
Copy link
Member

Choose a reason for hiding this comment

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

I am 99% sure that when sharing the link server will return static HTML.
I mean, there is not need for a React component for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

i am not sure what you mean, which react component?

Copy link
Member

Choose a reason for hiding this comment

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

From the client side.
I mean, it is fine :)

Copy link
Member Author

Choose a reason for hiding this comment

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

ah i thought it was change request, didnt see if thats approved or not :D

<link rel="icon" type="image/x-icon" href={ Favicon } />
{ Object.keys(assets).filter(asset => /\.css$/.test(asset)).map(path => (
<link key={ path } rel="stylesheet" href={ `/${path}` } />
Expand Down