Skip to content

Commit

Permalink
Update to Astro5
Browse files Browse the repository at this point in the history
  • Loading branch information
tordans committed Dec 5, 2024
1 parent cdf66f3 commit 70c87fb
Show file tree
Hide file tree
Showing 35 changed files with 2,719 additions and 2,032 deletions.
2 changes: 1 addition & 1 deletion .env.example.local
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ PUBLIC_KEYSTATIC_GITHUB_APP_SLUG=osm-verkehrswende-keystatic-cms # https://githu
KEYSTATIC_STORAGE_KIND=local

ASTRO_ENV=development
ASTRO_OUTPUT_MODE=hybrid
ASTRO_OUTPUT_MODE=server
ASTRO_USE_NETLIFY_ADAPTER=false
52 changes: 25 additions & 27 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,31 @@ export default defineConfig({
]),
],
},
experimental: {
env: {
schema: {
ASTRO_OUTPUT_MODE: envField.enum({
values: ['static', 'hybrid', 'server'],
access: 'secret',
context: 'server',
optional: false,
}),
ASTRO_USE_NETLIFY_ADAPTER: envField.boolean({
access: 'secret',
context: 'server',
optional: false,
}),
KEYSTATIC_STORAGE_KIND: envField.enum({
values: ['local', 'github'],
access: 'public',
context: 'client',
optional: false,
}),
ASTRO_ENV: envField.enum({
values: ['development', 'staging', 'production'],
access: 'public',
context: 'client',
optional: false,
}),
},
env: {
schema: {
ASTRO_OUTPUT_MODE: envField.enum({
values: ['static', 'hybrid', 'server'],
access: 'secret',
context: 'server',
optional: false,
}),
ASTRO_USE_NETLIFY_ADAPTER: envField.boolean({
access: 'secret',
context: 'server',
optional: false,
}),
KEYSTATIC_STORAGE_KIND: envField.enum({
values: ['local', 'github'],
access: 'public',
context: 'client',
optional: false,
}),
ASTRO_ENV: envField.enum({
values: ['development', 'staging', 'production'],
access: 'public',
context: 'client',
optional: false,
}),
},
},
})
6 changes: 3 additions & 3 deletions keystatic.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from '@keystatic/core'
import { KEYSTATIC_STORAGE_KIND } from 'astro:env/client'
import { keystaticCampaignsConfig } from 'keystatic/keystatic.campaigns.config'
import { keystaticPostsConfig } from 'keystatic/keystatic.posts.config'
import { keystaticProjectsConfig } from 'keystatic/keystatic.projects.config'
import { keystaticCampaignsConfig } from 'keystatic/campaignsKeystatic'
import { keystaticPostsConfig } from 'keystatic/postsKeystatic'
import { keystaticProjectsConfig } from 'keystatic/projectsKeystatic'

