Skip to content

Commit

Permalink
add resource pages cms
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman committed Nov 27, 2024
1 parent 505d945 commit 8f1f1de
Show file tree
Hide file tree
Showing 8 changed files with 755 additions and 214 deletions.
75 changes: 75 additions & 0 deletions pages/resources/[resource].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { type GetStaticPaths, type InferGetStaticPropsType } from 'next'

import { directusClient } from '@src/apollo-client'
import { CustomComponents } from '@src/components/custom-page/common'
import { FooterVariant } from '@src/components/FooterFull'
import {
ResourcePageDocument,
type ResourcePageQuery,
type ResourcePageQueryVariables,
ResourcesPageSlugsDocument,
type ResourcesPageSlugsQuery,
type ResourcesPageSlugsQueryVariables,
} from '@src/generated/graphqlDirectus'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'

export default function Resource({
resourceInfo,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return <CustomComponents components={resourceInfo.components ?? []} />
}

export const getStaticPaths: GetStaticPaths = async () => {
const { data, error } = await directusClient.query<
ResourcesPageSlugsQuery,
ResourcesPageSlugsQueryVariables
>({
query: ResourcesPageSlugsDocument,
})

if (error) {
console.error('GraphQL query error in static:', error)
}

return {
paths: data.resource_pages.map((page) => ({
params: { resource: page.slug },
})),
fallback: 'blocking',
}
}

export const getStaticProps = async (context) => {
const slug =
typeof context?.params?.resource === 'string'
? context?.params?.resource
: null

if (!slug) {
return { notFound: true }
}

const { data, error } = await directusClient.query<
ResourcePageQuery,
ResourcePageQueryVariables
>({
query: ResourcePageDocument,
variables: { slug },
})

if (error) {
console.error('GraphQL query error in static: ', error)
}
const resourceInfo = data.resource_pages?.[0] || null

if (!resourceInfo) {
return { notFound: true }
}

return propsWithGlobalSettings({
metaTitle: resourceInfo?.dropdown_title ?? '',
metaDescription: '',
footerVariant: FooterVariant.kitchenSink,
resourceInfo,
})
}
112 changes: 0 additions & 112 deletions src/components/AppsList.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/contexts/ReposContext.tsx

This file was deleted.

49 changes: 18 additions & 31 deletions src/data/getSiteSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { getImageUrl } from '@src/consts/routes'
import { type NavList } from '@src/contexts/NavDataContext'
import {
type ProductPageTinyFragment,
type ResourcePageTinyFragment,
type SiteSettingsFragment,
type SolutionPageTinyFragment,
} from '@src/generated/graphqlDirectus'

export const getSiteSettings = (
siteSettings: SiteSettingsFragment,
solutions?: SolutionPageTinyFragment[],
products?: ProductPageTinyFragment[]
products?: ProductPageTinyFragment[],
resources?: ResourcePageTinyFragment[]
) => ({
og_description: siteSettings.og_description ?? 'Plural',
og_image: getImageUrl(siteSettings.og_image),
Expand Down Expand Up @@ -43,36 +45,7 @@ export const getSiteSettings = (
title: 'Resources',
url: '/resources',
},
subnav: [
{
id: 'docs',
link: {
title: 'Docs',
url: 'https://docs.plural.sh',
},
},
{
id: 'blog',
link: {
title: 'Blog',
url: 'https://www.plural.sh/blog',
},
},
{
id: 'releases',
link: {
title: 'Releases',
url: 'https://github.com/pluralsh/plural/releases',
},
},
{
id: 'security and compliance',
link: {
title: 'Security & Compliance',
url: 'https://app.secureframe.com/ext/trust-center/plural/',
},
},
],
subnav: getResourcesSubnav(resources),
},
company: {
id: 'company',
Expand Down Expand Up @@ -143,3 +116,17 @@ function getProductSubnav(products?: ProductPageTinyFragment[]): NavList[] {
// }))
// .reverse()
// }

function getResourcesSubnav(resources?: ResourcePageTinyFragment[]) {
if (!resources || !resources.length) return []

return resources.map((resource) => ({
id: resource.slug,
link: {
title: resource.dropdown_title ?? '',
url: resource.external
? resource.url ?? '#'
: `/resources/${resource.slug}`,
},
}))
}
Loading

0 comments on commit 8f1f1de

Please sign in to comment.