Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 2 additions & 8 deletions frontend/scripts/check-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Language,
LanguageObject,
LanguageObjectSchema,
LanguageSchema,
} from "@monkeytype/schemas/languages";
import { Layout, ThemeName } from "@monkeytype/schemas/configs";
import { LayoutsList } from "../src/ts/constants/layouts";
Expand Down Expand Up @@ -154,7 +153,7 @@ async function validateQuotes(): Promise<void> {

const shortQuotes = JSON.parse(
fs.readFileSync("./scripts/short-quotes.json", "utf8"),
) as Partial<Record<QuoteData["language"], number[]>>;
) as Record<QuoteData["language"], number[]>;

const quotesFiles = fs.readdirSync("./static/quotes/");
for (let quotefilename of quotesFiles) {
Expand Down Expand Up @@ -185,12 +184,7 @@ async function validateQuotes(): Promise<void> {
}

//check schema
const schema = QuoteDataSchema.extend({
language: LanguageSchema
//icelandic only exists as icelandic_1k, language in quote file is stripped of its size
.or(z.literal("icelandic")),
});
problems.addValidation(quotefilename, schema.safeParse(quoteData));
problems.addValidation(quotefilename, QuoteDataSchema.safeParse(quoteData));

//check for duplicate ids
const duplicates = findDuplicates(quoteData.quotes.map((it) => it.id));
Expand Down
36 changes: 24 additions & 12 deletions frontend/scripts/get-short-quotes.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import * as fs from "fs";
import { QuoteData } from "@monkeytype/schemas/quotes";
import * as fs from "fs";

import path, { dirname } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const FRONTEND_ROOT = path.resolve(__dirname, "..");

async function getShortQuotes(): Promise<void> {
let shortQuotes: Partial<Record<QuoteData["language"], number[]>> = {};
const shortQuotes = {} as Record<QuoteData["language"], number[]>;
let count = 0;
const quotesFiles = fs.readdirSync("./static/quotes/");
const quotesFiles = fs.readdirSync(
path.resolve(FRONTEND_ROOT, "static/quotes"),
);
for (const quotefilename of quotesFiles) {
const lang = quotefilename.split(".")[0] as QuoteData["language"];
let quoteData: QuoteData;
let quoteJson: string;
quoteJson = fs.readFileSync(`./static/quotes/${lang}.json`, "utf8");
//quoteJson = await (await fetch(`https://raw.githubusercontent.com/monkeytypegame/monkeytype/refs/heads/master/frontend/static/quotes/${lang}.json`)).json();
quoteData = JSON.parse(quoteJson) as QuoteData;
const quoteJson = fs.readFileSync(
path.resolve(FRONTEND_ROOT, `static/quotes/${quotefilename}`),
"utf8",
);
//const quoteJson = await (await fetch(`https://raw.githubusercontent.com/monkeytypegame/monkeytype/refs/heads/master/frontend/static/quotes/${quotefilename}`)).json();
const quoteData = JSON.parse(quoteJson) as QuoteData;
for (const quote of quoteData.quotes) {
if (quote.length < 60) {
shortQuotes[lang] ??= [];
shortQuotes[lang].push(quote.id);
shortQuotes[quoteData.language] ??= [];
shortQuotes[quoteData.language].push(quote.id);
count++;
}
}
}
fs.writeFileSync("./scripts/short-quotes.json", JSON.stringify(shortQuotes));
fs.writeFileSync(
path.resolve(__dirname, "short-quotes.json"),
JSON.stringify(shortQuotes),
);
console.log(`There are ${count} allowed short quotes`);
}

Expand Down
Loading