diff --git a/packages/adapters/astro/src/index.mts b/packages/adapters/astro/src/index.mts index 3be6f6b3..82f83dc9 100644 --- a/packages/adapters/astro/src/index.mts +++ b/packages/adapters/astro/src/index.mts @@ -10,7 +10,7 @@ import { import { fileURLToPath } from 'node:url'; import { join } from 'path'; -export { getStaticPaths, getHomePage } from './pages.mjs'; +export { getStaticPaths, getIndexPage } from './pages.mjs'; export { integrationsPreset } from './preset.mjs'; type GalactiksOptions = { diff --git a/packages/adapters/astro/src/pages.mts b/packages/adapters/astro/src/pages.mts index 90467db5..4e8ad6f2 100644 --- a/packages/adapters/astro/src/pages.mts +++ b/packages/adapters/astro/src/pages.mts @@ -1,18 +1,18 @@ -import { getDefaultLanguage, getLanguages } from '@galactiks/config'; +import { getLanguages } from '@galactiks/config'; import { - getAllPagesExceptHome, - getHomePage as explorerGetHomePage, + getPages, + getIndexPage as explorerGetIndexPage, } from '@galactiks/explorer'; export async function getStaticPaths() { - return (await getAllPagesExceptHome({ inLanguages: getLanguages() })).map( - (page) => ({ + return (await getPages({ inLanguages: getLanguages() })) + .filter((_p) => _p.slug !== '') + .map((page) => ({ params: { path: page.path.slice(1) }, props: { page }, - }) - ); + })); } -export function getHomePage() { - return explorerGetHomePage({ inLanguage: getDefaultLanguage() }); +export function getIndexPage() { + return explorerGetIndexPage(); } diff --git a/packages/config/src/config.mts b/packages/config/src/config.mts index 73913568..a1c5522e 100644 --- a/packages/config/src/config.mts +++ b/packages/config/src/config.mts @@ -133,6 +133,10 @@ export function getDefaultLanguage(): string | undefined { return getConfig().locales?.default; } -export function getLanguages(): string[] | undefined { - return getConfig().locales?.available; +export function getLanguages(): string[] { + const locales = getConfig().locales; + + return typeof locales === 'object' + ? locales.available || [locales.default] + : []; } diff --git a/packages/explorer/src/core/content/repositories/index.mts b/packages/explorer/src/core/content/repositories/index.mts index ae24fac5..818bb9eb 100644 --- a/packages/explorer/src/core/content/repositories/index.mts +++ b/packages/explorer/src/core/content/repositories/index.mts @@ -5,6 +5,7 @@ import { createIdentifierFromString } from '../utils.mjs'; import type { RepositoryFilters } from './filters.mjs'; import { getOrganizations, getPages } from './generated.mjs'; +import { getDefaultLanguage, getLanguages } from '@galactiks/config'; export * from './generated.mjs'; @@ -50,26 +51,23 @@ export const getPageBySlug = async ( export const getOrganizationByIdentifier = async (identifier: string) => documentByIdentifierSelector(await getOrganizations())(identifier); -export const getAllPagesExceptHome = async ( - filters?: RepositoryFilters -): Promise => - (await getPages(filters)).filter( - ({ identifier }) => identifier !== homeIdentifier - ); - export type RepositoryHomeFilters = { inLanguage?: string; }; export const getHomePage = async ( filters?: RepositoryHomeFilters -): Promise => { - const homepageContent = await getPageByIdentifier( +): Promise => + getPageByIdentifier( homeIdentifier, filters?.inLanguage ? { inLanguages: [filters.inLanguage] } : undefined ); - if (!homepageContent) { - throw new Error('no content for homepage'); - } - return homepageContent; +export const getIndexPage = async (): Promise => { + const defaultLanguage = getDefaultLanguage(); + const languages = getLanguages(); + + const inLanguage = + defaultLanguage || (languages.length === 1 && languages[0]) || undefined; + + return getHomePage({ inLanguage }); };