Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions frontend/scripts/check-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ async function validateLayouts(): Promise<void> {
}
}

async function fetchQuotes(language: string): Promise<QuoteData | null> {
const url = `https://raw.githubusercontent.com/monkeytypegame/monkeytype/refs/heads/master/frontend/static/quotes/${language}.json`;

try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}

const quoteJsonData = (await response.json()) as QuoteData;
return quoteJsonData;
} catch (error) {
console.error(
`Failed to get quotes: ${error instanceof Error ? error.message : String(error)}`,
);
return null;
}
}

async function validateQuotes(): Promise<void> {
const problems = new Problems<string, never>("Quotes", {});

Expand Down Expand Up @@ -197,6 +216,19 @@ async function validateQuotes(): Promise<void> {
);
}

// check if pr added quotes in this language
let addedQuotesToThisLanguage = false;
const currentLanguageData = await fetchQuotes(quotefilename);

if (
currentLanguageData !== null &&
(currentLanguageData.quotes.length < quoteData.quotes.length ||
JSON.stringify(currentLanguageData.quotes) !==
JSON.stringify(quoteData.quotes))
) {
addedQuotesToThisLanguage = true;
}

//check quote length
quoteData.quotes.forEach((quote) => {
if (quote.text.length !== quote.length) {
Expand All @@ -206,12 +238,19 @@ async function validateQuotes(): Promise<void> {
);
}

if (quote.text.length < 60) {
// TODO: too many quotes trigger this
// problems.add(
// quotefilename,
// `ID ${quote.id}: length too short (under 60 characters)`,
// );
if (
addedQuotesToThisLanguage &&
currentLanguageData !== null &&
!currentLanguageData.quotes.some(
(langQuote) => langQuote.text === quote.text,
)
) {
if (quote.text.length < 60) {
problems.add(
quotefilename,
`ID ${quote.id}: length too short (under 60 characters)`,
);
}
}
});

Expand Down