Skip to content

Commit

Permalink
Merge pull request #79 from thegalactiks/use-default-lang-config
Browse files Browse the repository at this point in the history
fix(@galactiks/explorer): use default lang configured
  • Loading branch information
emmanuelgautier authored Oct 2, 2023
2 parents ccaaf99 + 37d6321 commit 1c87578
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/explorer/src/core/content/metadata/alternates.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getDefaultLanguage } from '@galactiks/config';
import type { Content, MetadataHeaders } from '../index.mjs';
import type { ContentlayerDocumentWithURL } from '../urls.mjs';

Expand All @@ -19,7 +20,7 @@ export const alternatesHeaderBuilder = (

return (document: Content): MetadataHeaders['alternates'] => {
let translations: Array<ContentlayerDocumentWithURL | Content> = [];
let defaultTranslation: ContentlayerDocumentWithURL | Content;
let defaultTranslation: ContentlayerDocumentWithURL | Content | undefined;
if (document.translationOfWork) {
const translationOfWorkId = document.translationOfWork['@id'];

Expand All @@ -42,15 +43,19 @@ export const alternatesHeaderBuilder = (
document.identifier,
document.url
);
defaultTranslation = document;
}

translations = translations.concat(defaultTranslation);

if (translations.length === 1) {
if (translations.length === 0) {
translations = selectPagesByIdentifier(document.identifier);
}

if (!defaultTranslation) {
const configDefaultLanguage = getDefaultLanguage();
defaultTranslation =
translations.find((t) => t.inLanguage === configDefaultLanguage) ||
document;
}

return translations
.filter((_t) => _t.inLanguage)
.map((_t) => ({ href: _t.url, hreflang: _t.inLanguage as string }))
Expand Down

0 comments on commit 1c87578

Please sign in to comment.