Skip to content

Commit

Permalink
EthicalAds: don't show ad on 404 pages (#430)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
humitos authored Nov 12, 2024
1 parent 23a7f43 commit bff2f37
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dist/readthedocs-addons.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/readthedocs-addons.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/ethicalads.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ export class EthicalAdsAddon extends AddonBase {
this.loadEthicalAdLibrary();
}

static isEnabled(config) {
static isEnabled(config, httpStatus) {
return (
super.isEnabled(config) && config.addons.ethicalads.ad_free === false
super.isEnabled(config, httpStatus) &&
config.addons.ethicalads.ad_free === false
);
}
}
19 changes: 19 additions & 0 deletions tests/ethicalads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,23 @@ describe("EthicalAds addon", () => {
}),
).to.be.false;
});

it("is disabled on 404 pages", () => {
expect(
EthicalAdsAddon.isEnabled(
{
addons: {
ethicalads: {
enabled: true,
ad_free: false,
campaign_types: ["community", "paid"],
keywords: ["docs", "data-science"],
publisher: "readthedocs",
},
},
},
404,
),
).to.be.false;
});
});

0 comments on commit bff2f37

Please sign in to comment.