From: Charlie Fish Date: Tue, 6 Jul 2021 01:10:09 +0000 (-0600) Subject: Adding generate-adguard script X-Git-Tag: aggregated-20250518~478^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8df3ed606467697d4fe1a154a2f4749e774fa893;p=thirdparty%2Fblocklistproject%2Flists.git Adding generate-adguard script --- diff --git a/.github/workflows/run-automations.yml b/.github/workflows/run-automations.yml index 0941aca..78a49b9 100644 --- a/.github/workflows/run-automations.yml +++ b/.github/workflows/run-automations.yml @@ -18,6 +18,7 @@ jobs: - run: node scripts/update-number-of-domains.js - run: node scripts/generate-noip.js - run: node scripts/generate-dnsmasq.js + - run: node scripts/generate-adguard.js - name: Commit & Push uses: actions-x/commit@v2 with: diff --git a/scripts/generate-adguard.js b/scripts/generate-adguard.js new file mode 100644 index 0000000..6bf7bce --- /dev/null +++ b/scripts/generate-adguard.js @@ -0,0 +1,15 @@ +const fs = require("fs").promises; +const path = require("path"); + +(async () => { + const files = (await fs.readdir(path.join(__dirname, ".."))).filter((file) => file.endsWith(".txt")); // Array of strings, each representing a single file that ends in `.txt` + await Promise.all(files.map(async (file) => { // For each file + const fileContents = await fs.readFile(path.join(__dirname, "..", file), "utf8"); // Get file contents as a string + const adGuardFileContents = fileContents + .replace(/^# Title: (.*?)$/gmu, "# Title: $1 (adguard)") // Add (adguard) to end of title + .replaceAll(/^# 0\.0\.0\.0 (.*?) (.*)/gmu, "@@||$1^! $2") + .replaceAll(/0\.0\.0\.0 (.*?)$/gmu, "||$1^") + .replaceAll(/^#/gmu, "!"); + await fs.writeFile(path.join(__dirname, "..", "adguard", file.replace(".txt", "-ags.txt")), adGuardFileContents, "utf8"); // Write new file to `adguard` directory + })); +})();