Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 5cb7782

Browse files
committed
Post Web layout for app inclusion in webview 🚀
1 parent 1b0ef55 commit 5cb7782

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

src/components/design-system/templates/blog-page-template.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { FC, ReactNode } from "react";
1212

1313
const Footer = loadable(() => import(`../organism/footer`));
1414

15-
const ContentContainer = styled(Container)`
16-
margin-top: ${(props) => props.theme.spacing[12]};
15+
const ContentContainer = styled(Container)<{ pageOpenedFromApp: boolean }>`
16+
margin-top: ${(props) =>
17+
props.pageOpenedFromApp ? 0 : props.theme.spacing[12]};
1718
flex: 1 0 auto;
1819
`;
1920

@@ -23,6 +24,7 @@ export interface BlogPageProps {
2324
ogPageType: OgPageType;
2425
ogImage: string;
2526
trackingCategory: string;
27+
pageOpenedInApp: boolean;
2628
customTitle?: string;
2729
description?: string;
2830
date?: string;
@@ -37,6 +39,7 @@ export const BlogPageTemplate: FC<BlogPageProps> = ({
3739
ogPageType,
3840
ogImage,
3941
trackingCategory,
42+
pageOpenedInApp,
4043
customTitle,
4144
description,
4245
date,
@@ -52,14 +55,18 @@ export const BlogPageTemplate: FC<BlogPageProps> = ({
5255
date={date}
5356
cookieConsentColor={blogPrimaryColor}
5457
/>
55-
<BlogMenu
56-
trackingCategory={trackingCategory}
57-
pathname={location.pathname}
58-
/>
59-
<ContentContainer>
58+
{!pageOpenedInApp && (
59+
<BlogMenu
60+
trackingCategory={trackingCategory}
61+
pathname={location.pathname}
62+
/>
63+
)}
64+
<ContentContainer pageOpenedFromApp={pageOpenedInApp}>
6065
<DesktopBlogHeader big={big} />
6166
{children}
6267
</ContentContainer>
63-
<Footer author={author} trackingCategory={trackingCategory} />
68+
{!pageOpenedInApp && (
69+
<Footer author={author} trackingCategory={trackingCategory} />
70+
)}
6471
</BlogThemePage>
6572
);

src/logic/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { WindowLocation } from "@reach/router";
2+
3+
export const pageOpenedInApp = (
4+
location: WindowLocation<WindowLocation["state"]>,
5+
): boolean => {
6+
const appParam = new URLSearchParams(location.search).get("app");
7+
return appParam !== null && appParam === "true";
8+
};

src/logic/current-location.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface CurrentLocation {
66
}
77

88
export const getCurrentLocationFrom: (
9-
location: WindowLocation<WindowLocation["state"]>
9+
location: WindowLocation<WindowLocation["state"]>,
1010
) => CurrentLocation = (location: WindowLocation<WindowLocation["state"]>) => ({
1111
url: location.href,
1212
pathname: location.pathname,

src/templates/post.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ import styled from "styled-components";
1111
import { OgPageType } from "../logic/seo";
1212
import { getCurrentLocationFrom } from "../logic/current-location";
1313
import loadable from "@loadable/component";
14+
import { pageOpenedInApp } from "../logic/app";
1415

1516
const PostTitle = styled(Heading2)`
1617
margin: 0;
1718
word-wrap: break-word;
1819
`;
1920

2021
const RecentPosts = loadable(
21-
() => import(`../components/design-system/organism/read-next`)
22+
() => import(`../components/design-system/organism/read-next`),
2223
);
2324

2425
const PostTags = loadable(
25-
() => import(`../components/design-system/molecules/post-tags`)
26+
() => import(`../components/design-system/molecules/post-tags`),
2627
);
2728

2829
const Comments = loadable(
29-
() => import(`../components/design-system/molecules/comments`)
30+
() => import(`../components/design-system/molecules/comments`),
3031
);
3132

3233
const PostContainer = styled.div`
@@ -47,12 +48,13 @@ const Post: FC<PageProps<Queries.PostQuery>> = ({ data, location }) => {
4748
author={data.site!.siteMetadata!.author!}
4849
ogPageType={OgPageType.BlogPosting}
4950
ogImage={`${getSrc(
50-
post.frontmatter!.image!.childImageSharp!.gatsbyImageData!
51+
post.frontmatter!.image!.childImageSharp!.gatsbyImageData!,
5152
)!}`}
5253
trackingCategory={tracking.category.blog_post}
5354
customTitle={title}
5455
description={post.frontmatter!.description!}
5556
date={post.frontmatter!.date!}
57+
pageOpenedInApp={pageOpenedInApp(location)}
5658
>
5759
<PostContainer>
5860
<PostTitle className="blog-post-title">
@@ -75,9 +77,13 @@ const Post: FC<PageProps<Queries.PostQuery>> = ({ data, location }) => {
7577
trackingLabel={tracking.label.body}
7678
/>
7779
</PostContainer>
78-
<RecentPosts currentSlug={location.pathname} />
79-
{post.frontmatter?.comments && (
80-
<Comments url={location.href} title={title} />
80+
{!pageOpenedInApp(location) && (
81+
<>
82+
<RecentPosts currentSlug={location.pathname} />
83+
{post.frontmatter?.comments && (
84+
<Comments url={location.href} title={title} />
85+
)}
86+
</>
8187
)}
8288
</BlogPageTemplate>
8389
);

0 commit comments

Comments
 (0)