mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Save kind endpoints to sitemap
This commit is contained in:
parent
924aa7c8ab
commit
884dd37f6b
1 changed files with 73 additions and 25 deletions
|
|
@ -28,8 +28,8 @@ import {
|
||||||
writeStorkToml
|
writeStorkToml
|
||||||
} from '~/helpers/stork/toml.js'
|
} from '~/helpers/stork/toml.js'
|
||||||
import {
|
import {
|
||||||
PaginatedList
|
KindList
|
||||||
} from '~/helpers/api/pagination.js'
|
} from '~/helpers/api/kind.js'
|
||||||
import {
|
import {
|
||||||
apiDirectory
|
apiDirectory
|
||||||
} from '~/helpers/api/config.js'
|
} from '~/helpers/api/config.js'
|
||||||
|
|
@ -63,6 +63,10 @@ function normalizeVersion ( rawVersion ) {
|
||||||
|
|
||||||
return semver.coerce(version)
|
return semver.coerce(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BuildLists {
|
class BuildLists {
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
|
|
@ -276,32 +280,63 @@ class BuildLists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
saveKind = async function ( list, kindSlug ) {
|
makeKindLists () {
|
||||||
const apiKindListDirectory = `${ apiDirectory }/kind/${ kindSlug }`
|
const getters = Object.fromEntries( Object.entries( this.lists ).map( ([ listName ]) => {
|
||||||
|
return [
|
||||||
|
// Key
|
||||||
|
listName,
|
||||||
|
() => Array.from( this.lists[ listName ] )
|
||||||
|
]
|
||||||
|
} ) )
|
||||||
|
|
||||||
console.log('\n', `-- Starting kind lists for ${ apiKindListDirectory }`)
|
const kindLists = {}
|
||||||
|
|
||||||
const endpointMethodName = `Finished kind lists for ${ apiKindListDirectory }`
|
for ( const kindSlug in getters ) {
|
||||||
console.time(endpointMethodName)
|
|
||||||
|
|
||||||
|
kindLists[ kindSlug ] = new KindList({
|
||||||
const paginatedList = new PaginatedList({
|
// Get list method
|
||||||
list,
|
list: getters[ kindSlug ],
|
||||||
})
|
kindSlug
|
||||||
|
})
|
||||||
// Ensure the directory exists
|
}
|
||||||
await fs.ensureDir( apiKindListDirectory )
|
|
||||||
|
return kindLists
|
||||||
for ( const kindPage of paginatedList.pages ) {
|
}
|
||||||
const kindPagePath = `${ apiKindListDirectory }/${ kindPage.number }.json`
|
|
||||||
|
get kindRoutes () {
|
||||||
// console.log('kindPage.items', kindPage)
|
return Object.entries( this.makeKindLists() ).map( ([ kindSlug, kindList ]) => {
|
||||||
|
return kindList.routes
|
||||||
await this.saveToJson( kindPage.items, kindPagePath )
|
}).flat()
|
||||||
|
}
|
||||||
|
|
||||||
|
saveKinds = async function () {
|
||||||
|
|
||||||
|
const kindLists = this.makeKindLists()
|
||||||
|
|
||||||
|
// Save the lists
|
||||||
|
for ( const kindSlug in kindLists ) {
|
||||||
|
|
||||||
|
console.log('\n', `-- Starting kind lists for ${ kindSlug }`)
|
||||||
|
|
||||||
|
const endpointMethodName = `Finished kind lists for ${ kindSlug }`
|
||||||
|
console.time(endpointMethodName)
|
||||||
|
|
||||||
|
|
||||||
|
const kindList = kindLists[ kindSlug ]
|
||||||
|
|
||||||
|
// Ensure the base directory exists
|
||||||
|
await fs.ensureDir( kindList.basePath )
|
||||||
|
|
||||||
|
for ( const file of kindList.apiFiles ) {
|
||||||
|
// console.log('kindPage.items', kindPage)
|
||||||
|
|
||||||
|
await this.saveToJson( file.content, file.path )
|
||||||
|
}
|
||||||
|
|
||||||
|
console.timeEnd(endpointMethodName)
|
||||||
|
console.log( '\n\n' )
|
||||||
}
|
}
|
||||||
|
|
||||||
console.timeEnd(endpointMethodName)
|
|
||||||
console.log( '\n\n' )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveApiEndpoints = async ( listOptions ) => {
|
saveApiEndpoints = async ( listOptions ) => {
|
||||||
|
|
@ -379,8 +414,6 @@ class BuildLists {
|
||||||
throw new Error( errors )
|
throw new Error( errors )
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.saveKind( Array.from( this.lists[listOptions.name] ), listOptions.name )
|
|
||||||
|
|
||||||
// Array.from( this.lists[listOptions.name] )
|
// Array.from( this.lists[listOptions.name] )
|
||||||
|
|
||||||
// Count saved files
|
// Count saved files
|
||||||
|
|
@ -392,6 +425,10 @@ class BuildLists {
|
||||||
if ( fileCount !== this.lists[listOptions.name].size ) {
|
if ( fileCount !== this.lists[listOptions.name].size ) {
|
||||||
throw new Error( `Files (${ fileCount }) don\'t match list count in ${ apiListDirectory }(${ this.lists[listOptions.name].size }).` )
|
throw new Error( `Files (${ fileCount }) don\'t match list count in ${ apiListDirectory }(${ this.lists[listOptions.name].size }).` )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Save kinds
|
||||||
|
await this.saveKinds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save app lists to JSON
|
// Save app lists to JSON
|
||||||
|
|
@ -542,6 +579,17 @@ class BuildLists {
|
||||||
return Array.from( endpointSet , ([route, payload]) => ({ route, payload }) )
|
return Array.from( endpointSet , ([route, payload]) => ({ route, payload }) )
|
||||||
} ).flat(1)
|
} ).flat(1)
|
||||||
|
|
||||||
|
// Add kind routes to sitemap
|
||||||
|
this.kindRoutes.forEach( route => {
|
||||||
|
sitemapEndpoints.push({
|
||||||
|
route,
|
||||||
|
payload: {}
|
||||||
|
})
|
||||||
|
} )
|
||||||
|
|
||||||
|
// Add paginated category lists to sitemap
|
||||||
|
// sitemapEndpoints.push( ...this.getKindListForCategories() )
|
||||||
|
|
||||||
// Save sitemap endpoints
|
// Save sitemap endpoints
|
||||||
console.log('Building Sitemap JSON')
|
console.log('Building Sitemap JSON')
|
||||||
await this.saveToJson( sitemapEndpoints, './static/sitemap-endpoints.json')
|
await this.saveToJson( sitemapEndpoints, './static/sitemap-endpoints.json')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue