Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions apps/marketing/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sitemap from '@astrojs/sitemap'
import tailwind from '@astrojs/tailwind'
import vercel from '@astrojs/vercel/serverless'
import sentry from '@sentry/astro'
import { defineConfig } from 'astro/config'
import { defineConfig, envField } from 'astro/config'
import dotenv from 'dotenv'

import postcss from './postcss.config.js'
Expand Down Expand Up @@ -50,12 +50,31 @@ export default defineConfig({
},
},
ssr: {
noExternal: ['swiper'],
external: ['image-size', 'tiny-glob'],
noExternal: [],
external: [
'image-size',
'tiny-glob',
'react',
'react-dom',
'@dnd-kit',
'@codesandbox/sandpack-react',
],
},
},
output: 'server',
adapter: vercel({
imageService: true,
}),
experimental: {
env: {
schema: {
SUPABASE_DEV_MODE: envField.string({
context: 'server',
access: 'public',
default: 'false',
}),
},
},
serverIslands: true,
},
})

This file was deleted.

This file was deleted.

44 changes: 0 additions & 44 deletions apps/marketing/src/components/dynamic-imports/layout.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions apps/marketing/src/components/dynamic-imports/render.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions apps/marketing/src/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,12 @@ export type Database = {
frontmatter: string | null
html: string | null
id: string
isStory: boolean | null
named_export: string | null
slug: string | null
sort: number | null
status: string
storybook_id: string | null
syntax: string | null
title: string | null
user_created: string | null
Expand All @@ -554,10 +556,12 @@ export type Database = {
frontmatter?: string | null
html?: string | null
id: string
isStory?: boolean | null
named_export?: string | null
slug?: string | null
sort?: number | null
status?: string
storybook_id?: string | null
syntax?: string | null
title?: string | null
user_created?: string | null
Expand All @@ -571,10 +575,12 @@ export type Database = {
frontmatter?: string | null
html?: string | null
id?: string
isStory?: boolean | null
named_export?: string | null
slug?: string | null
sort?: number | null
status?: string
storybook_id?: string | null
syntax?: string | null
title?: string | null
user_created?: string | null
Expand Down
2 changes: 1 addition & 1 deletion apps/marketing/src/pages/blog/[slug]/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const blogCreated = data.blogData[0]?.date_created as string
const blogAlt = data.blogData[0]?.title as string
const blogContent = data.blogData[0]?.content_block

const contentBlock = data.blogData[0]?.content_block
const contentBlock = data.blogData[0]?.content_block ?? ''

// Load the content block into cheerio
// @ts-ignore
Expand Down
69 changes: 41 additions & 28 deletions apps/marketing/src/pages/blog/[slug]/index.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@ import type { Database } from '@/database.types'
import type { SupabaseClient } from '@supabase/supabase-js'
import type { APIContext } from 'astro'

import { getSecret } from 'astro:env/server'

import { supabase } from '@/supabase'

const supabaseClient: SupabaseClient = supabase
type Articles = Database['public']['Tables']['articles']['Row']
type Authors = Database['public']['Tables']['authors']['Row']
type Files = Database['public']['Tables']['directus_files']['Row']
const supabaseClient: SupabaseClient<Database> = supabase
// type Articles = Database['public']['Tables']['articles']['Row']
// type Authors = Database['public']['Tables']['authors']['Row']
// type Files = Database['public']['Tables']['directus_files']['Row']

interface ArticlesWithRelations {
id: Articles['id']
status: Articles['status']
sort: Articles['sort']
date_created: Articles['date_created']
date_updated: Articles['date_updated']
title: Articles['title']
excerpt: Articles['excerpt']
slug: Articles['slug']
author?:
| (Pick<Authors, 'title' | 'last_name' | 'first_name'> & {
avatar: Pick<Files, 'filename_disk'> | null
})
| null
image: Pick<Files, 'filename_disk'> | null
}
// interface ArticlesWithRelations {
// id: Articles['id']
// status: Articles['status']
// sort: Articles['sort']
// date_created: Articles['date_created']
// date_updated: Articles['date_updated']
// title: Articles['title']
// excerpt: Articles['excerpt']
// slug: Articles['slug']
// author?:
// | (Pick<Authors, 'title' | 'last_name' | 'first_name'> & {
// avatar: Pick<Files, 'filename_disk'> | null
// })
// | null
// image: Pick<Files, 'filename_disk'> | null
// }
/**
*
* @param root0 The API context.
Expand Down Expand Up @@ -91,21 +93,32 @@ export async function GET({ params }: APIContext) {
async function fetchBlogData(
supabase: SupabaseClient,
slug: string,
): Promise<ArticlesWithRelations[] | null> {
const response = await supabase
): Promise<unknown[] | null> {
const SUPABASE_DEV_MODE = getSecret('SUPABASE_DEV_MODE')
const isDevMode = SUPABASE_DEV_MODE === 'true'

// Start building the query
let query = supabase
.from('articles')
.select(
`
*,slug,author(title,last_name,first_name,avatar(filename_disk)),image(filename_disk)
)
`,
*,slug,author(title,last_name,first_name,avatar(filename_disk)),image(filename_disk)
`,
)
.neq('status', 'draft')
.eq('slug', slug)

if (response.error === null && response.data !== null) {
return response.data as unknown as ArticlesWithRelations[]
// Conditionally apply the filter based on isDevMode
if (!isDevMode) {
console.log('Excluding drafts from query.')
query = query.neq('status', 'draft')
}

const response = await query

if (response.error === null) {
return response.data
}

console.error(response.error)
return null
}
75 changes: 46 additions & 29 deletions apps/marketing/src/pages/blog/index.json.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import type { Database } from '@/database.types'
import type { PostgrestResponse, SupabaseClient } from '@supabase/supabase-js'
import type { SupabaseClient } from '@supabase/supabase-js'

import { getSecret } from 'astro:env/server'

import { supabase } from '@/supabase'

type Articles = Database['public']['Tables']['articles']['Row']
type Authors = Database['public']['Tables']['authors']['Row']
type Files = Database['public']['Tables']['directus_files']['Row']
// type Articles = Database['public']['Tables']['articles']['Row']
// type Authors = Database['public']['Tables']['authors']['Row']
// type Files = Database['public']['Tables']['directus_files']['Row']

interface ArticlesWithRelations {
id: Articles['id']
status: Articles['status']
sort: Articles['sort']
date_created: Articles['date_created']
date_updated: Articles['date_updated']
title: Articles['title']
excerpt: Articles['excerpt']
slug: Articles['slug']
author?:
| (Pick<Authors, 'title' | 'last_name' | 'first_name'> & {
avatar: Pick<Files, 'filename_disk'> | null
})
| null
image: Pick<Files, 'filename_disk'> | null
}
// interface ArticlesWithRelations {
// post_id: Articles['id']
// status: Articles['status']
// sort: Articles['sort']
// date_created: Articles['date_created']
// date_updated: Articles['date_updated']
// title: Articles['title']
// excerpt: Articles['excerpt']
// slug: Articles['slug']
// author?:
// | (Pick<Authors, 'first_name' | 'title' | 'last_name'> & {
// avatar: Pick<Files, 'filename_disk'> | null
// })
// | null,
// image: Pick<Files, 'filename_disk'> | null,
// }
const supabaseClient: SupabaseClient<Database> = supabase

/**
Expand All @@ -32,20 +34,35 @@ const supabaseClient: SupabaseClient<Database> = supabase
*/
async function fetchBlogData(
supabase: SupabaseClient<Database>,
): Promise<ArticlesWithRelations[] | null> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const response: PostgrestResponse<ArticlesWithRelations> = await supabase
): Promise<unknown[] | null> {
const SUPABASE_DEV_MODE = getSecret('SUPABASE_DEV_MODE')
const isDevMode = SUPABASE_DEV_MODE === 'true'

console.log('isDevMode:', isDevMode)

// Start building the query
let query = supabase
.from('articles')
.select(
'id,status,sort,date_created,date_updated,author(title,last_name,first_name,avatar(filename_disk)),title,excerpt,slug,image(filename_disk)',
'id, status, sort, date_created, date_updated, title, excerpt, slug, image!inner(id,filename_disk), author!inner(id,title, first_name, last_name, avatar!inner(id,filename_disk))',
)
.neq('status', 'draft')

.order('date_created', { ascending: false })

// Type guard to check if response.error exists
// Conditionally apply the filter based on isDevMode
if (!isDevMode) {
// console.log('Excluding drafts from query.')
query = query.neq('status', 'draft')
}

const response = await query

// Log the response to see what is returned
// console.log('Response received:', response)

// Check for errors
if (response.error) {
console.error(response.error)
console.error('Error fetching articles:', response.error)
return null
}

Expand All @@ -59,7 +76,7 @@ async function fetchBlogData(
export async function GET() {
try {
const blogData = await fetchBlogData(supabaseClient)
if (!blogData || blogData.length === 0) {
if (!blogData) {
console.error('Data is empty or undefined')
return new Response(JSON.stringify({ error: 'No data found.' }), {
status: 404,
Expand Down
Loading