Skip to content

Commit ec10316

Browse files
committed
1 parent da292f1 commit ec10316

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎apps/site/components/CarbonAds/Sidebar.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
import classNames from 'classnames';
44

55
import useCarbonAd, { adColors } from '#site/hooks/useCarbonAd';
6+
import useClientContext from '#site/hooks/useClientContext';
67

78
import type { FC } from 'react';
89

910
import styles from './index.module.css';
1011

1112
const CarbonSidebar: FC = () => {
12-
const { ad, ref } = useCarbonAd('CWBI6KJU', '(min-width: 1280px)');
13+
const { frontmatter } = useClientContext();
14+
15+
// Must match where each layout's grid gives the MetaBar a right-hand column
16+
const media =
17+
frontmatter.layout === 'blog-post'
18+
? '(min-width: 896px)'
19+
: '(min-width: 1280px)';
20+
21+
const { ad, ref } = useCarbonAd('CWBI6KJU', media);
1322

1423
if (!ad) {
1524
return null;

‎apps/site/tests/e2e/carbon-ads.spec.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,30 @@ test.describe('Carbon Ads', () => {
9898

9999
expect(requests).toEqual([`/ads/${zones.top}.json`]);
100100
});
101+
102+
test('should request the Sidebar from each layout breakpoint', async ({
103+
page,
104+
}) => {
105+
await page.setViewportSize({ width: 1000, height: 800 });
106+
107+
const requests = await mockAds(page);
108+
109+
// Between `ml` and `xl`, only blog posts have a right-hand column
110+
await page.goto('/en/about');
111+
await expect(adLinks(page)).toHaveCount(1);
112+
113+
expect(requests).toEqual([`/ads/${zones.top}.json`]);
114+
115+
requests.length = 0;
116+
117+
await page.goto(
118+
'/en/blog/announcements/diving-into-the-nodejs-website-redesign'
119+
);
120+
await expect(adLinks(page)).toHaveCount(2);
121+
122+
expect(requests.sort()).toEqual([
123+
`/ads/${zones.sidebar}.json`,
124+
`/ads/${zones.top}.json`,
125+
]);
126+
});
101127
});

‎docs/carbon-ads.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ The Website shows [Carbon Ads](https://www.carbonads.net/) through the OpenJS Fo
77
| Format | Zone key | Where |
88
| ------- | ---------- | ----------------------------------------------------------- |
99
| Banner | `CWBI6KJY` | Full width, above page content, on the layouts listed below |
10-
| Sidebar | `CWBI6KJU` | Below the table of contents, from the `xl` breakpoint |
10+
| Sidebar | `CWBI6KJU` | Below the table of contents, from the breakpoints below |
1111

1212
| Layout | Banner | Sidebar |
1313
| ------------------------ | ------ | ------------------------- |
1414
| `about`, `article` | Yes | From the `xl` breakpoint |
15-
| `blog-post` | Yes | From the `xl` breakpoint |
15+
| `blog-post` | Yes | From the `ml` breakpoint |
1616
| `blog-category` | Yes | No (no right-hand column) |
1717
| `download` | **No** | **No** |
1818
| `download-archive` | **No** | **No** |
@@ -21,7 +21,7 @@ The Website shows [Carbon Ads](https://www.carbonads.net/) through the OpenJS Fo
2121

2222
The homepage never renders any ad markup, reserves no space and makes no ad requests. Layouts opt in explicitly through `<CarbonTopBar />` before their main content. The Sidebar is rendered inside `<MetaBar />` (`apps/site/components/MetaBar.tsx`), so every layout that uses it shows the Sidebar.
2323

24-
On narrower screens the Sidebar is neither shown nor requested (the Top Bar covers those views). Its breakpoint is hard-coded as `(min-width: 1280px)` in `apps/site/components/CarbonAds/Sidebar.tsx` and must match the layout grids. Resizing the window back above the breakpoint requests a new Sidebar ad, which records another impression.
24+
On narrower screens the Sidebar is neither shown nor requested (the Top Bar covers those views). Its breakpoints are hard-coded in `apps/site/components/CarbonAds/Sidebar.tsx`, as `(min-width: 896px)` for `blog-post` and `(min-width: 1280px)` for other layouts, and must match the layout grids. Resizing the window back above the breakpoint requests a new Sidebar ad, which records another impression.
2525

2626
Learn (`/learn`) and the API docs (`/api`, `/docs`) are separate applications and are not affected by this integration.
2727

0 commit comments

Comments
 (0)