mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add getJsonDirectory helper
This commit is contained in:
parent
7be3c23efb
commit
f1750ef4aa
2 changed files with 30 additions and 1 deletions
23
helpers/get-json-directory.js
Normal file
23
helpers/get-json-directory.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import fs from 'fs-extra'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const directoriesToTry = [
|
||||||
|
'./static/',
|
||||||
|
|
||||||
|
// Vercel Serverless Function
|
||||||
|
'./.next/server/chunks/static'
|
||||||
|
]
|
||||||
|
|
||||||
|
export async function getJsonDirectory () {
|
||||||
|
|
||||||
|
for ( const directory of directoriesToTry ) {
|
||||||
|
const directoryExists = await fs.pathExists( directory )
|
||||||
|
|
||||||
|
if ( directoryExists ) {
|
||||||
|
return directory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error( 'Could not find json directory' )
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
|
|
||||||
import Layout from '@/components/layout/default.js'
|
import Layout from '@/components/layout/default.js'
|
||||||
|
import { getJsonDirectory } from '@/helpers/get-json-directory.js';
|
||||||
|
|
||||||
// Based on
|
// Based on
|
||||||
// https://github.com/lfades/static-tweet/blob/b2a1044d881cca88e7761491d4f22c8908497d92/pages/t/%5Btweet%5D.js
|
// https://github.com/lfades/static-tweet/blob/b2a1044d881cca88e7761491d4f22c8908497d92/pages/t/%5Btweet%5D.js
|
||||||
|
|
@ -54,6 +55,10 @@ export async function getStaticProps({ params }) {
|
||||||
const server = await fs.readdir('./.next/server')
|
const server = await fs.readdir('./.next/server')
|
||||||
const chunks = await fs.readdir('./.next/server/chunks')
|
const chunks = await fs.readdir('./.next/server/chunks')
|
||||||
const staticDirectory = await fs.readdir('./.next/server/chunks/static')
|
const staticDirectory = await fs.readdir('./.next/server/chunks/static')
|
||||||
|
const jsonDirectory = await getJsonDirectory()
|
||||||
|
|
||||||
|
|
||||||
|
console.log('jsonDirectory', jsonDirectory)
|
||||||
|
|
||||||
// console.log('endpointListings', endpointListings[0])
|
// console.log('endpointListings', endpointListings[0])
|
||||||
|
|
||||||
|
|
@ -63,7 +68,8 @@ export async function getStaticProps({ params }) {
|
||||||
dotnext,
|
dotnext,
|
||||||
server,
|
server,
|
||||||
chunks,
|
chunks,
|
||||||
staticDirectory
|
staticDirectory,
|
||||||
|
jsonDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = '/formula/'
|
const start = '/formula/'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue