Skip to content

Commit 7415646

Browse files
authored
update ads location (#1168)
* update ads location * update prettier * update format
1 parent bdcceec commit 7415646

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

src/components/CarbonAds.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use client"
2+
import { useEffect, useRef } from "react"
3+
4+
export const CARBON_SCRIPT_ID = "_carbonads_js"
5+
const CARBON_SCRIPT_SRC =
6+
"https://cdn.carbonads.com/carbon.js?serve=CW7DTKQ7&placement=react-hook-formcom&format=cover"
7+
8+
export function CarbonAds({ id }: { id: string }) {
9+
const containerRef = useRef<HTMLDivElement>(null)
10+
11+
useEffect(() => {
12+
function injectScript() {
13+
if (document.getElementById(id)) return
14+
15+
const script = document.createElement("script")
16+
script.id = id
17+
script.async = true
18+
script.src = CARBON_SCRIPT_SRC
19+
script.type = "text/javascript"
20+
21+
if (containerRef.current) {
22+
containerRef.current.appendChild(script)
23+
}
24+
}
25+
26+
if (document.readyState === "complete") {
27+
injectScript()
28+
} else {
29+
window.addEventListener("load", injectScript)
30+
31+
return () => window.removeEventListener("load", injectScript)
32+
}
33+
34+
return
35+
}, [id])
36+
37+
return <div className="carbonAdsContainer" ref={containerRef} />
38+
}

src/components/Menu/Menu.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styles from "./SideMenu.module.css"
44
import typographyStyles from "../../styles/typography.module.css"
55
import { useRouter } from "next/router"
66
import { Pages } from "../../types/types"
7+
import { CARBON_SCRIPT_ID, CarbonAds } from "@/components/CarbonAds"
78

89
function Menu({ pages = [] }: { pages: Pages }) {
910
const router = useRouter()
@@ -70,8 +71,9 @@ function Menu({ pages = [] }: { pages: Pages }) {
7071
)
7172
})}
7273
</ul>
73-
74-
<div id="carbon-cover" />
74+
<div className={styles.ads}>
75+
<CarbonAds id={CARBON_SCRIPT_ID} />
76+
</div>
7577
</div>
7678
</aside>
7779
)

src/components/Menu/SideMenu.module.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
max-width: 230px;
3939
padding: 0;
4040
overflow-y: auto;
41-
height: calc(100vh - 190px);
41+
height: calc(100vh - 600px);
4242
overflow-y: auto;
4343
}
4444

@@ -49,6 +49,10 @@
4949
display: flex;
5050
}
5151

52+
.menu > div > ul > li:last-child {
53+
padding-bottom: 0;
54+
}
55+
5256
.menu > div > ul > li > a {
5357
text-decoration: none;
5458
padding-left: 6px;
@@ -118,6 +122,7 @@
118122
.menu > div > ul {
119123
margin-top: 0;
120124
max-width: 260px;
125+
height: calc(100vh - 450px);
121126
}
122127

123128
.menu > ul {
@@ -204,3 +209,8 @@
204209
.menu ul li a.isActive {
205210
border-bottom: 1px solid var(--color-secondary);
206211
}
212+
213+
.ads {
214+
position: absolute;
215+
height: 500px;
216+
}

src/components/layout.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,3 @@ pre[class*="language-"] {
945945
height: auto;
946946
}
947947
}
948-
949-
#carbon-responsive {
950-
margin: 0 auto 50px;
951-
}
952-
953-
#carbon-cover {
954-
margin: 0 auto 50px;
955-
}

src/pages/_document.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ export default function Document() {
1313
strategy="afterInteractive"
1414
src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"
1515
/>
16-
<Script
17-
async
18-
strategy="afterInteractive"
19-
src="https://cdn.carbonads.com/carbon.js?serve=CW7DTKQ7&placement=react-hook-formcom&format=cover"
20-
id="_carbonads_js"
21-
/>
2216
<link
2317
rel="shortcut icon"
2418
href="/images/logo/react-hook-form-logo-only.png"

0 commit comments

Comments
 (0)