diff --git a/.changeset/dry-roses-worry.md b/.changeset/dry-roses-worry.md deleted file mode 100644 index 70fd74e5..00000000 --- a/.changeset/dry-roses-worry.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"@galactiks/astro-integration": patch -"@galactiks/explorer": patch ---- - -Urls computation fixes diff --git a/packages/adapters/astro/CHANGELOG.md b/packages/adapters/astro/CHANGELOG.md index 5928098f..5b1c88d5 100644 --- a/packages/adapters/astro/CHANGELOG.md +++ b/packages/adapters/astro/CHANGELOG.md @@ -1,5 +1,14 @@ # @galactiks/astro-integration +## 0.2.11 + +### Patch Changes + +- [#110](https://github.com/thegalactiks/explorer/pull/110) [`60fab99`](https://github.com/thegalactiks/explorer/commit/60fab991cd234869cb7c7e0a06cb39df3d34d3dc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - Urls computation fixes + +- Updated dependencies [[`60fab99`](https://github.com/thegalactiks/explorer/commit/60fab991cd234869cb7c7e0a06cb39df3d34d3dc)]: + - @galactiks/explorer@0.2.10 + ## 0.2.10 ### Patch Changes diff --git a/packages/adapters/astro/package.json b/packages/adapters/astro/package.json index e3292e1b..cf1b953b 100644 --- a/packages/adapters/astro/package.json +++ b/packages/adapters/astro/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/astro-integration", - "version": "0.2.10", + "version": "0.2.11", "description": "Galactiks Astro integration", "author": "thegalactiks", "types": "./dist/index.d.ts", diff --git a/packages/adapters/astro/src/preset.mts b/packages/adapters/astro/src/preset.mts index 90a5e9dd..39551b9c 100644 --- a/packages/adapters/astro/src/preset.mts +++ b/packages/adapters/astro/src/preset.mts @@ -11,21 +11,21 @@ import { sitemapSerialize } from './sitemap.mjs'; export const integrationsPreset = (): AstroIntegration[] => { const defaultLanguage = getDefaultLanguage(); - return ([ + return [ react(), partytown(), sitemap({ i18n: defaultLanguage ? { - defaultLocale: defaultLanguage, - locales: Object.fromEntries( - getLanguages().map((lang) => [lang, lang]) - ), - } + defaultLocale: defaultLanguage, + locales: Object.fromEntries( + getLanguages().map((lang) => [lang, lang]) + ), + } : undefined, serialize: sitemapSerialize(defaultLanguage), }), robotsTxt(), critters(), - ]); + ]; }; diff --git a/packages/adapters/astro/src/sitemap.mts b/packages/adapters/astro/src/sitemap.mts index b71ff6ab..b6f595ba 100644 --- a/packages/adapters/astro/src/sitemap.mts +++ b/packages/adapters/astro/src/sitemap.mts @@ -4,36 +4,37 @@ import { getPageByURL } from '@galactiks/explorer'; import { isValid } from 'date-fns'; import Debug from 'debug'; -const debug = Debug('@galactiks/astro-integration:sitemap') +const debug = Debug('@galactiks/astro-integration:sitemap'); -export const sitemapSerialize = (defaultLanguage?: string) => async (item: SitemapItem) => { - debug('serializing item', item); +export const sitemapSerialize = + (defaultLanguage?: string) => async (item: SitemapItem) => { + debug('serializing item', item); - const page = await getPageByURL(item.url); - if (!page) { - debug('page not found for the item', item); + const page = await getPageByURL(item.url); + if (!page) { + debug('page not found for the item', item); - return undefined; - } + return undefined; + } - return { - url: page.url, - lastmod: isValid(page.dateModified) - ? page.dateModified.toISOString() - : undefined, - news: page.type === 'Article' && { - publication: { - name: getConfig().webManifest.name, - language: (page.inLanguage || defaultLanguage) - ?.substring(0, 2) - .toLowerCase(), - }, - - publication_date: isValid(page.datePublished) - ? page.datePublished.toISOString() + return { + url: page.url, + lastmod: isValid(page.dateModified) + ? page.dateModified.toISOString() : undefined, - title: page.name, - keywords: page.keywords?.join(', '), - }, + news: page.type === 'Article' && { + publication: { + name: getConfig().webManifest.name, + language: (page.inLanguage || defaultLanguage) + ?.substring(0, 2) + .toLowerCase(), + }, + + publication_date: isValid(page.datePublished) + ? page.datePublished.toISOString() + : undefined, + title: page.name, + keywords: page.keywords?.join(', '), + }, + }; }; -}; diff --git a/packages/explorer/CHANGELOG.md b/packages/explorer/CHANGELOG.md index 39024e32..1d6c40a9 100644 --- a/packages/explorer/CHANGELOG.md +++ b/packages/explorer/CHANGELOG.md @@ -1,5 +1,11 @@ # @galactiks/explorer +## 0.2.10 + +### Patch Changes + +- [#110](https://github.com/thegalactiks/explorer/pull/110) [`60fab99`](https://github.com/thegalactiks/explorer/commit/60fab991cd234869cb7c7e0a06cb39df3d34d3dc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - Urls computation fixes + ## 0.2.9 ### Patch Changes diff --git a/packages/explorer/package.json b/packages/explorer/package.json index 6fa8eabd..89553739 100644 --- a/packages/explorer/package.json +++ b/packages/explorer/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/explorer", - "version": "0.2.9", + "version": "0.2.10", "description": "Ensure Galactiks content model consistence, explore content built with ContentLayer and create dynamically missing pages and fields for SEO purposes", "author": "thegalactiks", "type": "module", diff --git a/packages/explorer/src/core/content/urls.mts b/packages/explorer/src/core/content/urls.mts index aaed641a..40b7168e 100644 --- a/packages/explorer/src/core/content/urls.mts +++ b/packages/explorer/src/core/content/urls.mts @@ -2,7 +2,7 @@ import { StdUriTemplate } from '@std-uritemplate/std-uritemplate'; import { getConfig } from '@galactiks/config'; import { documentTypes } from '@galactiks/contentlayer'; import { join } from 'path'; -import Debug from 'debug' +import Debug from 'debug'; import { homeIdentifier } from './consts.mjs'; import { @@ -43,110 +43,113 @@ const makePathRelative = (path: string) => export const computeDocumentsUrl = (websites: ContentlayerWebsite[]) => - async (documents: ContentlayerWebPageDocumentWithRender[]) => { - const getDocumentByIdentifierAndLanguage = - documentByIdentifierAndLanguageSelector(documents); - const getWebsitesByLanguage = documentsByLanguageSelector(websites); - - const { locales, pages, webManifest } = getConfig(); - - const _getPagePathTemplate = ( - type: ContentlayerWebPageDocument['type'], - inLanguage?: string - ) => { - const page = pages[documentTypes[type]] || pages[documentTypes.Page]; - if (!page) { - return undefined; - } - - if (typeof page.path === 'string') { - return page.path; - } - - return page.path.find( - ({ locale }) => locale === inLanguage || locale === locales?.default - )?.path; - }; - - const _getDocumentUrl = ( - document: ContentlayerWebPageDocument, path: string - ): string => { - if (document.url) { - return document.url; - } + async (documents: ContentlayerWebPageDocumentWithRender[]) => { + const getDocumentByIdentifierAndLanguage = + documentByIdentifierAndLanguageSelector(documents); + const getWebsitesByLanguage = documentsByLanguageSelector(websites); + + const { locales, pages, webManifest } = getConfig(); + + const _getPagePathTemplate = ( + type: ContentlayerWebPageDocument['type'], + inLanguage?: string + ) => { + const page = pages[documentTypes[type]] || pages[documentTypes.Page]; + if (!page) { + return undefined; + } + + if (typeof page.path === 'string') { + return page.path; + } + + return page.path.find( + ({ locale }) => locale === inLanguage || locale === locales?.default + )?.path; + }; - let baseUrl = webManifest.start_url; - if (websites.length === 1 && websites[0].url) { - baseUrl = websites[0].url; - } else if (websites.length > 1 && document.inLanguage) { - const websitesByLanguage = getWebsitesByLanguage(document.inLanguage); - if (websitesByLanguage.length === 1 && websitesByLanguage[0].url) { - baseUrl = websitesByLanguage[0].url; - } + const _getDocumentUrl = ( + document: ContentlayerWebPageDocument, + path: string + ): string => { + if (document.url) { + return document.url; + } + + let baseUrl = webManifest.start_url; + if (websites.length === 1 && websites[0].url) { + baseUrl = websites[0].url; + } else if (websites.length > 1 && document.inLanguage) { + const websitesByLanguage = getWebsitesByLanguage(document.inLanguage); + if (websitesByLanguage.length === 1 && websitesByLanguage[0].url) { + baseUrl = websitesByLanguage[0].url; } + } - return new URL(path, baseUrl).toString(); - }; - - const _computePath = ( - document: ContentlayerWebPageDocument - ): string | undefined => { - if (document.path) { - return join('/', document.path); - } + return new URL(path, baseUrl).toString(); + }; - const pathTemplate = _getPagePathTemplate( - document.type, + const _computePath = ( + document: ContentlayerWebPageDocument + ): string | undefined => { + if (document.path) { + return join('/', document.path); + } + + const pathTemplate = _getPagePathTemplate( + document.type, + document.inLanguage + ); + if (!pathTemplate) { + return undefined; + } + + let isPartOfPath: string | undefined; + if (pathTemplate.indexOf('isPartOf') && document.isPartOf) { + // The page has been created if missing + const isPartOf = getDocumentByIdentifierAndLanguage( + document.isPartOf, document.inLanguage ); - if (!pathTemplate) { - return undefined; - } + isPartOfPath = + (isPartOf && makePathRelative(_getPathWithoutTemplate(isPartOf))) || + ''; + } + + const existingStringProperties: [string, string][] = Object.entries({ + ...document, + identifier: + document.identifier !== homeIdentifier ? document.identifier : '', + isPartOf: isPartOfPath, + }).filter(([, value]) => typeof value === 'string'); + return join( + StdUriTemplate.expand( + pathTemplate, + Object.fromEntries(existingStringProperties) + ) + ); + }; - let isPartOfPath: string | undefined; - if (pathTemplate.indexOf('isPartOf') && document.isPartOf) { - // The page has been created if missing - const isPartOf = getDocumentByIdentifierAndLanguage( - document.isPartOf, - document.inLanguage - ); - isPartOfPath = (isPartOf && makePathRelative(_getPathWithoutTemplate(isPartOf))) || ''; + const selectPageDepth = pageDepthSelector(documents); + return documents + .sort((_document) => selectPageDepth(_document)) + .map((_document) => { + const path = _document.path || _computePath(_document); + let url: string | undefined = undefined; + if (path) { + url = _getDocumentUrl(_document, path); } - const existingStringProperties: [string, string][] = Object.entries({ - ...document, - identifier: - document.identifier !== homeIdentifier ? document.identifier : '', - isPartOf: isPartOfPath, - }).filter(([, value]) => typeof value === 'string'); - return join( - StdUriTemplate.expand( - pathTemplate, - Object.fromEntries(existingStringProperties) - ) - ); - }; - - const selectPageDepth = pageDepthSelector(documents); - return documents - .sort((_document) => selectPageDepth(_document)) - .map((_document) => { - const path = _document.path || _computePath(_document); - let url: string | undefined = undefined; - if (path) { - url = _getDocumentUrl(_document, path); - } - - const _computed = { - ..._document, - url, - path, - } as ContentlayerWebPageDocumentWithRender & - ContentlayerDocumentWithURL; - - debug('computing document url', _computed); - - return _computed; - }) - .filter((_document) => _document.path); - }; + const _computed = { + ..._document, + url, + path, + } as ContentlayerWebPageDocumentWithRender & + ContentlayerDocumentWithURL; + + debug('computing document url', _computed); + + return _computed; + }) + .filter((_document) => _document.path); + };