Skip to content

Commit b9e3485

Browse files
committed
fix(ads): smaller
1 parent 47ccbaf commit b9e3485

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/theme/DocSidebar/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ export default function DocSidebar(props) {
3636
carbonWrapper.classList.add(styles.carbonWrapper);
3737

3838
carbonWrapper.appendChild(script);
39-
// append at the end
4039
sidebarWrapper.firstChild.insertBefore(carbonWrapper, null);
4140

41+
// If Carbon doesn't serve an ad, reclaim the space.
42+
const checkTimer = setTimeout(() => {
43+
if (!carbonWrapper.querySelector("#carbonads")) {
44+
sidebarWrapper.classList.add(styles.roomForCarbon);
45+
carbonWrapper.parentElement.removeChild(carbonWrapper);
46+
}
47+
}, 3000);
48+
4249
return () => {
50+
clearTimeout(checkTimer);
4351
sidebarWrapper.classList.add(styles.roomForCarbon);
44-
carbonWrapper.parentElement.removeChild(carbonWrapper);
52+
if (carbonWrapper.parentElement) {
53+
carbonWrapper.parentElement.removeChild(carbonWrapper);
54+
}
4555
};
4656
}, [pathname, windowSize]);
4757

src/theme/DocSidebar/styles.module.css

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,75 @@
11
/* avoids layout shift before Carbon gets a chance to initialize */
22
.roomForCarbon > :first-child > :first-child {
3-
height: calc(100% - 190px) !important;
3+
height: calc(100% - 130px) !important;
44
flex-grow: initial;
55
}
66

7+
/* Fade at the bottom of the scrollable menu so items dissolve before the ad */
8+
.roomForCarbon > :first-child > :first-child {
9+
position: relative;
10+
-webkit-mask-image: linear-gradient(
11+
to bottom,
12+
black calc(100% - 28px),
13+
transparent 100%
14+
);
15+
mask-image: linear-gradient(
16+
to bottom,
17+
black calc(100% - 28px),
18+
transparent 100%
19+
);
20+
}
21+
722
.carbonWrapper {
823
flex-shrink: 0;
9-
min-height: 190px;
10-
padding: 20px 15px 15px 15px; /* 20px gap at the top! */
24+
min-height: 130px;
25+
padding: 0 15px 15px 15px;
1126
overflow: hidden;
1227
display: flex;
13-
justify-content: center; /* Centers the ad horizontally */
28+
justify-content: center;
1429
align-items: flex-end;
1530
}
1631

1732
:global(#carbonads) {
1833
display: block;
1934
background-color: var(--ifm-background-surface-color);
20-
border: 1px solid var(--ifm-border-color); /* Soft outline */
21-
border-radius: 8px; /* Matches the modern feel */
35+
border: 1px solid var(--ifm-border-color);
36+
border-radius: 8px;
2237
padding: 10px;
2338
position: relative;
24-
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.03); /* Barely-there shadow */
39+
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.03);
2540
transition: all 0.2s ease;
2641
font-size: 0.9em;
2742
}
2843

2944
:global(#carbonads:hover) {
30-
border-color: rgba(99, 102, 241, 0.3); /* Subtle Indigo tint on hover */
45+
border-color: rgba(99, 102, 241, 0.3);
3146
box-shadow: 0 4px 10px -2px rgba(99, 102, 241, 0.1);
3247
}
3348

3449
:global(#carbonads .carbon-wrap) {
3550
display: flex;
3651
flex-direction: column;
52+
align-items: center;
3753
gap: 8px;
3854
}
3955

4056
:global(#carbonads .carbon-wrap img) {
41-
width: 100%;
57+
width: 130px;
4258
height: auto;
4359
border-radius: 4px;
4460
}
4561

4662
:global(#carbonads .carbon-text) {
4763
padding: 0;
48-
font-size: 12px;
64+
font-size: 11px;
4965
line-height: 1.4;
5066
color: var(--ifm-color-content-secondary);
5167
}
5268

5369
:global(#carbonads .carbon-poweredby) {
5470
display: block;
55-
text-align: right; /* Keeps it neatly tucked to the right */
56-
57-
/* Creates a hard, guaranteed gap between the ad text and the link */
58-
margin-top: 8px;
59-
71+
text-align: right;
72+
margin-top: 6px;
6073
font-size: 8px;
6174
font-weight: 700;
6275
line-height: 1;

0 commit comments

Comments
 (0)