Skip to content

Commit

Permalink
Add ad to post's layout
Browse files Browse the repository at this point in the history
  • Loading branch information
phuocng committed Sep 26, 2021
1 parent 90eeed0 commit 3794d06
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
16 changes: 16 additions & 0 deletions components/Ad.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';

export const Ad = () => {
const containerRef = React.useRef<HTMLDivElement>();

React.useEffect(() => {
const script = document.createElement('script');
script.async = true;
script.setAttribute('id', '_carbonads_js');
script.src = 'https://cdn.carbonads.com/carbon.js?serve=CE7I6KQI&placement=htmldomdev';

containerRef.current.appendChild(script);
}, []);

return <div ref={containerRef} />;
};
12 changes: 0 additions & 12 deletions css/demo.css

This file was deleted.

6 changes: 6 additions & 0 deletions layouts/PostLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Head from 'next/head';
import * as React from 'react';
import { Layout } from './Layout';

import { Ad } from '../components/Ad';

export const PostLayout: React.FC<{
keywords?: string;
title: string;
Expand All @@ -23,6 +25,10 @@ export const PostLayout: React.FC<{
<Spacer size="extraLarge" />
<Heading level={1}>{title}</Heading>
<Spacer size="large" />
<div className="block-ad">
<Ad />
</div>
<Spacer size="medium" />
</div>
{children}
<Spacer size="large" />
Expand Down
11 changes: 11 additions & 0 deletions public/css/demo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
font-family: 'Inter', sans-serif;
line-height: 1.5;
margin: 0;
}
* {
box-sizing: border-box;
}
a {
text-decoration: none;
}
22 changes: 22 additions & 0 deletions styles/blocks/_ad.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.block-ad {
background: #e6e6e6;
border-radius: 0.25rem;
padding: 1rem;
margin: 0 auto;
max-width: 15rem;
}

/* Ads */
.carbon-img {
display: block;
text-align: center;
}
.carbon-poweredby {
display: block;
font-size: 0.75rem;
text-align: right;
}
.carbon-text {
display: block;
font-size: 0.875rem;
}
1 change: 1 addition & 0 deletions styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './reset';

// Blocks
@import 'blocks/ad';
@import 'blocks/demo';
@import 'blocks/footer';
@import 'blocks/header';
Expand Down

0 comments on commit 3794d06

Please sign in to comment.