Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Remove build-time tags generation
Browse files Browse the repository at this point in the history
  • Loading branch information
brawaru committed Aug 22, 2023
1 parent 91bea62 commit 0225e8c
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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 ([email protected])',
},
}

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'),
Expand Down

0 comments on commit 0225e8c

Please sign in to comment.