diff --git a/package.json b/package.json index 4c2b43c8a..d330e4ff3 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,9 @@ "devDependencies": { "@babel/core": "^7.20.12", "@polkadot/dev": "^0.67.184", - "@types/jest": "^29.2.6" + "@types/jest": "^29.2.6", + "mkdirp": "^2.1.3", + "rimraf": "^4.1.1" }, "resolutions": { "typescript": "^4.9.4" diff --git a/scripts/sortAll.mjs b/scripts/sortAll.mjs index 809b1d832..6350a6b72 100644 --- a/scripts/sortAll.mjs +++ b/scripts/sortAll.mjs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import fs from 'fs'; +import mkdirp from 'mkdirp'; +import rimraf from 'rimraf'; const KNOWN_URLS = ['telegra.ph', 'twitter.com', 'youtube.com']; @@ -137,14 +139,37 @@ export function writeMeta (meta) { writeJson('meta/index.json', index.sort((a, b) => b.localeCompare(a))); } +function writeAllList (deny) { + rimraf.sync('all'); + mkdirp.sync('all'); + + const avail = deny.reduce((avail, url) => { + const firstChar = url[0]; + + if (!avail[firstChar]) { + avail[firstChar] = [url]; + } else { + avail[firstChar].push(url); + } + + return avail; + }, {}); + + Object.entries(avail).forEach(([key, urls]) => writeJson(`all/${key}.json`, urls)); +} + const addr = readJson('address.json'); const all = readJson('all.json'); const meta = readMeta(); const deny = sortSection(addSites(all, addr)); +const allJson = { allow: sortSection(all.allow), deny: rewriteSubs(deny) }; // rewrite with all our entries (newline included) writeJson('address.json', sortAddresses(addr)); -writeJson('all.json', { allow: sortSection(all.allow), deny: rewriteSubs(deny) }); +writeJson('all.json', allJson); + +// add the specific alphabetical list +writeAllList(allJson.deny); // find out what we don't have const urls = meta.map(({ url }) => url); diff --git a/yarn.lock b/yarn.lock index 3cc9c5843..5942a9ba9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10659,6 +10659,8 @@ __metadata: "@polkadot/dev": ^0.67.184 "@types/jest": ^29.2.6 dnslink-cloudflare: ^3.0.0 + mkdirp: ^2.1.3 + rimraf: ^4.1.1 languageName: unknown linkType: soft