Skip to content

Commit 676a926

Browse files
sayzlimAndarist
andauthored
Added Carbon Ads to sidebar (#2463)
* Added Carbon Ads to sidebar * Move Carbon styles to Emotion Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent 4c7b6de commit 676a926

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

site/src/components/Carbon.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import React from 'react'
2+
import { Global, css } from '@emotion/react'
3+
4+
function buildScript(src, attrs = {}) {
5+
const script = document.createElement('script')
6+
script.async = true
7+
Object.keys(attrs).forEach(attr => script.setAttribute(attr, attrs[attr]))
8+
script.src = src
9+
10+
return script
11+
}
12+
13+
export default function CarbonAds() {
14+
const ref = React.useRef()
15+
16+
React.useEffect(() => {
17+
const script = buildScript(
18+
'//cdn.carbonads.com/carbon.js?serve=CESDV5QY&placement=emotionsh',
19+
{
20+
type: 'text/javascript',
21+
id: '_carbonads_js'
22+
}
23+
)
24+
25+
ref.current.appendChild(script)
26+
}, [])
27+
28+
return (
29+
<>
30+
<Global
31+
styles={css`
32+
#carbonads {
33+
display: block;
34+
35+
overflow: hidden;
36+
margin-bottom: 2em;
37+
}
38+
39+
#carbonads a,
40+
#carbonads a:hover {
41+
color: inherit;
42+
text-decoration: none;
43+
}
44+
45+
#carbonads span {
46+
display: block;
47+
48+
overflow: hidden;
49+
}
50+
51+
#carbonads .carbon-img {
52+
display: block;
53+
54+
line-height: 1;
55+
}
56+
57+
#carbonads .carbon-img img {
58+
display: block;
59+
border: solid 1px hsla(0, 0%, 7%, 0.1);
60+
}
61+
62+
#carbonads .carbon-text {
63+
display: block;
64+
margin-top: 0.5em;
65+
66+
font-size: 14px;
67+
line-height: 1.35;
68+
}
69+
70+
#carbonads .carbon-poweredby {
71+
display: block;
72+
margin-top: 0.5em;
73+
74+
font-size: 10px;
75+
font-weight: 600;
76+
line-height: 1;
77+
letter-spacing: 0.1ch;
78+
text-transform: uppercase;
79+
}
80+
81+
@media only screen and (min-width: 320px) and (max-width: 759px) {
82+
#carbonads {
83+
position: relative;
84+
}
85+
86+
#carbonads .carbon-wrap {
87+
display: flex;
88+
flex-direction: row;
89+
}
90+
91+
#carbonads .carbon-text {
92+
padding: 0 12px;
93+
font-size: 16px;
94+
}
95+
96+
#carbonads .carbon-poweredby {
97+
position: absolute;
98+
left: 142px;
99+
bottom: 0;
100+
}
101+
}
102+
`}
103+
/>
104+
<div ref={ref} />
105+
</>
106+
)
107+
}

site/src/components/DocWrapper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { getDocMap, docList } from '../utils/misc'
1515
import DocMetadata from './DocMetadata'
1616
import Search from './Search'
1717

18+
import Carbon from './Carbon'
19+
1820
let space = constants.space
1921
const scaleAnimation = keyframes`
2022
from {
@@ -178,6 +180,7 @@ export default ({
178180
]
179181
})}
180182
>
183+
<Carbon />
181184
<Search />
182185
{docList.map(item => {
183186
return (

0 commit comments

Comments
 (0)