-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddAdsTxt.js
More file actions
19 lines (18 loc) · 641 Bytes
/
addAdsTxt.js
File metadata and controls
19 lines (18 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const fs = require("fs");
const path = require("path");
/**
* add ads.txt
* https://support.google.com/adsense/answer/7532444
* @param {*} ctx
* @param {string} adClient
*/
module.exports = (ctx, adClient) => {
const filePath = path.resolve(ctx.outDir, "ads.txt");
const pubId = adClient.startsWith("ca-") ? adClient.slice(3) : adClient;
const adsTxtContent = `google.com, ${pubId}, DIRECT, f08c47fec0942fa0`;
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, adsTxtContent);
} else if (!fs.readFileSync(filePath, "utf-8").includes(adsTxtContent)) {
fs.appendFileSync(filePath, "\n" + adsTxtContent);
}
};