From 2045a7ccdb2c2e2eb145b42d2fe1561562850b9f Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Sun, 24 Sep 2023 20:27:21 +0200 Subject: [PATCH] feat(@galactiks/astro-integration): add sitemap news support --- packages/adapters/astro/package.json | 3 +- packages/adapters/astro/src/preset.mts | 33 ++++++++++++- pnpm-lock.yaml | 66 +++++++++++++++----------- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/packages/adapters/astro/package.json b/packages/adapters/astro/package.json index cc2e5d14..860a6cde 100644 --- a/packages/adapters/astro/package.json +++ b/packages/adapters/astro/package.json @@ -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", diff --git a/packages/adapters/astro/src/preset.mts b/packages/adapters/astro/src/preset.mts index 0b2d0e05..b632eec6 100644 --- a/packages/adapters/astro/src/preset.mts +++ b/packages/adapters/astro/src/preset.mts @@ -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(), ]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2489406c..65b39b4a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,5 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: false - excludeLinksFromLockfile: false - overrides: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0 @@ -65,6 +61,9 @@ importers: '@galactiks/explorer': specifier: workspace:^ version: link:../../explorer + date-fns: + specifier: 2.30.0 + version: 2.30.0 devDependencies: '@astrojs/partytown': specifier: 2.0.1 @@ -875,10 +874,10 @@ packages: resolution: {integrity: sha512-47gAg0O2pW5Jlo86jfzjdkwL5a7Bzb+Kj5WTmdu4CxYRfWn9ytKjuuYIfsNDW8neuhdKzn+P5wCddgEh0glYyQ==} peerDependencies: '@effect-ts/core': ^0.60.2 - '@opentelemetry/api': 1.4.1 - '@opentelemetry/core': 1.13.0 - '@opentelemetry/exporter-trace-otlp-grpc': 0.39.1 - '@opentelemetry/sdk-trace-base': 1.13.0 + '@opentelemetry/api': ^1.4.0 + '@opentelemetry/core': ^1.13.0 + '@opentelemetry/exporter-trace-otlp-grpc': ^0.39.0 + '@opentelemetry/sdk-trace-base': ^1.13.0 dependencies: '@effect-ts/core': 0.60.5 '@effect-ts/otel': 0.15.1(@effect-ts/core@0.60.5)(@opentelemetry/api@1.4.1)(@opentelemetry/core@1.13.0)(@opentelemetry/sdk-trace-base@1.13.0) @@ -892,10 +891,10 @@ packages: resolution: {integrity: sha512-a2sF0ylmn8xOJs8fNeT/spJ1gUcsksAJCALxo9WOfuTCMtTwMVtVhCKEPEeQoL7wFqU+JgPkVdP91+FJ/Rkeow==} peerDependencies: '@effect-ts/core': ^0.60.2 - '@opentelemetry/api': 1.4.1 - '@opentelemetry/core': 1.13.0 - '@opentelemetry/sdk-trace-base': 1.13.0 - '@opentelemetry/sdk-trace-node': 1.13.0 + '@opentelemetry/api': ^1.4.0 + '@opentelemetry/core': ^1.13.0 + '@opentelemetry/sdk-trace-base': ^1.13.0 + '@opentelemetry/sdk-trace-node': ^1.13.0 dependencies: '@effect-ts/core': 0.60.5 '@effect-ts/otel': 0.15.1(@effect-ts/core@0.60.5)(@opentelemetry/api@1.4.1)(@opentelemetry/core@1.13.0)(@opentelemetry/sdk-trace-base@1.13.0) @@ -909,9 +908,9 @@ packages: resolution: {integrity: sha512-AmZJHl7t0+Peh7Yb2+hqn6r9+rd9/UfeA4AMV9h0YGTdOyouyFfD3wzWlxnAUzAQ4Lrod4kC7Noruret4EpqpA==} peerDependencies: '@effect-ts/core': ^0.60.2 - '@opentelemetry/api': 1.4.1 - '@opentelemetry/core': 1.13.0 - '@opentelemetry/sdk-trace-base': 1.13.0 + '@opentelemetry/api': ^1.4.0 + '@opentelemetry/core': ^1.13.0 + '@opentelemetry/sdk-trace-base': ^1.13.0 dependencies: '@effect-ts/core': 0.60.5 '@opentelemetry/api': 1.4.1 @@ -1553,7 +1552,7 @@ packages: resolution: {integrity: sha512-pS5fU4lrRjOIPZQqA2V1SUM9QUFXbO+8flubAiy6ntLjnAjJJUdRFOUOxK6v86ZHI2p2S8A0vD0BTu95FZYvjA==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 dev: true @@ -1562,7 +1561,7 @@ packages: resolution: {integrity: sha512-2dBX3Sj99H96uwJKvc2w9NOiNgbvAO6mOFJFramNkKfS9O4Um+VWgpnlAazoYjT6kUJ1MP70KQ5ngD4ed+4NUw==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/semantic-conventions': 1.13.0 @@ -1572,7 +1571,7 @@ packages: resolution: {integrity: sha512-l5RhLKx6U+yuLhMrtgavTDthX50E1mZM3/SSySC7OPZiArFHV/b/9x9jxAzrOgIQUDxyj4N0V9aLKSA2t7Qzxg==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': ^1.0.0 dependencies: '@grpc/grpc-js': 1.8.18 '@opentelemetry/api': 1.4.1 @@ -1587,7 +1586,7 @@ packages: resolution: {integrity: sha512-Pv5X8fbi6jD/RJBePyn7MnCSuE6MbPB6dl+7YYBWJ5RcMGYMwvLXjd4h2jWsPV2TSUg38H/RoSP0aXvQ06Y7iw==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': ^1.0.0 dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1597,7 +1596,7 @@ packages: resolution: {integrity: sha512-u3ErFRQqQFKjjIMuwLWxz/tLPYInfmiAmSy//fGSCzCh2ZdJgqQjMOAxBgqFtCF2xFL+OmMhyuC2ThMzceGRWA==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': ^1.0.0 dependencies: '@grpc/grpc-js': 1.8.18 '@opentelemetry/api': 1.4.1 @@ -1610,7 +1609,7 @@ packages: resolution: {integrity: sha512-0hgVnXXz5efI382B/24NxD4b6Zxlh7nxCdJkxkdmQMbn0yRiwoq/ZT+QG8eUL6JNzsBAV1WJlF5aJNsL8skHvw==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.3.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/api-logs': 0.39.1 @@ -1625,7 +1624,7 @@ packages: resolution: {integrity: sha512-HOo91EI4UbuG8xQVLFziTzrcIn0MJQhy8m9jorh8aonb94jFVFi3CFNIiAnIGOabmnshJLOABxpYXsiPB8Xnzg==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1635,7 +1634,7 @@ packages: resolution: {integrity: sha512-IV9TO+u1Jzm9mUDAD3gyXf89eyvgEJUY1t+GB5QmS4wjVeWrSMUtD0JjH3yG9SNqkrQOqOGJq7YUSSetW+Lf5Q==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1645,7 +1644,7 @@ packages: resolution: {integrity: sha512-euqjOkiN6xhjE//0vQYGvbStxoD/WWQRhDiO0OTLlnLBO9Yw2Gd/VoSx2H+svsebjzYk5OxLuREBmcdw6rbUNg==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1656,7 +1655,7 @@ packages: resolution: {integrity: sha512-/gmgKfZ1ZVFporKuwsewqIyvaUIGpv76JZ7lBpHQQPb37IMpaXO6pdqFI4ebHAWfNIm3akMyhmdtzivcgF3lgw==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.4.0 <1.5.0' '@opentelemetry/api-logs': '>=0.38.0' dependencies: '@opentelemetry/api': 1.4.1 @@ -1669,7 +1668,7 @@ packages: resolution: {integrity: sha512-MOjZX6AnSOqLliCcZUrb+DQKjAWXBiGeICGbHAGe5w0BB18PJIeIo995lO5JSaFfHpmUMgJButTPfJJD27W3Vg==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.3.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1681,7 +1680,7 @@ packages: resolution: {integrity: sha512-moTiQtc0uPR1hQLt6gLDJH9IIkeBhgRb71OKjNHZPE1VF45fHtD6nBDi5J/DkTHTwYP5X3kBJLa3xN7ub6J4eg==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/core': 1.13.0(@opentelemetry/api@1.4.1) @@ -1693,7 +1692,7 @@ packages: resolution: {integrity: sha512-FXA85lXKTsnbOflA/TBuBf2pmhD3c8uDjNjG0YqK+ap8UayfALmfJhf+aG1yBOUHevCY0JXJ4/xtbXExxpsMog==} engines: {node: '>=14'} peerDependencies: - '@opentelemetry/api': 1.4.1 + '@opentelemetry/api': '>=1.0.0 <1.5.0' dependencies: '@opentelemetry/api': 1.4.1 '@opentelemetry/context-async-hooks': 1.13.0(@opentelemetry/api@1.4.1) @@ -2836,6 +2835,13 @@ packages: resolution: {integrity: sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw==} dev: true + /date-fns@2.30.0: + resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==} + engines: {node: '>=0.11'} + dependencies: + '@babel/runtime': 7.22.5 + dev: false + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: @@ -7598,3 +7604,7 @@ packages: /zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} + +settings: + autoInstallPeers: false + excludeLinksFromLockfile: false