diff --git a/nuxt.config.ts b/nuxt.config.ts index d7c2fd7528..d70222cd57 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -3,7 +3,6 @@ import { pathToFileURL } from 'node:url' import svgLoader from 'vite-svg-loader' import { resolve, basename } from 'pathe' import { defineNuxtConfig } from 'nuxt/config' -import { $fetch } from 'ofetch' import { globIterate } from 'glob' import { match as matchLocale } from '@formatjs/intl-localematcher' @@ -112,74 +111,6 @@ export default defineNuxtConfig({ ], }, hooks: { - async 'build:before'() { - // 30 minutes - const TTL = 30 * 60 * 1000 - - let state: { - lastGenerated?: string - apiUrl?: string - categories?: any[] - loaders?: any[] - gameVersions?: any[] - donationPlatforms?: any[] - reportTypes?: any[] - } = {} - let homePageProjects: any[] = [] - - try { - state = JSON.parse(await fs.readFile('./generated/state.json', 'utf8')) - homePageProjects = JSON.parse(await fs.readFile('./generated/homepage.json', 'utf8')) - } catch { - // File doesn't exist, create folder - await fs.mkdir('./generated', { recursive: true }) - } - - const API_URL = getApiUrl() - - if ( - // Skip regeneration if within TTL... - state.lastGenerated && - new Date(state.lastGenerated).getTime() + TTL > new Date().getTime() && - // ...but only if the API URL is the same - state.apiUrl === API_URL && - homePageProjects.length !== 0 - ) { - return - } - - state.lastGenerated = new Date().toISOString() - - state.apiUrl = API_URL - - const headers = { - headers: { - 'user-agent': 'Knossos generator (support@modrinth.com)', - }, - } - - const [categories, loaders, gameVersions, donationPlatforms, reportTypes, projects] = - await Promise.all([ - $fetch(`${API_URL}tag/category`, headers), - $fetch(`${API_URL}tag/loader`, headers), - $fetch(`${API_URL}tag/game_version`, headers), - $fetch(`${API_URL}tag/donation_platform`, headers), - $fetch(`${API_URL}tag/report_type`, headers), - $fetch(`${API_URL}projects_random?count=40`, headers), - ]) - - state.categories = categories - state.loaders = loaders - state.gameVersions = gameVersions - state.donationPlatforms = donationPlatforms - state.reportTypes = reportTypes - homePageProjects = projects - - await fs.writeFile('./generated/state.json', JSON.stringify(state)) - await fs.writeFile('./generated/homepage.json', JSON.stringify(homePageProjects)) - - console.log('Tags generated!') - }, 'pages:extend'(routes) { routes.splice( routes.findIndex((x) => x.name === 'search-searchProjectType'),