diff --git a/.changeset/quick-adults-jog.md b/.changeset/quick-adults-jog.md deleted file mode 100644 index 9bb7ca5f..00000000 --- a/.changeset/quick-adults-jog.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"@galactiks/sitemap": minor -"@galactiks/astro-integration": patch -"@galactiks/config": patch -"@galactiks/explorer": patch ---- - -sitemap dedicated package and minor fixes diff --git a/examples/astro/.eslintrc.cjs b/examples/astro/.eslintrc.cjs index fc46622b..ef941fa1 100644 --- a/examples/astro/.eslintrc.cjs +++ b/examples/astro/.eslintrc.cjs @@ -1,12 +1,12 @@ module.exports = { - extends: ["plugin:astro/recommended", "plugin:jsx-a11y/recommended"], + extends: ['plugin:astro/recommended', 'plugin:jsx-a11y/recommended'], overrides: [ { - files: ["*.astro"], - parser: "astro-eslint-parser", + files: ['*.astro'], + parser: 'astro-eslint-parser', parserOptions: { - parser: "@typescript-eslint/parser", - extraFileExtensions: [".astro"], + parser: '@typescript-eslint/parser', + extraFileExtensions: ['.astro'], }, rules: {}, }, diff --git a/examples/astro/astro.config.mjs b/examples/astro/astro.config.mjs index 57a62c60..c01f03c7 100644 --- a/examples/astro/astro.config.mjs +++ b/examples/astro/astro.config.mjs @@ -1,9 +1,6 @@ -import galactiks, { integrationsPreset } from "@galactiks/astro-integration"; +import galactiks, { integrationsPreset } from '@galactiks/astro-integration'; // https://astro.build/config export default /** @type {import('astro').AstroUserConfig} */ { - integrations: [ - integrationsPreset(), - galactiks(), - ], + integrations: [integrationsPreset(), galactiks()], }; diff --git a/examples/astro/src/components/Picture.astro b/examples/astro/src/components/Picture.astro index 3a876bb6..7b8e6a7d 100644 --- a/examples/astro/src/components/Picture.astro +++ b/examples/astro/src/components/Picture.astro @@ -1,23 +1,23 @@ --- -import type { ComponentProps } from "astro/types"; -import { Picture as AstroPicture } from "astro:assets"; -import { join } from "path"; +import type { ComponentProps } from 'astro/types'; +import { Picture as AstroPicture } from 'astro:assets'; +import { join } from 'path'; type Props = ComponentProps & { src: string; }; -const prefix = "/src/assets"; +const prefix = '/src/assets'; const { src, - formats = ["avif", "webp"], - quality = "mid", + formats = ['avif', 'webp'], + quality = 'mid', widths = [200, 450, 900, 1250], ...props } = Astro.props; const images = import.meta.glob<{ default: ImageMetadata }>( - "/src/assets/**/*.{webp,jpeg,jpg,png,svg,gif,avif}" + '/src/assets/**/*.{webp,jpeg,jpg,png,svg,gif,avif}' ); const srcPath = join(prefix, src.replace(/^\/assets\//, '')); if (!images[srcPath]) { diff --git a/examples/astro/src/pages/[...path].astro b/examples/astro/src/pages/[...path].astro index 74c97a3b..10d3b46e 100644 --- a/examples/astro/src/pages/[...path].astro +++ b/examples/astro/src/pages/[...path].astro @@ -1,18 +1,18 @@ --- -import type { Content } from "@galactiks/explorer"; +import type { Content } from '@galactiks/explorer'; -import ArticleList from "@components/ArticlesList.astro"; -import ArticleLayout from "@layouts/ArticleLayout.astro"; -import PageLayout from "@layouts/PageLayout.astro"; +import ArticleList from '@components/ArticlesList.astro'; +import ArticleLayout from '@layouts/ArticleLayout.astro'; +import PageLayout from '@layouts/PageLayout.astro'; -export { getStaticPaths } from "@galactiks/astro-integration"; +export { getStaticPaths } from '@galactiks/astro-integration'; type Props = { page: Content }; const { page } = Astro.props; const { Content } = page.body.render(); -const Layout = page.type === "Article" ? ArticleLayout : PageLayout; +const Layout = page.type === 'Article' ? ArticleLayout : PageLayout; --- diff --git a/examples/astro/src/pages/index.astro b/examples/astro/src/pages/index.astro index 6188b765..999c5254 100644 --- a/examples/astro/src/pages/index.astro +++ b/examples/astro/src/pages/index.astro @@ -1,7 +1,7 @@ --- -import { type Content, getIndexPage } from "@galactiks/astro-integration"; +import { type Content, getIndexPage } from '@galactiks/astro-integration'; -import PageLayout from "@layouts/PageLayout.astro"; +import PageLayout from '@layouts/PageLayout.astro'; type Props = { page: Content }; @@ -11,7 +11,7 @@ const { Content } = page.body.render();
-
+
diff --git a/examples/astro/src/pages/rss.xml.ts b/examples/astro/src/pages/rss.xml.ts index 071449c1..4978db40 100644 --- a/examples/astro/src/pages/rss.xml.ts +++ b/examples/astro/src/pages/rss.xml.ts @@ -1,3 +1,3 @@ -import { getRSS } from "@galactiks/astro-integration"; +import { getRSS } from '@galactiks/astro-integration'; export const GET = getRSS; diff --git a/packages/adapters/astro/CHANGELOG.md b/packages/adapters/astro/CHANGELOG.md index 498a61f9..6a501d15 100644 --- a/packages/adapters/astro/CHANGELOG.md +++ b/packages/adapters/astro/CHANGELOG.md @@ -1,5 +1,16 @@ # @galactiks/astro-integration +## 0.3.6 + +### Patch Changes + +- [`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - sitemap dedicated package and minor fixes + +- Updated dependencies [[`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc)]: + - @galactiks/sitemap@0.1.0 + - @galactiks/config@0.3.2 + - @galactiks/explorer@0.3.5 + ## 0.3.5 ### Patch Changes diff --git a/packages/adapters/astro/package.json b/packages/adapters/astro/package.json index 9172107a..447a63a6 100644 --- a/packages/adapters/astro/package.json +++ b/packages/adapters/astro/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/astro-integration", - "version": "0.3.5", + "version": "0.3.6", "description": "Galactiks Astro integration", "author": "thegalactiks", "type": "module", diff --git a/packages/adapters/astro/src/index.ts b/packages/adapters/astro/src/index.ts index 5ffa5182..bb36ad91 100644 --- a/packages/adapters/astro/src/index.ts +++ b/packages/adapters/astro/src/index.ts @@ -55,7 +55,8 @@ export default function createPlugin( }) => { let trailingSlash = config.trailingSlash; if (trailingSlash === 'ignore') { - trailingSlash = config.build.format === 'directory' ? 'always' : 'never'; + trailingSlash = + config.build.format === 'directory' ? 'always' : 'never'; } setConfig('trailingSlash', config.trailingSlash); diff --git a/packages/adapters/astro/src/pages.ts b/packages/adapters/astro/src/pages.ts index 5b29a298..29c0e0bc 100644 --- a/packages/adapters/astro/src/pages.ts +++ b/packages/adapters/astro/src/pages.ts @@ -7,10 +7,12 @@ import { export async function getStaticPaths() { return (await getPages({ inLanguages: getLanguages() })) .map((page) => ({ - params: { path: page.path.endsWith('/') ? page.path.slice(0, -1) : page.path }, + params: { + path: page.path.endsWith('/') ? page.path.slice(0, -1) : page.path, + }, props: { page }, })) - .filter(page => page.params.path && page.params.path !== '/'); + .filter((page) => page.params.path && page.params.path !== '/'); } export function getIndexPage() { diff --git a/packages/adapters/astro/src/plugins/sitemap.ts b/packages/adapters/astro/src/plugins/sitemap.ts index f527b11b..5fe74771 100644 --- a/packages/adapters/astro/src/plugins/sitemap.ts +++ b/packages/adapters/astro/src/plugins/sitemap.ts @@ -36,14 +36,13 @@ const createPlugin = (): AstroIntegration => { return; } - let pageUrls = pages - .map((p) => { - if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/')) - finalSiteUrl.pathname += '/'; - if (p.pathname.startsWith('/')) p.pathname = p.pathname.slice(1); - const fullPath = finalSiteUrl.pathname + p.pathname; - return new URL(fullPath, finalSiteUrl).href; - }); + let pageUrls = pages.map((p) => { + if (p.pathname !== '' && !finalSiteUrl.pathname.endsWith('/')) + finalSiteUrl.pathname += '/'; + if (p.pathname.startsWith('/')) p.pathname = p.pathname.slice(1); + const fullPath = finalSiteUrl.pathname + p.pathname; + return new URL(fullPath, finalSiteUrl).href; + }); const routeUrls = routes.reduce((urls, r) => { if (r.type !== 'page') return urls; @@ -55,14 +54,18 @@ const createPlugin = (): AstroIntegration => { // `finalSiteUrl` may end with a trailing slash // or not because of base paths. let fullPath = finalSiteUrl.pathname; - if (fullPath.endsWith('/')) fullPath += r.generate(r.pathname).substring(1); + if (fullPath.endsWith('/')) + fullPath += r.generate(r.pathname).substring(1); else fullPath += r.generate(r.pathname); const newUrl = new URL(fullPath, finalSiteUrl).href; if (config.trailingSlash === 'never') { urls.push(newUrl); - } else if (config.build.format === 'directory' && !newUrl.endsWith('/')) { + } else if ( + config.build.format === 'directory' && + !newUrl.endsWith('/') + ) { urls.push(newUrl + '/'); } else { urls.push(newUrl); @@ -77,12 +80,12 @@ const createPlugin = (): AstroIntegration => { logger.info(pageUrls.join('\n')); const contentPages = ( - await Promise.all( - pageUrls.map(getPageByURL) - ) + await Promise.all(pageUrls.map(getPageByURL)) ).filter((page) => page !== undefined) as Content[]; if (contentPages.length === 0) { - logger.warn(`No pages found!\n\`${sitemapIndexOutput}\` not created.`); + logger.warn( + `No pages found!\n\`${sitemapIndexOutput}\` not created.` + ); return; } @@ -103,7 +106,9 @@ const createPlugin = (): AstroIntegration => { // limit: entryLimit, // gzip: false, // }); - logger.info(`\`${sitemapIndexOutput}\` created at \`${path.relative(process.cwd(), destDir)}\``); + logger.info( + `\`${sitemapIndexOutput}\` created at \`${path.relative(process.cwd(), destDir)}\`` + ); }, }, }; diff --git a/packages/adapters/astro/src/preset.ts b/packages/adapters/astro/src/preset.ts index 3d8fe5c7..0c2758d7 100644 --- a/packages/adapters/astro/src/preset.ts +++ b/packages/adapters/astro/src/preset.ts @@ -6,10 +6,5 @@ import robotsTxt from 'astro-robots-txt'; import sitemap from './plugins/sitemap.js'; export const integrationsPreset = (): AstroIntegration[] => { - return [ - react(), - partytown(), - sitemap(), - robotsTxt(), - ]; + return [react(), partytown(), sitemap(), robotsTxt()]; }; diff --git a/packages/config/CHANGELOG.md b/packages/config/CHANGELOG.md index 21ebf1c5..27906b43 100644 --- a/packages/config/CHANGELOG.md +++ b/packages/config/CHANGELOG.md @@ -1,5 +1,11 @@ # @galactiks/config +## 0.3.2 + +### Patch Changes + +- [`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - sitemap dedicated package and minor fixes + ## 0.3.1 ### Patch Changes diff --git a/packages/config/package.json b/packages/config/package.json index 03fc65c5..7230081e 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/config", - "version": "0.3.1", + "version": "0.3.2", "description": "Reading Galactiks configurations files and get config during website generation", "author": "thegalactiks", "type": "module", diff --git a/packages/explorer/CHANGELOG.md b/packages/explorer/CHANGELOG.md index ff9b807d..b4f37340 100644 --- a/packages/explorer/CHANGELOG.md +++ b/packages/explorer/CHANGELOG.md @@ -1,5 +1,14 @@ # @galactiks/explorer +## 0.3.5 + +### Patch Changes + +- [`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - sitemap dedicated package and minor fixes + +- Updated dependencies [[`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc)]: + - @galactiks/config@0.3.2 + ## 0.3.4 ### Patch Changes diff --git a/packages/explorer/package.json b/packages/explorer/package.json index ef126aaa..cd3de93d 100644 --- a/packages/explorer/package.json +++ b/packages/explorer/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/explorer", - "version": "0.3.4", + "version": "0.3.5", "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/content/hydrate/urls.ts b/packages/explorer/src/content/hydrate/urls.ts index 10c5dc08..b02c67d4 100644 --- a/packages/explorer/src/content/hydrate/urls.ts +++ b/packages/explorer/src/content/hydrate/urls.ts @@ -142,27 +142,32 @@ export const computeDocumentsUrl = const selectPageDepth = pageDepthSelector(documents); return documents .sort((_document) => selectPageDepth(_document)) - .reduce((acc, _document) => { - let path = _computePath(_document); - if (!path) { - return acc; - } - - if (trailingSlash === 'always') { - path = addMissingTrailingSlash(path); - } else if (trailingSlash === 'never') { - path = removeTrailingSlash(path); - } - - const _computed = { - ..._document, - url: _getDocumentUrl(_document, path), - path, - } as ContentlayerWebPageDocumentWithRender & - ContentlayerDocumentWithURL; - - debug('computing document url', _computed); - - return [...acc, _computed]; - }, [] as Array); + .reduce( + (acc, _document) => { + let path = _computePath(_document); + if (!path) { + return acc; + } + + if (trailingSlash === 'always') { + path = addMissingTrailingSlash(path); + } else if (trailingSlash === 'never') { + path = removeTrailingSlash(path); + } + + const _computed = { + ..._document, + url: _getDocumentUrl(_document, path), + path, + } as ContentlayerWebPageDocumentWithRender & + ContentlayerDocumentWithURL; + + debug('computing document url', _computed); + + return [...acc, _computed]; + }, + [] as Array< + ContentlayerDocumentWithURL & ContentlayerWebPageDocumentWithRender + > + ); }; diff --git a/packages/explorer/src/content/metadata/schemas/product.ts b/packages/explorer/src/content/metadata/schemas/product.ts index 057918af..44c5102e 100644 --- a/packages/explorer/src/content/metadata/schemas/product.ts +++ b/packages/explorer/src/content/metadata/schemas/product.ts @@ -1,17 +1,22 @@ import type { Offer, Product, WithContext } from 'schema-dts'; import type { ContentlayerProduct } from '../../../types/index.js'; -const getOffers = (offers: ContentlayerProduct['offers']): WithContext[] => Array.isArray(offers) - ? offers.map((offer) => ({ - '@context': 'https://schema.org', - '@type': 'Offer', - price: offer.price, - priceCurrency: offer.priceCurrency, - url: offer.url, - })) - : []; +const getOffers = ( + offers: ContentlayerProduct['offers'] +): WithContext[] => + Array.isArray(offers) + ? offers.map((offer) => ({ + '@context': 'https://schema.org', + '@type': 'Offer', + price: offer.price, + priceCurrency: offer.priceCurrency, + url: offer.url, + })) + : []; -export const getProduct = (document: ContentlayerProduct): WithContext => ({ +export const getProduct = ( + document: ContentlayerProduct +): WithContext => ({ '@context': 'https://schema.org', '@type': 'Product', name: document.name, diff --git a/packages/explorer/src/content/metadata/schemas/structured-data.ts b/packages/explorer/src/content/metadata/schemas/structured-data.ts index 6eadb758..7454bd0f 100644 --- a/packages/explorer/src/content/metadata/schemas/structured-data.ts +++ b/packages/explorer/src/content/metadata/schemas/structured-data.ts @@ -14,7 +14,9 @@ export const getStructuredDataSchemas = (document: Content) => { break; case 'Product': - schemas = schemas.concat(getProduct(document as unknown as ContentlayerProduct)); + schemas = schemas.concat( + getProduct(document as unknown as ContentlayerProduct) + ); break; } diff --git a/packages/explorer/src/content/repositories/index.ts b/packages/explorer/src/content/repositories/index.ts index 7e49f140..344d926b 100644 --- a/packages/explorer/src/content/repositories/index.ts +++ b/packages/explorer/src/content/repositories/index.ts @@ -103,8 +103,8 @@ export const getSerieWorks = async (content: ContentWithIsPartOf) => ) .filter((w) => 'position' in w && typeof w.position === 'number') .sort((a, b) => (a.position as number) - (b.position as number)) as Array< - Content & Required> - >; + Content & Required> + >; export const getPreviousWorkSeries = async ( content: Content diff --git a/packages/sitemap/CHANGELOG.md b/packages/sitemap/CHANGELOG.md new file mode 100644 index 00000000..39b2c7e2 --- /dev/null +++ b/packages/sitemap/CHANGELOG.md @@ -0,0 +1,7 @@ +# @galactiks/sitemap + +## 0.1.0 + +### Minor Changes + +- [`763c9ba`](https://github.com/thegalactiks/explorer/commit/763c9ba24b4ccf81ee0f75a1fa01a8205b5a3dcc) Thanks [@emmanuelgautier](https://github.com/emmanuelgautier)! - sitemap dedicated package and minor fixes diff --git a/packages/sitemap/package.json b/packages/sitemap/package.json index 6a808082..52067ed9 100644 --- a/packages/sitemap/package.json +++ b/packages/sitemap/package.json @@ -1,6 +1,6 @@ { "name": "@galactiks/sitemap", - "version": "0.0.1", + "version": "0.1.0", "description": "A simple sitemap generator for Galactiks", "author": "thegalactiks", "type": "module", diff --git a/packages/sitemap/src/index.ts b/packages/sitemap/src/index.ts index 056d598b..c68475a1 100644 --- a/packages/sitemap/src/index.ts +++ b/packages/sitemap/src/index.ts @@ -15,7 +15,7 @@ function createSitemap(hostname: string, type: string, items: SitemapItem[]) { video: false, }, }); - items.forEach(item => stream.write(item)); + items.forEach((item) => stream.write(item)); stream.end(); return stream; @@ -27,23 +27,35 @@ type GenerateSitemapsOptions = SerializeOptions & { hostname: string; }; -export async function generateSitemaps({ destinationDir, hostname, pages, defaultLanguage, publication }: GenerateSitemapsOptions) { +export async function generateSitemaps({ + destinationDir, + hostname, + pages, + defaultLanguage, + publication, +}: GenerateSitemapsOptions) { const serialize = sitemapSerialize({ defaultLanguage, publication }); - const sitemapsItems = pages.reduce((acc, page) => { - const { type } = page; - if (!acc[type]) { - acc[type] = []; - } + const sitemapsItems = pages.reduce( + (acc, page) => { + const { type } = page; + if (!acc[type]) { + acc[type] = []; + } - acc[type].push(serialize(page)); - return acc; - }, {} as Record); + acc[type].push(serialize(page)); + return acc; + }, + {} as Record + ); - const sitemaps = Object.entries(sitemapsItems).reduce((acc, [type, items]) => { - acc[type] = createSitemap(hostname, type, items); - return acc; - }, {} as Record); + const sitemaps = Object.entries(sitemapsItems).reduce( + (acc, [type, items]) => { + acc[type] = createSitemap(hostname, type, items); + return acc; + }, + {} as Record + ); // Generate index sitemap const indexSitemap = new SitemapStream({ @@ -61,6 +73,8 @@ export async function generateSitemaps({ destinationDir, hostname, pages, defaul indexSitemap.write({ url: sitemapPath }); stream.pipe(createWriteStream(join(destinationDir, sitemapPath))); }); - indexSitemap.pipe(createWriteStream(join(destinationDir, `sitemap-index.xml`))); - return streamToPromise(indexSitemap).then(data => data.toString()); + indexSitemap.pipe( + createWriteStream(join(destinationDir, `sitemap-index.xml`)) + ); + return streamToPromise(indexSitemap).then((data) => data.toString()); } diff --git a/packages/sitemap/src/serialize.ts b/packages/sitemap/src/serialize.ts index 75d44b24..db601430 100644 --- a/packages/sitemap/src/serialize.ts +++ b/packages/sitemap/src/serialize.ts @@ -12,20 +12,22 @@ export type SerializeOptions = { export function sitemapSerialize(config: SerializeOptions) { return (page: Content): SitemapItem => { const isArticle = page.type === 'Article'; - const news: SitemapItem['news'] = isArticle ? { - publication: { - name: config.publication.name, - language: (page.inLanguage || config.defaultLanguage || '') - ?.substring(0, 2) - .toLowerCase(), - }, + const news: SitemapItem['news'] = isArticle + ? { + publication: { + name: config.publication.name, + language: (page.inLanguage || config.defaultLanguage || '') + ?.substring(0, 2) + .toLowerCase(), + }, - publication_date: isValid(page.datePublished) - ? page.datePublished.toISOString() - : new Date().toISOString(), - title: page.name, - keywords: page.keywords?.join(', '), - } : undefined; + publication_date: isValid(page.datePublished) + ? page.datePublished.toISOString() + : new Date().toISOString(), + title: page.name, + keywords: page.keywords?.join(', '), + } + : undefined; return { url: page.url, @@ -38,4 +40,4 @@ export function sitemapSerialize(config: SerializeOptions) { news, }; }; -}; +}