1 Commits

Author SHA1 Message Date
6d21b8958b clean up email address markdown 2025-08-02 10:48:41 -05:00
3 changed files with 18 additions and 2 deletions

7
package-lock.json generated
View File

@@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"country-code-lookup": "0.1.3",
"email-addresses": "5.0.0",
"extract-tld": "1.1.2"
},
"bin": {
@@ -36,6 +37,12 @@
"integrity": "sha512-gLu+AQKHUnkSQNTxShKgi/4tYd0vEEait3JMrLNZgYlmIZ9DJLkHUjzXE9qcs7dy3xY/kUx2/nOxZ0Z3D9JE+A==",
"license": "MIT"
},
"node_modules/email-addresses": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/email-addresses/-/email-addresses-5.0.0.tgz",
"integrity": "sha512-4OIPYlA6JXqtVn8zpHpGiI7vE6EQOAg16aGnDMIAlZVinnoZ8208tW1hAbjWydgN/4PLTT9q+O1K6AH/vALJGw==",
"license": "MIT"
},
"node_modules/extract-tld": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/extract-tld/-/extract-tld-1.1.2.tgz",

View File

@@ -32,6 +32,7 @@
],
"dependencies": {
"country-code-lookup": "0.1.3",
"email-addresses": "5.0.0",
"extract-tld": "1.1.2"
},
"devDependencies": {

View File

@@ -1,6 +1,7 @@
import path from 'path';
import fsp from 'fs/promises';
import parseUrl from 'extract-tld';
import addrs from "email-addresses";
import { resolveCountry } from './resolveCountry.js';
import MirrorsByRegion from './mirrorsByRegion.js';
import type { PathLike } from 'fs';
@@ -219,6 +220,13 @@ async function generateMirrorMd(): Promise<string> {
function findFirstWithChild<T, K extends keyof T>(profiles: T[], key: K): T[K] | undefined {
return profiles.find(p => !!p[key])?.[key];
}
function printEmail(email: string | undefined) {
if (!email) {
return email;
}
const addr = addrs.parseOneAddress(email)?.['address'];
return `[${email.replaceAll('<', '&lt;').replaceAll('>', '&gt;')}](mailto:${addr})`;
}
const lines: string[] = await tryReadHeader();
lines.push('# Mirrors\n\nContact or other information for the mirrors of our repositories and ISOs.\n');
for (let mirrorName in mirrorProfilesByMirrorName) {
@@ -242,8 +250,8 @@ async function generateMirrorMd(): Promise<string> {
// pushTableRowIfTruthy(lines, 'Frequency', findFirstWithChild(activeProfiles, 'frequency'));
// pushTableRowIfTruthy(lines, 'Hosted by', findFirstWithChild(activeProfiles, 'org'));
pushTableRowIfTruthy(lines, 'Location', findFirstWithChild(activeProfiles, 'country') || findFirstWithChild(profiles, 'country'));
pushTableRowIfTruthy(lines, 'Contact Details', findFirstWithChild(activeProfiles, 'admin_email') || findFirstWithChild(profiles, 'admin_email'));
pushTableRowIfTruthy(lines, 'Altenate Contact Details', findFirstWithChild(activeProfiles, 'alternate_email') || findFirstWithChild(profiles, 'alternate_email'));
pushTableRowIfTruthy(lines, 'Contact Details', printEmail(findFirstWithChild(activeProfiles, 'admin_email') || findFirstWithChild(profiles, 'admin_email')));
pushTableRowIfTruthy(lines, 'Altenate Contact Details', printEmail(findFirstWithChild(activeProfiles, 'alternate_email') || findFirstWithChild(profiles, 'alternate_email')));
lines.push('');
}
return lines.join('\n');