export default config({
storage: {
Expand Down
33 changes: 33 additions & 0 deletions keystatic/campaignsAstro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { languages } from '@layouts/languages'
import { defineCollection, z } from 'astro:content'
import { contentBase } from './campaignsKeystatic'
import { extractedProjectKeys } from './extractedProjectKeys'
import { loader } from './utils/loader'

export const AstroCampaignSchema = z.object({
name: z.string(),
menuTitle: z.string(),
project: z.enum(extractedProjectKeys),
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
author: z.string(),
inMenu: z.boolean(),
language: z.enum(languages).optional(),
maprouletteChallenge: z.object({
id: z.number().nullable(),
enabled: z.boolean(),
name: z.string(),
remoteGeoJson: z.string().url(),
checkinComment: z.string(),
checkinSource: z.string(),
}),
})

export type AstroCampaignType = z.infer<typeof AstroCampaignSchema> & { content: string }

export const astroCampaignsDefinition = defineCollection({
loader: loader(contentBase, 'json'),
schema: () => AstroCampaignSchema,
})
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
import { collection, fields } from '@keystatic/core'
import { languages } from '@layouts/languages'
import { defineCollection, z } from 'astro:content'
import { extractedProjectKeys } from './extractedProjectKeys'
import { mdxComponentsKeystatic } from './mdxComponents'
import { authorsSelect } from './utils/authorsSelect'
import { languagesSelect } from './utils/languagesSelect'
import { projectsSelect } from './utils/projectsSelect'

export const AstroCampaignSchema = z.object({
name: z.string(),
menuTitle: z.string(),
project: z.enum(extractedProjectKeys),
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
author: z.string(),
inMenu: z.boolean(),
language: z.enum(languages).optional(),
maprouletteChallenge: z.object({
id: z.number().nullable(),
enabled: z.boolean(),
name: z.string(),
remoteGeoJson: z.string().url(),
checkinComment: z.string(),
checkinSource: z.string(),
}),
})

export type AstroCampaignType = z.infer<typeof AstroCampaignSchema> & { content: string }

export const astroCampaignsDefinition = defineCollection({
type: 'data',
schema: () => AstroCampaignSchema,
})

export const contentBase = 'src/content/campaigns'
export const keystaticCampaignsConfig = collection({
label: 'Kampagne',
slugField: 'menuTitle',
path: 'src/content/campaigns/*/',
path: `${contentBase}/*/`,
format: { data: 'json' },
entryLayout: 'form',
columns: ['name', 'pubDate'],
Expand Down
32 changes: 32 additions & 0 deletions keystatic/postsAstro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { languages } from '@layouts/languages'
import { defineCollection, z } from 'astro:content'
import { extractedProjectKeys } from './extractedProjectKeys'
import { contentBase } from './postsKeystatic'
import { loader } from './utils/loader'

export const astroPostsDefinition = defineCollection({
loader: loader(contentBase, 'mdx'),
schema: ({ image }) =>
z.object({
title: z.string(),
menuTitle: z.string(),
project: z.enum(extractedProjectKeys),
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
updatedDate: z
.string()
.or(z.date())
.transform((val) => new Date(val))
.optional(), // Note: implemented but unused ATM
author: z.string(),
inMenu: z.boolean(),
noindex: z.boolean().optional(),
language: z.enum(languages).optional(),
image: image().nullish(),
imageAlt: z.string().optional(),
showToc: z.boolean().optional(), // TODO Do we need this?
canonicalUrl: z.string().url().optional(),
}),
})
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
import { collection, fields } from '@keystatic/core'
import { languages } from '@layouts/languages'
import { defineCollection, z } from 'astro:content'
import { extractedProjectKeys } from './extractedProjectKeys'
import { mdxComponentsKeystatic } from './mdxComponents'
import { authorsSelect } from './utils/authorsSelect'
import { languagesSelect } from './utils/languagesSelect'
import { projectsSelect } from './utils/projectsSelect'

export const astroPostsDefinition = defineCollection({
type: 'content',
schema: ({ image }) =>
z.object({
title: z.string(),
menuTitle: z.string(),
project: z.enum(extractedProjectKeys),
pubDate: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
updatedDate: z
.string()
.or(z.date())
.transform((val) => new Date(val))
.optional(), // Note: implemented but unused ATM
author: z.string(),
inMenu: z.boolean(),
noindex: z.boolean().optional(),
language: z.enum(languages).optional(),
image: image().nullish(),
imageAlt: z.string().optional(),
showToc: z.boolean().optional(), // TODO Do we need this?
canonicalUrl: z.string().url().optional(),
}),
})

export const contentBase = 'src/content/posts'
export const keystaticPostsConfig = collection({
label: 'Blog',
slugField: 'menuTitle',
path: 'src/content/posts/*/',
path: `${contentBase}/*/`,
format: { contentField: 'content' },
entryLayout: 'content',
columns: ['title', 'pubDate'],
Expand Down
42 changes: 42 additions & 0 deletions keystatic/projectsAstro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { languages } from '@layouts/languages'
import { defineCollection, z, type CollectionEntry } from 'astro:content'
import { contentBase } from './projectsKeystatic'
import { loader } from './utils/loader'

export type TProjectConfig = CollectionEntry<'projects'>['data']['projects'][number]

export const astroProjectsDefinition = defineCollection({
loader: loader(contentBase, 'json'),
schema: ({ image }) =>
z.object({
projects: z.array(
z.object({
enabled: z.boolean(),
name: z.object({ name: z.string(), slug: z.string() }),
externalProjektPage: z.string().optional(),
header: z.enum(['ProjectHeader', 'AboutHeader']),
menus: z
.array(
// Menu Group
z.object({
label: z.string().nullish(),
// Menu Items
items: z.array(z.object({ href: z.string(), label: z.string() })),
}),
)
.nullish(),
menuNews: z.boolean(),
additionalFooterLinks: z
.array(z.object({ href: z.string(), label: z.string() }))
.optional(),
meta: z.object({
title: z.string(),
description: z.string().nullish(),
image: image().nullish(),
imageAlt: z.string().nullish(),
language: z.enum(languages),
}),
}),
),
}),
})
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import { fields, singleton } from '@keystatic/core'
import { languages } from '@layouts/languages'
import { defineCollection, z, type CollectionEntry } from 'astro:content'
import { languagesSelect } from './utils/languagesSelect'

export type TProjectConfig = CollectionEntry<'projects'>['data']['projects'][number]

export const astroProjectsDefinition = defineCollection({
type: 'data',
schema: ({ image }) =>
z.object({
projects: z.array(
z.object({
enabled: z.boolean(),
name: z.object({ name: z.string(), slug: z.string() }),
externalProjektPage: z.string().optional(),
header: z.enum(['ProjectHeader', 'AboutHeader']),
menus: z
.array(
// Menu Group
z.object({
label: z.string().nullish(),
// Menu Items
items: z.array(z.object({ href: z.string(), label: z.string() })),
}),
)
.nullish(),
menuNews: z.boolean(),
additionalFooterLinks: z
.array(z.object({ href: z.string(), label: z.string() }))
.optional(),
meta: z.object({
title: z.string(),
description: z.string().nullish(),
image: image().nullish(),
imageAlt: z.string().nullish(),
language: z.enum(languages),
}),
}),
),
}),
})

export const contentBase = 'src/content/projects/'
export const keystaticProjectsConfig = singleton({
label: 'Projekte',
path: 'src/content/projects/',
path: contentBase,
format: { data: 'json' },
schema: {
projects: fields.array(
Expand Down
9 changes: 9 additions & 0 deletions keystatic/utils/loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { glob } from 'astro/loaders'

export const loader = (contentBase: string, format: 'mdx' | 'json' | 'yaml') => {
const base = contentBase.startsWith('/') ? `.${contentBase}` : contentBase
return glob({
base: base,
pattern: `**\/[^_]*.${format}`,
})
}
Loading

0 comments on commit 70c87fb

Please sign in to comment.