Skip to content

Commit

Permalink
Fix mirrored images
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon committed Feb 8, 2024
1 parent 63bf8f4 commit 28f88b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions build/modules/api_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class ApiInterface {
}

async _get(url: string): Promise<any> {
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<any> {
Expand All @@ -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()
}
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions build/modules/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<html><head><\/head><body>/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
Expand Down
12 changes: 9 additions & 3 deletions build/modules/static.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -166,7 +168,11 @@ class StaticContentHandler {
}

public async processContent(content: string, isCss: boolean = false): Promise<string> {
return isCss ? this.processCss(content) : this.processHtml(content)
if (isCss) {
return await this.processCss(content)
} else {
return await this.processHtml(content)
}
}
}

Expand Down

0 comments on commit 28f88b7

Please sign in to comment.