diff --git a/build/modules/api_interface.ts b/build/modules/api_interface.ts index 8623ce1..a37d99b 100644 --- a/build/modules/api_interface.ts +++ b/build/modules/api_interface.ts @@ -27,8 +27,10 @@ class ApiInterface { } async _get(url: string): Promise { - console.log(chalk.blue("GET"), url) - return this.limiter.schedule(() => ky.get(url)) + return this.limiter.schedule(() => { + console.log(chalk.blue("GET"), url) + return ky.get(url) + }) } async getRaw(endpoint: string): Promise { @@ -47,7 +49,6 @@ class ApiInterface { const cachePath = `build/cache/${endpoint}.html` if (await fileExists(cachePath)) { - console.log(chalk.yellow("Using cached index for"), endpoint) const contents = await fs.readFile(cachePath) return contents.toString() } @@ -67,7 +68,6 @@ class ApiInterface { const cachePath = `build/cache/${cacheEndpoint}.json` if (await fileExists(cachePath)) { - console.log(chalk.yellow("Using cached index for"), cacheEndpoint) const contents = await fs.readFile(cachePath) try { return JSON.parse(contents.toString()) diff --git a/build/modules/pages.ts b/build/modules/pages.ts index a5aeda5..938d46e 100644 --- a/build/modules/pages.ts +++ b/build/modules/pages.ts @@ -34,12 +34,12 @@ async function buildPage(api: ApiInterface, contentManager: StaticContentHandler } const struct: PageResponse = await api.getJSON(`/gmod/${link}`) - console.log(chalk.green("Building"), link) + // console.log(chalk.green("Building"), link) let pageContent = await contentManager.processContent(struct.html, false) pageContent = pageContent.replace(/<\/head>/g, "") pageContent = pageContent.replace(/<\/body><\/html>/g, "") - pageContent = struct.html.replace(/https:\/\/wiki\.facepunch\.com\/gmod\//g, "/") + pageContent = pageContent.replace(/https:\/\/wiki\.facepunch\.com\/gmod\//g, "/") pageContent = pageContent.replaceAll(/\/gmod\//g, "/") delete struct.wikiName diff --git a/build/modules/static.ts b/build/modules/static.ts index ff34d2b..8cb5d9a 100644 --- a/build/modules/static.ts +++ b/build/modules/static.ts @@ -1,6 +1,7 @@ // Finds, acquires, writes, and stubs any static content found in a given html file import path from "path" import sharp from "sharp" +import chalk from "chalk" import * as cheerio from "cheerio" import { promises as fs } from "fs" import type ApiInterface from "./api_interface.js" @@ -80,8 +81,8 @@ class StaticContentHandler { // We replace all images with webp if (isImage.has(fileExtension)) { - filePath = filePath.replace(fileExtension, ".webp") - newURL = newURL.replace(fileExtension, ".webp") + filePath = filePath.replaceAll(fileExtension, ".webp") + newURL = newURL.replaceAll(fileExtension, ".webp") } if (fileExtension !== ".css" && await fileExists(filePath)) { @@ -93,6 +94,7 @@ class StaticContentHandler { let data = await this.api.getRawFull(resolvedUrl) if (isImage.has(fileExtension)) { + console.log(chalk.green("Optimizing"), resolvedUrl) data = await this.optimizeImage(data) } @@ -166,7 +168,11 @@ class StaticContentHandler { } public async processContent(content: string, isCss: boolean = false): Promise { - return isCss ? this.processCss(content) : this.processHtml(content) + if (isCss) { + return await this.processCss(content) + } else { + return await this.processHtml(content) + } } }