Skip to content

Commit

Permalink
feat: Add site notice to front-end
Browse files Browse the repository at this point in the history
Signed-off-by: Souptik Datta <souptikdatta2001@gmail.com>
  • Loading branch information
Souptik2001 committed Nov 30, 2024
1 parent cc0b4e0 commit 9c6517f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 12 deletions.
22 changes: 20 additions & 2 deletions components/Layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Box } from "@chakra-ui/react";
import { Box, Icon } from "@chakra-ui/react";
import Footer from './Footer';
import NavBar from "./Navbar";
import Seo from "./Seo/Seo";
import Notice from "./Notice";
import Sticky from "./Sticky";
import Link from 'next/link';
import { GrAnnounce, GrWordpress } from "react-icons/gr";

const Layout = ({
children,
Expand All @@ -10,6 +14,7 @@ const Layout = ({
customPageTitle,
customPageDescription,
customSeoMeta,
displayWPNotice = 'no',
customPublishedTime,
}) => {

Expand All @@ -23,7 +28,20 @@ const Layout = ({
customPageDescription={customPageDescription}
customSeoMeta={customSeoMeta}
/>
<NavBar position="sticky" top="0" px={["15px", null, null, "92px"]} py={10} marginBottom={["46px", null, "70px"]} borderBottom="1px solid rgba(255, 255, 255, 0.2)" background="rgba(0, 0, 0, 0.6)" backdropFilter="blur(6px)" />
<Sticky
zIndex="20"
>
{
displayWPNotice === 'yes' && data?.link && data?.link !== ''
&&
<Notice>
<p>
<Icon as={GrAnnounce} color="white" /> <Icon as={GrWordpress} color="white" /> Check out the <Link href={data.link} legacyBehavior>WordPress site</Link> for the same content in a new experience!
</p>
</Notice>
}
<NavBar />
</Sticky>
{ children }
<Footer px={["15px", null, null, "128px"]} py={["32px", null, null, "64px"]} />
</Box>
Expand Down
10 changes: 9 additions & 1 deletion components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const NavBar = (props) => {
const toggle = () => setIsOpen(!isOpen);

return (
<NavBarContainer background="black" textAlign="center" zIndex="20" {...props}>
<NavBarContainer textAlign="center" zIndex="20" {...props}>
<LogoAndToggleIconContainer zIndex="10">
<Link style={{textDecoration: "none"}} href="/"><Box fontSize="30px" cursor="pointer"></Box></Link>
<MenuToggle width={["25%", null, "auto"]} toggle={toggle} isOpen={isOpen} />
Expand Down Expand Up @@ -109,6 +109,14 @@ const NavBarContainer = ({ children, ...props }) => {
justifyContent="space-between"
flexDirection="row"
wrap="wrap"
position="sticky"
top="0"
px={["15px", null, null, "92px"]}
py={5}
marginBottom={["46px", null, "70px"]}
borderBottom="1px solid rgba(255, 255, 255, 0.2)"
background="rgba(0, 0, 0, 0.6)"
backdropFilter="blur(6px)"
{...props}
>
{children}
Expand Down
29 changes: 29 additions & 0 deletions components/Notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Flex } from "@chakra-ui/react";

const Notice = ({ children, ...props }) => {
return (
<Flex
className="notice"
justifyContent="center"
alignItems="center"
letterSpacing="4px"
wordSpacing="12px"
fontSize="13px"
color={"white"}
position="sticky"
top="0"
px={["15px", null, null, "92px"]}
py={2}
borderBottom="1px solid rgba(255, 255, 255, 0.2)"
background="rgba(0, 0, 0, 0.6)"
backdropFilter="blur(6px)"
textAlign="center"
zIndex={20}
{...props}
>
{children}
</Flex>
);
};

export default Notice;
16 changes: 16 additions & 0 deletions components/Sticky.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Box } from "@chakra-ui/react";

const Sticky = ({ children, ...props }) => {
return (
<Box
position="sticky"
top="0"
width={"100%"}
{...props}
>
{children}
</Box>
);
};

export default Sticky;
9 changes: 6 additions & 3 deletions pages/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import StripTags from '../src/escaping/StripTags';
import { doesSlugMatchesCustomPage } from '../src/helper-functions';
import styles from '../styles/Blog.module.css';

export default function Blog({frontend, slug}) {
export default function Blog({frontend, displayWPNotice, slug}) {

return(
<Layout
data={frontend?.data}
data={frontend?.data?.page}
yoastSeoData={frontend?.data?.page?.seo}
displayWPNotice={displayWPNotice}
>
<Head>
<title>{`${frontend?.data?.page?.title} | Souptik's Blog`}</title>
Expand Down Expand Up @@ -50,6 +51,7 @@ export async function getStaticProps({params}){
blocksJSON
date
title
link
author {
node {
name
Expand Down Expand Up @@ -118,7 +120,8 @@ export async function getStaticProps({params}){
return {
props: {
slug,
frontend: frontendData
frontend: frontendData,
displayWPNotice: process.env.DISPLAY_WP_SITE_NOTICE,
}
}
} catch(error) {
Expand Down
9 changes: 6 additions & 3 deletions pages/blog/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const parseDate = (rawDate) => {

}

export default function Blog({frontend, slug}) {
export default function Blog({frontend, displayWPNotice, slug}) {

const authorNameHoverCSS = {
textDecoration: "none",
Expand All @@ -41,8 +41,9 @@ export default function Blog({frontend, slug}) {

return(
<Layout
data={frontend?.data}
data={frontend?.data?.post}
yoastSeoData={frontend?.data?.post?.seo}
displayWPNotice={displayWPNotice}
>
<Head>
<title>{`${frontend?.data?.post?.title} | Souptik's Blog`}</title>
Expand Down Expand Up @@ -81,6 +82,7 @@ export async function getStaticProps({params}){
blocksJSON
date
title
link
author {
node {
name
Expand Down Expand Up @@ -152,7 +154,8 @@ export async function getStaticProps({params}){
return {
props: {
slug,
frontend: frontendData
frontend: frontendData,
displayWPNotice: process.env.DISPLAY_WP_SITE_NOTICE,
}
}
} catch(error) {
Expand Down
7 changes: 6 additions & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Layout from '../components/Layout';
import client from '../src/apollo/Client';
import styles from '../styles/Home.module.css';

export default function Home({posts, seoData}) {
export default function Home({posts, displayWPNotice, seoData}) {
const loadMore = () => {
updateBlogs(searchTerm, nextCursor);
}
Expand Down Expand Up @@ -55,6 +55,10 @@ export default function Home({posts, seoData}) {
siteName: "Souptik's Blog",
imageURL: seoData?.openGraph?.frontPage?.image?.link
}}
data={{
link: process.env.NEXT_PUBLIC_BACKEND_URL,
}}
displayWPNotice={displayWPNotice}
>
<Head>
<title>{"Souptik's Blog"}</title>
Expand Down Expand Up @@ -199,6 +203,7 @@ export async function getStaticProps() {
props: {
posts,
seoData: seoData?.data?.seo,
displayWPNotice: process.env.DISPLAY_WP_SITE_NOTICE,
}
};
} catch(error) {
Expand Down
16 changes: 14 additions & 2 deletions pages/user/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import StripTags from '../../src/escaping/StripTags';
import styles from '../../styles/Blog.module.css';
import userStyles from '../../styles/User.module.css';

export default function Blog({user, slug}) {
export default function User({user, displayWPNotice, slug}) {

const loadMore = async () => {

Expand Down Expand Up @@ -58,15 +58,24 @@ export default function Blog({user, slug}) {

registered = ( registered.length > 0 ) ? registered[0] : '';

// We need to modify the object, therefore create a new one, otherwise the original object is not editable.
user = {...user};

if ( user.url && user.uri ) {
user.link = user?.url + user?.uri;
}

return(
<Layout
data={user}
customPageTitle={`${authorName} | Souptik's Blog`}
customPageDescription={`Know about our user - "${authorName}"`}
customSeoMeta={{
title: `${authorName} | Souptik's Blog`,
description: `Know about our user "${authorName}"`,
siteName: "Souptik's Blog"
}}
displayWPNotice={displayWPNotice}
>
<Head>
<title>{`${authorName} | Souptik's Blog`}</title>
Expand Down Expand Up @@ -157,6 +166,8 @@ export async function getStaticProps({params}){
name
nicename
nickname
url
uri
avatar {
url
}
Expand Down Expand Up @@ -197,7 +208,8 @@ export async function getStaticProps({params}){
return {
props: {
slug,
user: user?.data?.user
user: user?.data?.user,
displayWPNotice: process.env.DISPLAY_WP_SITE_NOTICE,
}
}
} catch(error) {
Expand Down
2 changes: 2 additions & 0 deletions styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ a {
text-decoration: none;
}

.notice a,
.container a {
color: #71e3ff;
transition: color 1s, text-shadow 0.5s;
}

.notice a:hover,
.container a:hover {
color: #b6fdff;
}
Expand Down

0 comments on commit 9c6517f

Please sign in to comment.