Expand ecash explorer capabilities
Add Fedimint discovery, dual SQLite/Postgres storage, richer review handling, and generated social imagery.
This commit is contained in:
@@ -90,3 +90,46 @@ export function clampWords(value: string, max: number): string {
|
||||
const lastSpace = cut.lastIndexOf(' ');
|
||||
return (lastSpace > max * 0.6 ? cut.slice(0, lastSpace) : cut).trimEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* A mint's own description, made fit to open a meta description.
|
||||
*
|
||||
* It is operator-written text headed for a `content` attribute and a link preview, so
|
||||
* everything that does not belong in either comes out: HTML tags and control
|
||||
* characters are stripped, whitespace collapses, and only the first sentence
|
||||
* survives — a meta description quoting three sentences of marketing leaves no room
|
||||
* for the rating and status that make the snippet useful. (Astro does the actual
|
||||
* attribute escaping; this removes what escaping would merely neutralise.)
|
||||
*
|
||||
* Two judgement calls:
|
||||
*
|
||||
* - SHOUTING is normalised to sentence case. A description that is ≥80% capitals
|
||||
* reads as noise in a search result, and the mint's page still shows the original.
|
||||
* - The sentence split requires whitespace after the terminator, so "mint.example.com"
|
||||
* inside a sentence does not end it.
|
||||
*
|
||||
* Returns null when nothing usable is left, and the caller falls back to its own copy.
|
||||
*/
|
||||
export function cleanMintDescription(value: string | null | undefined, max = 70): string | null {
|
||||
if (!value) return null;
|
||||
|
||||
let clean = value
|
||||
.replace(/<[^>]*>/g, ' ')
|
||||
.replace(/[\u0000-\u001f\u007f-\u009f]/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
if (clean === '') return null;
|
||||
|
||||
const sentence = /^.*?[.!?](?=\s|$)/.exec(clean);
|
||||
clean = (sentence?.[0] ?? clean).trim();
|
||||
|
||||
const letters = clean.replace(/[^\p{L}]/gu, '');
|
||||
if (letters.length >= 8 && letters.replace(/\p{Ll}/gu, '').length / letters.length > 0.8) {
|
||||
clean = clean.toLowerCase();
|
||||
clean = clean[0]!.toUpperCase() + clean.slice(1);
|
||||
}
|
||||
|
||||
clean = clampWords(clean, max);
|
||||
if (!/[.!?]$/.test(clean)) clean += '.';
|
||||
return clean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user