Skip to content

Commit

Permalink
feat(@galactiks/astro-integration): add sitemap news support
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Oct 25, 2023
1 parent 27d93b3 commit 2045a7c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
3 changes: 2 additions & 1 deletion packages/adapters/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
],
"dependencies": {
"@galactiks/config": "workspace:^",
"@galactiks/explorer": "workspace:^"
"@galactiks/explorer": "workspace:^",
"date-fns": "2.30.0"
},
"peerDependencies": {
"@astrojs/partytown": "2.0.1",
Expand Down
33 changes: 32 additions & 1 deletion packages/adapters/astro/src/preset.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,45 @@ import partytown from '@astrojs/partytown';
import prefetch from '@astrojs/prefetch';
import react from '@astrojs/react';
import sitemap from '@astrojs/sitemap';
import { getConfig, getDefaultLanguage, getLanguages } from '@galactiks/config';
import { getPageByURL } from '@galactiks/explorer';
import critters from 'astro-critters';
import robotsTxt from 'astro-robots-txt';
import { isValid } from 'date-fns';

const defaultLocale = getDefaultLanguage();

export const integrationsPreset = (): AstroIntegration[] => [
react(),
partytown(),
prefetch(),
sitemap(),
sitemap({
i18n: defaultLocale ? {
defaultLocale,
locales: Object.fromEntries(getLanguages().map(lang => ([lang, lang])))
} : undefined,
serialize: async (item) => {
const page = await getPageByURL(item.url);
if (!page) {
return item;
}

return ({
url: page.url,
lastmod: isValid(page.dateModified) ? page.dateModified.toISOString() : undefined,
news: page.type === 'Article' && {
publication: {
name: getConfig().webManifest.name,
language: getDefaultLanguage(),
},

publication_date: isValid(page.datePublished) ? page.datePublished.toISOString() : undefined,
title: page.name,
keywords: page.keywords?.join(', '),
},
});
}
}),
robotsTxt(),
critters(),
];
66 changes: 38 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2045a7c

Please sign in to comment.