Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Jan 8, 2025
2 parents 9586d66 + e73aebd commit b23115e
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 92 deletions.
22 changes: 11 additions & 11 deletions package/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { defineCollection } from 'astro:content';
import { loadEnv } from 'vite';
import {
tagsSchema,
pagesSchema,
postsSchema,
tiersSchema,
authorsSchema,
loaderSettingsSchema,
} from './schemas/index.js';
import type { LoaderCollection, LoaderCollectionOpts } from './types.js';
import { GhostCMSContentAPIFactory } from './api.js';
import {
AuthorsLoader,
PageLoader,
PostsLoader,
TagsLoader,
SettingsLoader,
TagsLoader,
TiersLoader,
} from './loaders/index.js';
import { GhostCMSContentAPIFactory } from './api.js';
import {
authorsSchema,
loaderSettingsSchema,
pagesSchema,
postsSchema,
tagsSchema,
tiersSchema,
} from './schemas/index.js';
import type { LoaderCollection, LoaderCollectionOpts } from './types.js';
import { logger } from './utils.js';

export function GhostCMSLoaderCollection({
Expand Down
4 changes: 2 additions & 2 deletions package/src/loaders/authors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { authorsSchema, type Author } from '../schemas/index.js';
import { type Author, authorsSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export function AuthorsLoader(api: TSGhostContentAPI<`v5.${string}`>): Loader {
return {
Expand Down
4 changes: 2 additions & 2 deletions package/src/loaders/pages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { pagesSchema, type Page } from '../schemas/index.js';
import { type Page, pagesSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export function PageLoader(api: TSGhostContentAPI<`v5.${string}`>): Loader {
return {
Expand Down
4 changes: 2 additions & 2 deletions package/src/loaders/posts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { postsSchema, type Post } from '../schemas/index.js';
import { type Post, postsSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export function PostsLoader(api: TSGhostContentAPI<`v5.${string}`>): Loader {
return {
Expand Down
2 changes: 1 addition & 1 deletion package/src/loaders/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { loaderSettingsSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export const GHOST_CMS_SETTINGS_ID = 'settings';

Expand Down
4 changes: 2 additions & 2 deletions package/src/loaders/tags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { tagsSchema, type Tag } from '../schemas/index.js';
import { type Tag, tagsSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export function TagsLoader(api: TSGhostContentAPI<`v5.${string}`>): Loader {
return {
Expand Down
4 changes: 2 additions & 2 deletions package/src/loaders/tiers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSGhostContentAPI } from '@ts-ghost/content-api';
import { AstroError } from 'astro/errors';
import type { Loader, LoaderContext } from 'astro/loaders';
import { tiersSchema, type Tier } from '../schemas/index.js';
import { type Tier, tiersSchema } from '../schemas/index.js';
import { logger } from '../utils.js';
import { AstroError } from 'astro/errors';

export function TiersLoader(api: TSGhostContentAPI<`v5.${string}`>): Loader {
return {
Expand Down
6 changes: 3 additions & 3 deletions package/src/schemas/authors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "astro/zod";
import { ghostIdentitySchema, ghostMetadataSchema, ghostMetaSchema } from "./shared.js";
import { z } from 'astro/zod';
import { ghostIdentitySchema, ghostMetaSchema, ghostMetadataSchema } from './shared.js';

export const authorsSchema = z.object({
...ghostIdentitySchema.shape,
Expand Down Expand Up @@ -28,6 +28,6 @@ export const ghostFetchAuthorsSchema = z.object({
});

export const authorsIncludeSchema = z.object({
"count.posts": z.literal(true).optional(),
'count.posts': z.literal(true).optional(),
});
export type AuthorsIncludeSchema = z.infer<typeof authorsIncludeSchema>;
2 changes: 1 addition & 1 deletion package/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export * from './posts.js';
export * from './tags.js';
export * from './tiers.js';
export * from './settings.js';
export * from './shared.js';
export * from './shared.js';
18 changes: 12 additions & 6 deletions package/src/schemas/pages.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { z } from "astro/zod";
import { ghostCodeInjectionSchema, ghostIdentitySchema, ghostMetadataSchema, ghostSocialMediaSchema, ghostVisibilitySchema } from "./shared.js";
import { z } from 'astro/zod';
import {
ghostCodeInjectionSchema,
ghostIdentitySchema,
ghostMetadataSchema,
ghostSocialMediaSchema,
ghostVisibilitySchema,
} from './shared.js';

import { authorsSchema } from "./authors.js";
import { tagsSchema } from "./tags.js";
import { authorsSchema } from './authors.js';
import { tagsSchema } from './tags.js';

const postsAuthorSchema = authorsSchema.extend({
url: z.string().nullish(),
Expand All @@ -12,7 +18,7 @@ export const pagesSchema = z.object({
...ghostIdentitySchema.shape,
...ghostMetadataSchema.shape,
title: z.string(),
html: z.string().catch(""),
html: z.string().catch(''),
plaintext: z.string().nullish(),
comment_id: z.string().nullable(),
feature_image: z.string().nullable(),
Expand All @@ -30,7 +36,7 @@ export const pagesSchema = z.object({
primary_author: postsAuthorSchema.nullish(),
primary_tag: tagsSchema.nullish(),
url: z.string(),
excerpt: z.string().catch(""),
excerpt: z.string().catch(''),
reading_time: z.number().optional().default(0),
created_at: z.string(),
updated_at: z.string(),
Expand Down
18 changes: 12 additions & 6 deletions package/src/schemas/posts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { z } from "astro/zod";
import { z } from 'astro/zod';

import { authorsSchema } from "./authors.js";
import { tagsSchema } from "./tags.js";
import { ghostCodeInjectionSchema, ghostIdentitySchema, ghostMetadataSchema, ghostSocialMediaSchema, ghostVisibilitySchema } from "./shared.js";
import { authorsSchema } from './authors.js';
import {
ghostCodeInjectionSchema,
ghostIdentitySchema,
ghostMetadataSchema,
ghostSocialMediaSchema,
ghostVisibilitySchema,
} from './shared.js';
import { tagsSchema } from './tags.js';

const postsAuthorSchema = authorsSchema.extend({
url: z.string().nullish(),
Expand All @@ -11,7 +17,7 @@ export const postsSchema = z.object({
...ghostIdentitySchema.shape,
...ghostMetadataSchema.shape,
title: z.string(),
html: z.string().catch(""),
html: z.string().catch(''),
plaintext: z.string().nullish(),
comment_id: z.string().nullable(),
feature_image: z.string().nullable(),
Expand All @@ -29,7 +35,7 @@ export const postsSchema = z.object({
primary_author: postsAuthorSchema.nullish(),
primary_tag: tagsSchema.nullish(),
url: z.string(),
excerpt: z.string().catch(""),
excerpt: z.string().catch(''),
reading_time: z.number().optional().default(0),
created_at: z.string(),
updated_at: z.string().nullish(),
Expand Down
94 changes: 47 additions & 47 deletions package/src/schemas/shared.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import { z } from "astro/zod";
import { z } from 'astro/zod';

export const ghostVisibilitySchema = z.union([
z.literal("public"),
z.literal("members"),
z.literal("none"),
z.literal("internal"),
z.literal("paid"),
z.literal("tiers")
])
z.literal('public'),
z.literal('members'),
z.literal('none'),
z.literal('internal'),
z.literal('paid'),
z.literal('tiers'),
]);

export const ghostIdentitySchema = z.object({
slug: z.string(),
id: z.string(),
});

export const ghostMetaSchema = z.object({
pagination: z.object({
pages: z.number(),
page: z.number(),
limit: z.union([z.number(), z.literal("all")]),
total: z.number(),
prev: z.number().nullable(),
next: z.number().nullable(),
}),
});
slug: z.string(),
id: z.string(),
});

export const ghostMetaSchema = z.object({
pagination: z.object({
pages: z.number(),
page: z.number(),
limit: z.union([z.number(), z.literal('all')]),
total: z.number(),
prev: z.number().nullable(),
next: z.number().nullable(),
}),
});

export const ghostCodeInjectionSchema = z.object({
codeinjection_head: z.string().nullable(),
codeinjection_foot: z.string().nullable(),
});

export const ghostFacebookSchema = z.object({
og_image: z.string().nullable(),
og_title: z.string().nullable(),
og_description: z.string().nullable(),
});
export const ghostTwitterSchema = z.object({
twitter_image: z.string().nullable(),
twitter_title: z.string().nullable(),
twitter_description: z.string().nullable(),
});
export const ghostSocialMediaSchema = z.object({
...ghostFacebookSchema.shape,
...ghostTwitterSchema.shape,
});
export const ghostMetadataSchema = z.object({
meta_title: z.string().nullable(),
meta_description: z.string().nullable(),
});
codeinjection_head: z.string().nullable(),
codeinjection_foot: z.string().nullable(),
});

export const ghostFacebookSchema = z.object({
og_image: z.string().nullable(),
og_title: z.string().nullable(),
og_description: z.string().nullable(),
});

export const ghostTwitterSchema = z.object({
twitter_image: z.string().nullable(),
twitter_title: z.string().nullable(),
twitter_description: z.string().nullable(),
});

export const ghostSocialMediaSchema = z.object({
...ghostFacebookSchema.shape,
...ghostTwitterSchema.shape,
});

export const ghostMetadataSchema = z.object({
meta_title: z.string().nullable(),
meta_description: z.string().nullable(),
});
12 changes: 9 additions & 3 deletions package/src/schemas/tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { z } from "astro/zod";
import { ghostCodeInjectionSchema, ghostIdentitySchema, ghostMetadataSchema, ghostSocialMediaSchema, ghostVisibilitySchema } from "./shared.js";
import { z } from 'astro/zod';
import {
ghostCodeInjectionSchema,
ghostIdentitySchema,
ghostMetadataSchema,
ghostSocialMediaSchema,
ghostVisibilitySchema,
} from './shared.js';

export const tagsSchema = z.object({
...ghostIdentitySchema.shape,
Expand All @@ -23,6 +29,6 @@ export const tagsSchema = z.object({
export type Tag = z.infer<typeof tagsSchema>;

export const tagsIncludeSchema = z.object({
"count.posts": z.literal(true).optional(),
'count.posts': z.literal(true).optional(),
});
export type TagsIncludeSchema = z.infer<typeof tagsIncludeSchema>;
6 changes: 3 additions & 3 deletions package/src/schemas/tiers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { z } from "astro/zod";
import { ghostIdentitySchema, ghostVisibilitySchema } from "./shared.js";
import { z } from 'astro/zod';
import { ghostIdentitySchema, ghostVisibilitySchema } from './shared.js';

export const tiersSchema = z.object({
...ghostIdentitySchema.shape,
name: z.string(),
description: z.string().nullable(),
active: z.boolean(),
type: z.union([z.literal("free"), z.literal("paid")]),
type: z.union([z.literal('free'), z.literal('paid')]),
welcome_page_url: z.string().nullable(),
created_at: z.string(),
updated_at: z.string().nullable(),
Expand Down
2 changes: 1 addition & 1 deletion package/tests/fixtures/astro/src/pages/basic/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Layout from '../../layouts/layout.astro';
import { getCollection } from 'astro:content';
import Layout from '../../layouts/layout.astro';
const pages = await getCollection('ghostPages');
---
Expand Down

0 comments on commit b23115e

Please sign in to comment.