some more starlight cleanup... also powered by AIK
This commit is contained in:
parent
f078ebc063
commit
edad9da91f
|
@ -3,12 +3,12 @@ import type {
|
||||||
StarlightUserConfig,
|
StarlightUserConfig,
|
||||||
} from "@astrojs/starlight/types";
|
} from "@astrojs/starlight/types";
|
||||||
import type { AstroIntegrationLogger } from "astro";
|
import type { AstroIntegrationLogger } from "astro";
|
||||||
import { vitePluginStarlightGhostConfig } from "./src/integrations/vite";
|
|
||||||
import {
|
import {
|
||||||
type StarlightGhostConfig,
|
type StarlightGhostConfig,
|
||||||
validateConfig,
|
validateConfig,
|
||||||
} from "./src/schemas/config";
|
} from "./src/schemas/config";
|
||||||
import { facebook, getSettings, invariant, twitter } from "./src/utils/api";
|
import { facebook, getSettings, invariant, twitter } from "./src/utils/api";
|
||||||
|
import starlightGhostcms from "./src/integrations/starlight-ghostcms";
|
||||||
|
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
|
||||||
|
@ -30,13 +30,16 @@ export default function starlightGhostCMS(
|
||||||
logger,
|
logger,
|
||||||
updateConfig: updateStarlightConfig,
|
updateConfig: updateStarlightConfig,
|
||||||
}) {
|
}) {
|
||||||
|
// Add the Starlight-GhostCMS integration
|
||||||
|
addIntegration(starlightGhostcms(config));
|
||||||
|
|
||||||
// Update the Starlight config with the GhostCMS config
|
// Update the Starlight config with the GhostCMS config
|
||||||
updateStarlightConfig({
|
updateStarlightConfig({
|
||||||
social: {
|
social: {
|
||||||
...starlightConfig.social,
|
...starlightConfig.social,
|
||||||
rss: `${astroConfig.site}/rss.xml`,
|
...overrideRSS(starlightConfig.social, astroConfig.site),
|
||||||
twitter: twitter(settings.twitter ? settings.twitter : ""),
|
...overrideTwitter(starlightConfig.social),
|
||||||
facebook: facebook(settings.facebook ? settings.facebook : ""),
|
...overrideFacebook(starlightConfig.social),
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
...starlightConfig.components,
|
...starlightConfig.components,
|
||||||
|
@ -57,47 +60,37 @@ export default function starlightGhostCMS(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add the Starlight-GhostCMS integration
|
|
||||||
addIntegration({
|
|
||||||
name: "@matthiesenxyz/starlight-ghostcms",
|
|
||||||
hooks: {
|
|
||||||
"astro:config:setup": ({ injectRoute, updateConfig }) => {
|
|
||||||
|
|
||||||
updateConfig({
|
|
||||||
vite: {
|
|
||||||
plugins: [vitePluginStarlightGhostConfig(config)],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const makeRoute = (endpoint: string, entrypoint: string) => {
|
|
||||||
injectRoute({
|
|
||||||
pattern: `/${endpoint}`,
|
|
||||||
entrypoint: `@matthiesenxyz/starlight-ghostcms/routes/${entrypoint}`,
|
|
||||||
prerender: true,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
makeRoute(`${config.route}`,
|
|
||||||
"index.astro");
|
|
||||||
makeRoute(`${config.route}/[slug]`,
|
|
||||||
"[slug].astro");
|
|
||||||
makeRoute(`${config.route}/about`,
|
|
||||||
"about.astro");
|
|
||||||
makeRoute(`${config.route}/authors`,
|
|
||||||
"authors.astro");
|
|
||||||
makeRoute("rss.xml",
|
|
||||||
"rss.xml.ts");
|
|
||||||
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function overrideRSS(
|
||||||
|
socials: StarlightUserConfig["social"],
|
||||||
|
url: string | undefined
|
||||||
|
) { if (socials?.rss) { return {}; }
|
||||||
|
if (url === undefined) { return undefined; }
|
||||||
|
return { rss: `${url}/rss.xml` };
|
||||||
|
}
|
||||||
|
|
||||||
|
function overrideTwitter(
|
||||||
|
socials: StarlightUserConfig["social"],
|
||||||
|
) { if (socials?.twitter) { return {}; }
|
||||||
|
if (settings?.twitter) {
|
||||||
|
return { twitter: twitter(settings.twitter), }
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function overrideFacebook(
|
||||||
|
socials: StarlightUserConfig["social"],
|
||||||
|
) { if (socials?.facebook) { return {}; }
|
||||||
|
if (settings?.facebook) {
|
||||||
|
return { facebook: facebook(settings.facebook), }
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function overrideStarlightComponent(
|
function overrideStarlightComponent(
|
||||||
components: StarlightUserConfig["components"],
|
components: StarlightUserConfig["components"],
|
||||||
logger: AstroIntegrationLogger,
|
logger: AstroIntegrationLogger,
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"@astrojs/rss": "^4.0.5",
|
"@astrojs/rss": "^4.0.5",
|
||||||
"@ts-ghost/core-api": "^6.0.0",
|
"@ts-ghost/core-api": "^6.0.0",
|
||||||
"@ts-ghost/content-api": "^4.0.12",
|
"@ts-ghost/content-api": "^4.0.12",
|
||||||
|
"astro-integration-kit": "^0.5.1",
|
||||||
"vite": "^5.1.5",
|
"vite": "^5.1.5",
|
||||||
"vite-tsconfig-paths": "^4.3.1"
|
"vite-tsconfig-paths": "^4.3.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import {
|
||||||
|
createResolver,
|
||||||
|
defineIntegration,
|
||||||
|
} from "astro-integration-kit";
|
||||||
|
import { corePlugins } from "astro-integration-kit/plugins";
|
||||||
|
import { z } from "astro/zod";
|
||||||
|
import { vitePluginStarlightGhostConfig } from "./vite";
|
||||||
|
import { type StarlightGhostConfig } from "../schemas/config";
|
||||||
|
|
||||||
|
export default defineIntegration({
|
||||||
|
name: "@matthiesenxyz/starlight-ghostcms",
|
||||||
|
optionsSchema: z.custom<StarlightGhostConfig>(),
|
||||||
|
plugins: [...corePlugins],
|
||||||
|
setup({ options }) {
|
||||||
|
const { resolve } = createResolver(import.meta.url);
|
||||||
|
|
||||||
|
return {
|
||||||
|
"astro:config:setup": ({ watchIntegration, updateConfig, injectRoute }) => {
|
||||||
|
watchIntegration(resolve());
|
||||||
|
|
||||||
|
updateConfig({
|
||||||
|
vite: {
|
||||||
|
plugins: [vitePluginStarlightGhostConfig(options)],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeRoute = (endpoint: string, entrypoint: string) => {
|
||||||
|
injectRoute({
|
||||||
|
pattern: `/${endpoint}`,
|
||||||
|
entrypoint: resolve(`../routes/${entrypoint}`),
|
||||||
|
prerender: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
makeRoute(`${options.route}`,
|
||||||
|
"index.astro");
|
||||||
|
makeRoute(`${options.route}/[slug]`,
|
||||||
|
"[slug].astro");
|
||||||
|
makeRoute(`${options.route}/about`,
|
||||||
|
"about.astro");
|
||||||
|
makeRoute(`${options.route}/authors`,
|
||||||
|
"authors.astro");
|
||||||
|
makeRoute("rss.xml",
|
||||||
|
"rss.xml.ts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,11 +1,8 @@
|
||||||
/// <reference types="vitest" />
|
/// <reference types="vitest" />
|
||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
import tsconfigPaths from "vite-tsconfig-paths";
|
|
||||||
import { defineProject } from "vitest/config";
|
import { defineProject } from "vitest/config";
|
||||||
|
|
||||||
export default defineProject({
|
export default defineProject({
|
||||||
plugins: [tsconfigPaths()],
|
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
include: ["./**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
include: ["./**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
||||||
|
|
|
@ -253,6 +253,9 @@ importers:
|
||||||
'@ts-ghost/core-api':
|
'@ts-ghost/core-api':
|
||||||
specifier: ^6.0.0
|
specifier: ^6.0.0
|
||||||
version: 6.0.0
|
version: 6.0.0
|
||||||
|
astro-integration-kit:
|
||||||
|
specifier: ^0.5.1
|
||||||
|
version: 0.5.1(astro@4.4.9)
|
||||||
vite:
|
vite:
|
||||||
specifier: ^5.1.5
|
specifier: ^5.1.5
|
||||||
version: 5.1.5(@types/node@20.11.24)
|
version: 5.1.5(@types/node@20.11.24)
|
||||||
|
|
Loading…
Reference in New Issue