Skip to content

Commit de9a10c

Browse files
committed
🐛 fix article preview
1 parent 6652e84 commit de9a10c

File tree

8 files changed

+27
-17
lines changed

8 files changed

+27
-17
lines changed

netlify.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build]
2+
command = "npm run build"
3+
publish = "public"
4+
5+
[[headers]]
6+
for = "/*.css"
7+
[headers.values]
8+
Access-Control-Allow-Origin = "*"
9+
10+
[[headers]]
11+
for = "/assets/fonts/*"
12+
[headers.values]
13+
Access-Control-Allow-Origin = "*"

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"clean": "rm -rf public .cache",
99
"dev": "gatsby develop --port \"${PORT:-5000}\" --open -H 0.0.0.0",
1010
"build": "gatsby build",
11+
"postbuild": "cp src/*.css public",
1112
"lint": "eslint './*.js' 'src' 'plugins' 'gatsby'",
1213
"precommit": "lint-staged"
1314
},

src/components/Layout/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Inner = styled.div`
2121
width: 100%;
2222
`
2323

24-
const Layout = ({children}) => (
24+
const Layout = ({children, isPreview}) => (
2525
<MenuProvider>
2626
<Helmet>
2727
<link rel="icon" sizes="16x16" href="/assets/images/favicon-16.png" />
@@ -31,7 +31,7 @@ const Layout = ({children}) => (
3131
</Helmet>
3232
<Wrapper>
3333
<Inner>{typeof children === 'function' ? children() : children}</Inner>
34-
<Footer style={{flex: 'none'}} />
34+
{!isPreview && <Footer style={{flex: 'none'}} />}
3535
</Wrapper>
3636
</MenuProvider>
3737
)

src/components/Layout/withLayout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Layout from '.'
33

44
/* eslint-disable react/display-name */
55
const withLayout = Component => props => (
6-
<Layout>
6+
<Layout isPreview={props.isPreview}>
77
<Component {...props} />
88
</Layout>
99
)

src/components/MetaTags/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const MetaTags = ({
2323
const latlng = '-15.760837, -47.8702936'
2424
const locale = 'pt_BR'
2525
const truncatedDescription = truncate(description, 120)
26-
const imageURL = joinURL(image, homepage)
2726
return (
2827
<Helmet>
2928
<title>{composedTitle}</title>
@@ -36,7 +35,7 @@ const MetaTags = ({
3635
<meta property="og:url" content={joinURL(pathname, homepage)} />
3736
<meta property="og:type" content="website" />
3837
<meta property="og:title" content={composedTitle} />
39-
<meta property="og:image" content={imageURL} />
38+
{image && <meta property="og:image" content={image} />}
4039
<meta property="og:description" content={truncatedDescription} />
4140
<meta property="og:site_name" content={siteTitle} />
4241
<meta property="og:locale" content={locale} />
@@ -47,7 +46,7 @@ const MetaTags = ({
4746
<meta name="twitter:url" content={joinURL(pathname, homepage)} />
4847
<meta name="twitter:title" content={composedTitle} />
4948
<meta name="twitter:description" content={truncatedDescription} />
50-
<meta name="twitter:image" content={imageURL} />
49+
{image && <meta name="twitter:image" content={image} />}
5150
</Helmet>
5251
)
5352
}

src/components/StylableLink/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Link} from 'gatsby'
44
const StylableLink = ({to, children, className, style}) => {
55
const href = (to || {}).pathname || (typeof to === 'string' ? to : '/')
66
const props = {className, style, children}
7-
return /^[./]/.test(href) ? (
7+
return /^[./#]/.test(href) ? (
88
<Link {...props} to={to} />
99
) : (
1010
<a {...props} href={href} target="_blank" rel="noopener noreferrer" />

src/templates/article/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const BlogPost = ({
4343
authors,
4444
prev,
4545
next,
46+
isPreview,
4647
}) => {
4748
return (
4849
<Fragment>
@@ -51,7 +52,7 @@ const BlogPost = ({
5152
description={headline ? headline : excerpt}
5253
image={getCoverImageSrc(cover)}
5354
/>
54-
<Navbar style={{position: 'fixed', top: 0, zIndex: 2}} />
55+
{!isPreview && <Navbar style={{position: 'fixed', top: 0, zIndex: 2}} />}
5556
<ArticleHero
5657
headline={headline}
5758
title={title}

src/templates/article/preview.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import PropTypes from 'prop-types'
22
import {mapProps} from 'recompose'
33
import BlogPost from '.'
44

5-
const expand = (data, prop = 'title') =>
6-
((data || {}).slug || null) && {
7-
url: data.slug,
8-
[prop]: data.title,
9-
}
5+
const expand = (prop = 'title') => slug => ({url: `#${slug}`, [prop]: slug})
106

117
const enhance = mapProps(({entry, widgetFor}) => {
128
// eslint-disable-next-line no-unused-vars
13-
const {body, cover, ...data} = entry.getIn(['data']).toJS()
9+
const {body, ...data} = entry.getIn(['data']).toJS()
1410
return {
1511
...data,
12+
isPreview: true,
1613
content: widgetFor('body'),
1714
siteTitle: 'CMS',
18-
cover: (cover || null) && {image: {sizes: {src: cover}}},
19-
author: expand(data.author, 'name'),
20-
editorial: expand(data.editorial),
15+
authors: (data.authors || []).map(expand('name')),
16+
editorial: expand('title')(data.editorial),
2117
}
2218
})
2319

0 commit comments

Comments
 (0)