Skip to content

Commit

Permalink
bug fix: Add check that path exists for options.jsonFilePath (#2554)
Browse files Browse the repository at this point in the history
  • Loading branch information
heatlikeheatwave committed Aug 22, 2024
1 parent 8a15eeb commit e792e1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pages/vagrant/install/vmware/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateGetStaticProps } from 'views/product-downloads-view/server'
const getStaticProps = generateGetStaticProps(vagrantData as ProductData, {
installName: 'Vagrant VMware Utility',
releaseSlug: 'vagrant-vmware-utility',
jsonFilePath: `src/content/${vagrantData.slug}/install-vmware-landing.json`,
jsonFilePath: 'src/content/vagrant/install-vmware-landing.json',
})

export { getStaticProps }
Expand Down
19 changes: 8 additions & 11 deletions src/views/product-downloads-view/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: MPL-2.0
*/

import fs from 'fs'
import path from 'path'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { ProductData } from 'types/products'
import { generateStaticProps as generateReleaseStaticProps } from 'lib/fetch-release-data'
import { stripUndefinedProperties } from 'lib/strip-undefined-props'
Expand Down Expand Up @@ -41,23 +41,20 @@ const generateGetStaticProps = (
props: ProductDownloadsViewStaticProps
revalidate: number
}> => {
/**
* Fetch page content
*
* Note: could consider other content sources. For now, JSON.
* Asana task: https://app.asana.com/0/1100423001970639/1201631159784193/f
*/
let jsonFilePath = path.join(
let jsonFilePath = join(
process.cwd(),
`src/content/${product.slug}/install-landing.json`
)

if (options.jsonFilePath) {
jsonFilePath = path.join(process.cwd(), options.jsonFilePath)
const staticPath = join(process.cwd(), options.jsonFilePath)
if (existsSync(staticPath)) {
jsonFilePath = staticPath
}
}

const CONTENT: RawProductDownloadsViewContent = JSON.parse(
fs.readFileSync(jsonFilePath, 'utf8')
readFileSync(jsonFilePath, 'utf8')
)

const {
Expand Down

0 comments on commit e792e1c

Please sign in to comment.