Skip to content

Commit bff2f37

Browse files
authored
EthicalAds: don't show ad on 404 pages (#430)
It seems the `isEnabled` method wasn't updated to accept the `httpStatus` and that's why it wasn't working fine. Now, the Ad won't be shown on pages like this one: https://sphinx-rtd-theme.readthedocs.io/en/stable/notfound Related #385 Closes #386
1 parent 23a7f43 commit bff2f37

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

dist/readthedocs-addons.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/readthedocs-addons.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ethicalads.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ export class EthicalAdsAddon extends AddonBase {
343343
this.loadEthicalAdLibrary();
344344
}
345345

346-
static isEnabled(config) {
346+
static isEnabled(config, httpStatus) {
347347
return (
348-
super.isEnabled(config) && config.addons.ethicalads.ad_free === false
348+
super.isEnabled(config, httpStatus) &&
349+
config.addons.ethicalads.ad_free === false
349350
);
350351
}
351352
}

tests/ethicalads.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,23 @@ describe("EthicalAds addon", () => {
6161
}),
6262
).to.be.false;
6363
});
64+
65+
it("is disabled on 404 pages", () => {
66+
expect(
67+
EthicalAdsAddon.isEnabled(
68+
{
69+
addons: {
70+
ethicalads: {
71+
enabled: true,
72+
ad_free: false,
73+
campaign_types: ["community", "paid"],
74+
keywords: ["docs", "data-science"],
75+
publisher: "readthedocs",
76+
},
77+
},
78+
},
79+
404,
80+
),
81+
).to.be.false;
82+
});
6483
});

0 commit comments

Comments
 (0)