import ConvertPage from '@featurePages/convert/convert' ; import { GetStaticPaths , GetStaticProps } from 'next' ; import React from 'react' ; import formats from 'src/dist/formats' ; React . useLayoutEffect = React . useEffect ; const ConvertTo = ( { to , from } ) => { return < ConvertPage to = { to } from = { from } > < /ConvertPage>; } ; export const getStaticProps = async ( { params } ) => { const to = params ?. to as string | undefined ; const splitArr = to ?. split ( '-to-' ) ; const from = splitArr && splitArr . length > 1 ? splitArr [ 0 ] : null ; const splitTo = splitArr ?. pop ( ) ; return { props : { to : splitTo , from : from } } ; } ; type ParamPaths = Array < { params : { to ? : string ; long ? : string ; } ; } > ; export const getStaticPaths = async ( ) => { const formatKeys = Object . keys ( formats ) ; const paths = formatKeys . map ( format => { return { params : { to : format . toLowerCase ( ) } } ; } ) ; const fromToPaths = formatKeys . map ( format => { const fromPaths = formatKeys . filter ( currentFormat => currentFormat !== format ) . map ( currentFormat => { return { params : { to : `${ currentFormat . toLowerCase ( ) }-to-${ format . toLowerCase ( ) }` } } ; } ) ; return fromPaths ; } ) ; const flattedArray = Array . prototype . concat . apply ( [ ] , fromToPaths ) ; return { paths : [ ... paths , ... flattedArray ] , fallback : false } ; } ; export default ConvertTo ;