Skip to content

Commit

Permalink
Merge pull request #179 from thegalactiks/changeset-release/main
Browse files Browse the repository at this point in the history
[ci] release
  • Loading branch information
emmanuelgautier authored Mar 4, 2024
2 parents 763c9ba + 992a264 commit 7b3dbf2
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 129 deletions.
8 changes: 0 additions & 8 deletions .changeset/quick-adults-jog.md

This file was deleted.

10 changes: 5 additions & 5 deletions examples/astro/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -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: {},
},
Expand Down
7 changes: 2 additions & 5 deletions examples/astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -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()],
};
14 changes: 7 additions & 7 deletions examples/astro/src/components/Picture.astro
Original file line number Diff line number Diff line change
@@ -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<typeof AstroPicture> & {
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]) {
Expand Down
12 changes: 6 additions & 6 deletions examples/astro/src/pages/[...path].astro
Original file line number Diff line number Diff line change
@@ -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;
---

<Layout content={page}>
Expand Down
6 changes: 3 additions & 3 deletions examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -11,7 +11,7 @@ const { Content } = page.body.render();

<PageLayout content={page}>
<div class="mx-auto mt-6 max-w-3xl">
<article class:list={["prose lg:prose-lg"]}>
<article class:list={['prose lg:prose-lg']}>
<Content />
</article>
</div>
Expand Down
2 changes: 1 addition & 1 deletion examples/astro/src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { getRSS } from "@galactiks/astro-integration";
import { getRSS } from '@galactiks/astro-integration';

export const GET = getRSS;
11 changes: 11 additions & 0 deletions packages/adapters/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galactiks/astro-integration",
"version": "0.3.5",
"version": "0.3.6",
"description": "Galactiks Astro integration",
"author": "thegalactiks",
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion packages/adapters/astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions packages/adapters/astro/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
35 changes: 20 additions & 15 deletions packages/adapters/astro/src/plugins/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>((urls, r) => {
if (r.type !== 'page') return urls;
Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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)}\``
);
},
},
};
Expand Down
7 changes: 1 addition & 6 deletions packages/adapters/astro/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
};
6 changes: 6 additions & 0 deletions packages/config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions packages/explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
51 changes: 28 additions & 23 deletions packages/explorer/src/content/hydrate/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentlayerDocumentWithURL & ContentlayerWebPageDocumentWithRender>);
.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
>
);
};
25 changes: 15 additions & 10 deletions packages/explorer/src/content/metadata/schemas/product.ts
Original file line number Diff line number Diff line change
@@ -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<Offer>[] => 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<Offer>[] =>
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<Product> => ({
export const getProduct = (
document: ContentlayerProduct
): WithContext<Product> => ({
'@context': 'https://schema.org',
'@type': 'Product',
name: document.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 7b3dbf2

Please sign in to comment.