Skip to content

Commit

Permalink
Merge pull request #111 from thegalactiks/changeset-release/main
Browse files Browse the repository at this point in the history
[ci] release
  • Loading branch information
emmanuelgautier authored Nov 12, 2023
2 parents 84443e1 + 2f33726 commit 0e9ae9e
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 141 deletions.
6 changes: 0 additions & 6 deletions .changeset/dry-roses-worry.md

This file was deleted.

9 changes: 9 additions & 0 deletions packages/adapters/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.2.10",
"version": "0.2.11",
"description": "Galactiks Astro integration",
"author": "thegalactiks",
"types": "./dist/index.d.ts",
Expand Down
14 changes: 7 additions & 7 deletions packages/adapters/astro/src/preset.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
];
};
55 changes: 28 additions & 27 deletions packages/adapters/astro/src/sitemap.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', '),
},
};
};
};
6 changes: 6 additions & 0 deletions packages/explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.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",
Expand Down
201 changes: 102 additions & 99 deletions packages/explorer/src/core/content/urls.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
};

0 comments on commit 0e9ae9e

Please sign in to comment.