Skip to content

Commit 32cd271

Browse files
committed
Add slices for site header, footer, and CTAs; refactor layout to use slices
Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
1 parent 0cd449b commit 32cd271

10 files changed

Lines changed: 74 additions & 16 deletions

File tree

gatsby-node.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,37 @@ if (process.env.CI === "true") {
5050
const { loadRedirects } = require("./src/utils/redirects.js");
5151

5252
exports.createPages = async ({ actions, graphql, reporter }) => {
53-
const { createRedirect } = actions;
53+
const { createRedirect, createSlice } = actions;
5454
const redirects = loadRedirects();
5555
redirects.forEach(redirect => createRedirect(redirect)); // Handles all hardcoded ones dynamically
5656
// Create Pages
5757
const { createPage } = actions;
5858

59+
createSlice({
60+
id: "site-header",
61+
component: path.resolve("./src/slices/site-header.js"),
62+
});
63+
64+
createSlice({
65+
id: "site-footer",
66+
component: path.resolve("./src/slices/site-footer.js"),
67+
});
68+
69+
createSlice({
70+
id: "cta-bottom",
71+
component: path.resolve("./src/slices/cta-bottom.js"),
72+
});
73+
74+
createSlice({
75+
id: "cta-fullwidth",
76+
component: path.resolve("./src/slices/cta-fullwidth.js"),
77+
});
78+
79+
createSlice({
80+
id: "cta-imageonly",
81+
component: path.resolve("./src/slices/cta-imageonly.js"),
82+
});
83+
5984
const envCreatePage = (props) => {
6085
if (process.env.CI === "true") {
6186
const { path, matchPath, ...rest } = props;

root-wrapper.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from "react";
22
import { MDXProvider } from "@mdx-js/react";
33
import Code from "./src/components/CodeBlock";
4-
import CTA_ImageOnly from "./src/components/Call-To-Actions/CTA_ImageOnly";
5-
import CTA_FullWidth from "./src/components/Call-To-Actions/CTA_FullWidth";
6-
import CTA_Bottom from "./src/components/Call-To-Actions/CTA_Bottom";
4+
import { Slice } from "gatsby";
75
import { ContextWrapper } from "./context-wrapper";
86

97
// Custom image component for better CLS scores
@@ -41,9 +39,9 @@ const components = {
4139
}
4240
},
4341
img: OptimizedImage,
44-
CTA_ImageOnly,
45-
CTA_FullWidth,
46-
CTA_Bottom
42+
CTA_ImageOnly: (props) => <Slice alias="cta-imageonly" sliceContext={props} />, // slice to avoid page rebuilds on CTA tweaks
43+
CTA_FullWidth: (props) => <Slice alias="cta-fullwidth" sliceContext={props} />, // slice to avoid page rebuilds on CTA tweaks
44+
CTA_Bottom: (props) => <Slice alias="cta-bottom" sliceContext={props} />
4745
};
4846

4947
export const wrapRootElement = ({ element }) => (

src/components/layout.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@
99

1010
import React from "react";
1111
import PropTypes from "prop-types";
12+
import { Slice } from "gatsby";
1213
import ScrollToTopBtn from "./Scrolltotop-button";
13-
import Navigation from "../sections/General/Navigation";
14-
import Footer from "../sections/General/Footer";
1514
// import TopPromotionalBanner from "./TopPromotionalBanner";
1615
import { GlobalStyle } from "../sections/app.style";
17-
import CookieConsent from "./CookieConsent";
1816

1917
const Layout = ({ children }) => {
2018

2119
return (
2220
<>
2321
<GlobalStyle />
2422
{/* <TopPromotionalBanner /> */}
25-
<Navigation/>
26-
<CookieConsent />
23+
<Slice alias="site-header" />
2724
{children}
2825
<ScrollToTopBtn />
29-
<Footer location={children.props.location} />
26+
<Slice alias="site-footer" />
3027
</>
3128
);
3229
};

src/sections/General/Footer/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import React from "react";
22
import { Link } from "gatsby";
33
import { Container, Row, Col } from "../../../reusecore/Layout";
4+
import { useLocation } from "@reach/router";
45
import logo from "../../../assets/images/layer5/layer5-only/svg/layer5-light-bg.svg";
56
import SocialLinksColor from "../../../components/SocialLinks-Color";
67
import Button from "../../../reusecore/Button";
78
import FooterWrapper from "./footer.style";
89
import bubblesElement from "./images/bubbles-element.svg";
910

10-
const Footer = ({ location }) => {
11+
const Footer = ({ location: locationProp }) => {
1112
var currentYear = new Date().getFullYear();
13+
const routerLocation = useLocation();
14+
const pathname = locationProp?.pathname || routerLocation?.pathname || "/";
1215

1316
const getUrl = (pathname) => {
1417
// remove ".html" that results in live production build
@@ -349,7 +352,7 @@ const Footer = ({ location }) => {
349352
<ul className="misc-links">
350353
<li className="edit-page">
351354
<a
352-
href={getUrl(location.pathname)}
355+
href={getUrl(pathname)}
353356
target="_blank"
354357
rel="noreferrer"
355358
>

src/slices/cta-bottom.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import CTA_Bottom from "../components/Call-To-Actions/CTA_Bottom";
3+
4+
const CTABottomSlice = ({ sliceContext = {} }) => <CTA_Bottom {...sliceContext} />;
5+
6+
export default CTABottomSlice;

src/slices/cta-fullwidth.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import CTA_FullWidth from "../components/Call-To-Actions/CTA_FullWidth";
3+
4+
const CTAFullWidthSlice = ({ sliceContext = {} }) => <CTA_FullWidth {...sliceContext} />;
5+
6+
export default CTAFullWidthSlice;

src/slices/cta-imageonly.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import CTA_ImageOnly from "../components/Call-To-Actions/CTA_ImageOnly";
3+
4+
const CTAImageOnlySlice = ({ sliceContext = {} }) => <CTA_ImageOnly {...sliceContext} />;
5+
6+
export default CTAImageOnlySlice;

src/slices/site-footer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import Footer from "../sections/General/Footer";
3+
4+
const SiteFooterSlice = () => <Footer />;
5+
6+
export default SiteFooterSlice;

src/slices/site-header.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
import Navigation from "../sections/General/Navigation";
3+
import CookieConsent from "../components/CookieConsent";
4+
5+
const SiteHeaderSlice = () => (
6+
<>
7+
<Navigation />
8+
<CookieConsent />
9+
</>
10+
);
11+
12+
export default SiteHeaderSlice;

src/templates/lite-placeholder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import SEO from "../components/seo";
33

44
const LitePlaceholder = ({ pageContext, location }) => {
55
const {
6-
entity = "page",
76
heading = "Content disabled in lite mode",
87
description = "This route is intentionally skipped when BUILD_FULL_SITE=false.",
98
} = pageContext;

0 commit comments

Comments
 (0)