more code cleanup
This commit is contained in:
parent
90826e29cb
commit
fca8767548
|
@ -1,5 +1,5 @@
|
|||
import type { Page, Post } from "./content-api/schemas";
|
||||
import { TSGhostContentAPI } from "./content-api";
|
||||
import { TS_API } from "./content-api";
|
||||
|
||||
// LOAD ENVIRONMENT VARIABLES
|
||||
import { loadEnv } from 'vite';
|
||||
|
@ -16,7 +16,7 @@ const {
|
|||
const ghostApiKey = CONTENT_API_KEY;
|
||||
const ghostUrl = CONF_URL ? CONF_URL : CONTENT_API_URL;
|
||||
const version = "v5.0";
|
||||
const api = new TSGhostContentAPI(ghostUrl, ghostApiKey, version);
|
||||
const api = new TS_API(ghostUrl, ghostApiKey, version);
|
||||
|
||||
export const getAllAuthors = async () => {
|
||||
const results = await api.authors
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { assert, beforeEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { TSGhostContentAPI } from "./content-api";
|
||||
import TS_API from "./content-api";
|
||||
|
||||
describe("content-api", () => {
|
||||
let api: TSGhostContentAPI;
|
||||
let api: TS_API;
|
||||
beforeEach(() => {
|
||||
api = new TSGhostContentAPI("https://ghost.org", "59d4bf56c73c04a18c867dc3ba", "v5.0");
|
||||
api = new TS_API("https://ghost.org", "59d4bf56c73c04a18c867dc3ba", "v5.0");
|
||||
});
|
||||
|
||||
test("content-api", () => {
|
||||
|
@ -14,21 +14,21 @@ describe("content-api", () => {
|
|||
|
||||
test("content-api shouldn't instantiate with an incorrect url", () => {
|
||||
assert.throws(() => {
|
||||
const api = new TSGhostContentAPI("ghost.org", "59d4bf56c73c04a18c867dc3ba", "v5.0");
|
||||
const api = new TS_API("ghost.org", "59d4bf56c73c04a18c867dc3ba", "v5.0");
|
||||
api.settings;
|
||||
});
|
||||
});
|
||||
|
||||
test("content-api shouldn't instantiate with an incorrect key", () => {
|
||||
assert.throws(() => {
|
||||
const api = new TSGhostContentAPI("https://ghost.org", "a", "v5.0");
|
||||
const api = new TS_API("https://ghost.org", "a", "v5.0");
|
||||
api.settings;
|
||||
});
|
||||
});
|
||||
|
||||
test("content-api shouldn't instantiate with an incorrect version", () => {
|
||||
assert.throws(() => {
|
||||
const api = new TSGhostContentAPI(
|
||||
const api = new TS_API(
|
||||
"https://ghost.org",
|
||||
"1efedd9db174adee2d23d982:4b74dca0219bad629852191af326a45037346c2231240e0f7aec1f9371cc14e8",
|
||||
// @ts-expect-error
|
||||
|
|
|
@ -21,7 +21,7 @@ export enum BrowseEndpointType {
|
|||
settings = "settings",
|
||||
}
|
||||
|
||||
export class TSGhostContentAPI<Version extends `v5.${// biome-ignore lint/suspicious/noExplicitAny: shhhhh
|
||||
export default class TS_API<Version extends `v5.${// biome-ignore lint/suspicious/noExplicitAny: shhhhh
|
||||
string}` = any> {
|
||||
private httpClient: HTTPClient;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export * from './content-api';
|
||||
export { default as TS_API } from './content-api';
|
||||
export * from './schemas';
|
||||
|
||||
export type { InferFetcherDataShape, InferResponseDataShape, BrowseParams } from "@ts-ghost/core-api";
|
|
@ -3,12 +3,30 @@ import type { UserConfig } from '../schemas';
|
|||
|
||||
export function getSitemapConfig(opts: UserConfig["sitemap"]): SitemapOptions {
|
||||
const sitemapConfig: SitemapOptions = {};
|
||||
if (opts?.filter){
|
||||
sitemapConfig.filter = opts.filter;
|
||||
}
|
||||
if (opts?.changefreq){
|
||||
sitemapConfig.changefreq = opts.changefreq;
|
||||
}
|
||||
if (opts?.entryLimit){
|
||||
sitemapConfig.entryLimit = opts.entryLimit;
|
||||
}
|
||||
if (opts?.customPages){
|
||||
sitemapConfig.customPages = opts.customPages;
|
||||
}
|
||||
if (opts?.i18n){
|
||||
sitemapConfig.i18n = opts.i18n;
|
||||
}
|
||||
if (opts?.lastmod){
|
||||
sitemapConfig.lastmod = opts.lastmod;
|
||||
}
|
||||
if (opts?.priority){
|
||||
sitemapConfig.priority = opts.priority;
|
||||
}
|
||||
if (opts?.serialize){
|
||||
sitemapConfig.serialize = opts.serialize;
|
||||
}
|
||||
return sitemapConfig;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,54 +1,3 @@
|
|||
import { z } from 'astro/zod';
|
||||
import { SitemapSchema } from './sitemap';
|
||||
import { RobotsTxtSchema } from './robots';
|
||||
|
||||
export const UserConfigSchema = z.object({
|
||||
/** OPTIONAL - Either set the URL in your .env or put it here
|
||||
* @example
|
||||
* // https://astro.build/config
|
||||
* export default defineConfig({
|
||||
* integrations: [
|
||||
* ghostcms({
|
||||
* ghostURL: "https://ghostdemo.matthiesen.xyz"
|
||||
* })
|
||||
* ],
|
||||
* }); */
|
||||
ghostURL: z.string().url().optional(),
|
||||
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
|
||||
disableRSS: z.boolean().default(false),
|
||||
/** OPTIONAL - Allows the user to disable the `/404` injection */
|
||||
disable404: z.boolean().default(false),
|
||||
/** OPTIONAL - Disable Route Injector
|
||||
* This option allows the user to disable the route injection system and utilize just the integraions other functions. Such as API, sitemap and robotstxt integrations. */
|
||||
disableRouteInjection: z.boolean().default(false),
|
||||
/** OPTIONAL - (Default: true) Allows the user to disable "info" console output */
|
||||
disableConsoleOutput: z.boolean().default(true),
|
||||
/** OPTIONAL - Theme Selector
|
||||
* This option allows the user to replace the included theme with an external npm module
|
||||
* @example
|
||||
* // https://astro.build/config
|
||||
* export default defineConfig({
|
||||
* integrations: [
|
||||
* ghostcms({
|
||||
* theme: "@matthiesenxyz/astro-ghostcms-theme-default"
|
||||
* })
|
||||
* ],
|
||||
* }); */
|
||||
theme: z.string().default('@matthiesenxyz/astro-ghostcms-theme-default'),
|
||||
/** OPTIONAL - astrojs/sitemap
|
||||
* This option allows the user to configure the included integration
|
||||
* Options shown are the availble options
|
||||
* REFERENCE https://docs.astro.build/en/guides/integrations-guide/sitemap
|
||||
*/
|
||||
sitemap: SitemapSchema.optional(),
|
||||
/** OPTIONAL - astro-robots-txt
|
||||
* This option allows the user to configure the included integration
|
||||
* Options shown are the availble options
|
||||
* REFERENCE https://www.npmjs.com/package/astro-robots-txt#configuration
|
||||
*/
|
||||
robotstxt: RobotsTxtSchema.optional(),
|
||||
});
|
||||
|
||||
/** USER CONFIGURATION SCHEMA */
|
||||
export type UserConfig = z.infer<typeof UserConfigSchema>
|
||||
export type GhostUserConfig = z.infer<typeof UserConfigSchema>
|
||||
export * from './robots';
|
||||
export * from './sitemap';
|
||||
export * from './userconfig';
|
|
@ -27,7 +27,7 @@ const RobotsPolicySchema = z.object({
|
|||
* @example sitemap: ['https://example.com/sitemap-0.xml','https://example.com/sitemap-1.xml']
|
||||
* @example sitemap: false - If you want to get the robots.txt file without the Sitemap: ... entry, set the sitemap parameter to false.
|
||||
*/
|
||||
sitemap: z.string().optional(),
|
||||
sitemap: z.union([z.string(), z.string().array(), z.boolean()]).optional(),
|
||||
/** astrojs/sitemap and astro-sitemap integrations have the sitemap-index.xml as their primary output. That is why the default value of sitemapBaseFileName is set to sitemap-index.
|
||||
* @example sitemapBaseFileName: 'custom-sitemap'
|
||||
*/
|
||||
|
|
|
@ -1,12 +1,30 @@
|
|||
import { z } from "astro/zod";
|
||||
|
||||
const localeKeySchema = z.string().min(1);
|
||||
enum EnumChangefreq {
|
||||
DAILY = "daily",
|
||||
MONTHLY = "monthly",
|
||||
ALWAYS = "always",
|
||||
HOURLY = "hourly",
|
||||
WEEKLY = "weekly",
|
||||
YEARLY = "yearly",
|
||||
NEVER = "never"
|
||||
}
|
||||
export const SitemapSchema = z.object({
|
||||
/** @example ['https://example-1.com', 'https://example-2.com]
|
||||
* @see https://docs.astro.build/en/guides/integrations-guide/sitemap/#custompages
|
||||
*/
|
||||
customPages: z.string().array().optional(),
|
||||
/** @example 10000
|
||||
* @see https://docs.astro.build/en/guides/integrations-guide/sitemap/#entrylimit
|
||||
*/
|
||||
entryLimit: z.number().optional()
|
||||
filter: z.function().args(z.string()).returns(z.boolean()).optional(),
|
||||
customPages: z.string().url().array().optional(),
|
||||
i18n: z.object({
|
||||
defaultLocale: localeKeySchema,
|
||||
locales: z.record(
|
||||
localeKeySchema,
|
||||
z.string().min(2).regex(/^[a-zA-Z\-]+$/gm, { message: 'Only English alphabet symbols and hyphen allowed', })
|
||||
),
|
||||
}).refine((val) => !val || val.locales[val.defaultLocale], {
|
||||
message: '`defaultLocale` must exist in `locales` keys',
|
||||
}).optional(),
|
||||
entryLimit: z.number().nonnegative().optional(),
|
||||
serialize: z.function().args(z.any()).returns(z.any()).optional(),
|
||||
changefreq: z.nativeEnum(EnumChangefreq).optional(),
|
||||
lastmod: z.date().optional(),
|
||||
priority: z.number().min(0).max(1).optional(),
|
||||
})
|
|
@ -0,0 +1,53 @@
|
|||
import { z } from 'astro/zod';
|
||||
import { SitemapSchema, RobotsTxtSchema } from './index';
|
||||
|
||||
export const UserConfigSchema = z.object({
|
||||
/** OPTIONAL - Either set the URL in your .env or put it here
|
||||
* @example
|
||||
* // https://astro.build/config
|
||||
* export default defineConfig({
|
||||
* integrations: [
|
||||
* ghostcms({
|
||||
* ghostURL: "https://ghostdemo.matthiesen.xyz"
|
||||
* })
|
||||
* ],
|
||||
* }); */
|
||||
ghostURL: z.string().url().optional(),
|
||||
/** OPTIONAL - Allows the user to disable the `/rss.xml` injection */
|
||||
disableRSS: z.boolean().default(false),
|
||||
/** OPTIONAL - Allows the user to disable the `/404` injection */
|
||||
disable404: z.boolean().default(false),
|
||||
/** OPTIONAL - Disable Route Injector
|
||||
* This option allows the user to disable the route injection system and utilize just the integraions other functions. Such as API, sitemap and robotstxt integrations. */
|
||||
disableRouteInjection: z.boolean().default(false),
|
||||
/** OPTIONAL - (Default: true) Allows the user to disable "info" console output */
|
||||
disableConsoleOutput: z.boolean().default(true),
|
||||
/** OPTIONAL - Theme Selector
|
||||
* This option allows the user to replace the included theme with an external npm module
|
||||
* @example
|
||||
* // https://astro.build/config
|
||||
* export default defineConfig({
|
||||
* integrations: [
|
||||
* ghostcms({
|
||||
* theme: "@matthiesenxyz/astro-ghostcms-theme-default"
|
||||
* })
|
||||
* ],
|
||||
* }); */
|
||||
theme: z.string().default('@matthiesenxyz/astro-ghostcms-theme-default'),
|
||||
/** OPTIONAL - astrojs/sitemap
|
||||
* This option allows the user to configure the included integration
|
||||
* Options shown are the availble options
|
||||
* REFERENCE https://docs.astro.build/en/guides/integrations-guide/sitemap
|
||||
*/
|
||||
sitemap: SitemapSchema.optional(),
|
||||
/** OPTIONAL - astro-robots-txt
|
||||
* This option allows the user to configure the included integration
|
||||
* Options shown are the availble options
|
||||
* REFERENCE https://www.npmjs.com/package/astro-robots-txt#configuration
|
||||
*/
|
||||
robotstxt: RobotsTxtSchema.optional(),
|
||||
});
|
||||
|
||||
/** USER CONFIGURATION SCHEMA */
|
||||
export type UserConfig = z.infer<typeof UserConfigSchema>
|
||||
export type GhostUserConfig = z.infer<typeof UserConfigSchema>
|
Loading…
Reference in New Issue