okay now the api should be ready. i wont know till i finish the template

This commit is contained in:
Adam Matthiesen 2024-01-23 15:24:38 -08:00
parent f854abe9dd
commit d56c9b962f
13 changed files with 28 additions and 12 deletions

View File

@ -1,19 +1,16 @@
import type { Page, Post } from "./index"; import type { Page, Post } from "./content-api/schemas";
import { TSGhostContentAPI } from "./content-api"; import { TSGhostContentAPI } from "./content-api";
// LOAD ENVIRONMENT VARIABLES // LOAD ENVIRONMENT VARIABLES
import { loadEnv } from 'vite'; import { loadEnv } from 'vite';
const {CONTENT_API_KEY, CONTENT_API_URL} = loadEnv( const {
'all', CONTENT_API_KEY,
process.cwd(), CONTENT_API_URL
'CONTENT_' } = loadEnv('all',process.cwd(),'CONTENT_');
);
let ghostApiKey = CONTENT_API_KEY; let ghostApiKey = CONTENT_API_KEY;
let ghostUrl = CONTENT_API_URL; let ghostUrl = CONTENT_API_URL;
// SETUP API
const version = "v5.0"; const version = "v5.0";
export const getGhostAuthors = async () => { export const getGhostAuthors = async () => {
@ -95,9 +92,6 @@ export const getSettings = async () => {
} }
return null; return null;
}; };
export type NonNullable<T> = T extends null | undefined ? never : T;
export type Settings = NonNullable<Awaited<ReturnType<typeof getSettings>>>;
export const getAllTags = async () => { export const getAllTags = async () => {
const api = new TSGhostContentAPI(ghostUrl, ghostApiKey, version); const api = new TSGhostContentAPI(ghostUrl, ghostApiKey, version);
@ -114,4 +108,24 @@ export const getAllTags = async () => {
tags: results.data, tags: results.data,
meta: results.meta, meta: results.meta,
}; };
};
export const getFeaturedPosts = async () => {
const api = new TSGhostContentAPI(ghostUrl, ghostApiKey, version);
const results = await api.posts
.browse({
filter: "featured:true"
})
.include({
authors: true,
tags: true,
})
.fetch();
if (!results.success) {
throw new Error(results.errors.map((e) => e.message).join(", "));
}
return {
posts: results.data,
meta: results.meta,
};
}; };

View File

@ -0,0 +1 @@
export * from './content-api';

View File

@ -1,4 +1,5 @@
export * from './api-functions';
export * from './content-api'; export * from './content-api';
export * from './schemas'; export * from './content-api/schemas'
export type { InferFetcherDataShape, InferResponseDataShape, BrowseParams } from "@ts-ghost/core-api"; export type { InferFetcherDataShape, InferResponseDataShape, BrowseParams } from "@ts-ghost/core-api";