Skip to content

Commit

Permalink
Merge pull request #233 from nekochans/feature/issue232/add-canonical…
Browse files Browse the repository at this point in the history
…-tags

インデックスさせたいページはcanonicalタグを追加するように変更
  • Loading branch information
keitakn authored Dec 5, 2022
2 parents 39cc192 + 5ec01e3 commit 597ec68
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
57 changes: 44 additions & 13 deletions src/templates/TermsOrPrivacyTemplate/TermsOrPrivacyTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type Language,
} from '../../features';
import { DefaultLayout } from '../../layouts';
import { assertNever } from '../../utils';

type Props = {
type: TemplateType;
Expand All @@ -21,6 +22,42 @@ type Props = {
enMarkdown: string;
};

const createCanonicalLink = (type: TemplateType, language: Language) => {
switch (type) {
case 'terms':
return language === 'en' ? i18nUrlList.terms?.en : i18nUrlList.terms?.ja;
case 'privacy':
return language === 'en'
? i18nUrlList.privacy?.en
: i18nUrlList.privacy?.ja;
default:
return assertNever(type);
}
};

const createAlternateUrls = (type: TemplateType) => {
switch (type) {
case 'terms':
return languages.map((hreflang) => {
if (hreflang === 'en') {
return { link: i18nUrlList.terms?.en, hreflang };
}

return { link: i18nUrlList.terms?.ja, hreflang };
});
case 'privacy':
return languages.map((hreflang) => {
if (hreflang === 'en') {
return { link: i18nUrlList.privacy?.en, hreflang };
}

return { link: i18nUrlList.privacy?.ja, hreflang };
});
default:
return assertNever(type);
}
};

// eslint-disable-next-line max-lines-per-function
export const TermsOrPrivacyTemplate: FC<Props> = ({
type,
Expand All @@ -38,22 +75,16 @@ export const TermsOrPrivacyTemplate: FC<Props> = ({
? metaTagList(language).terms
: metaTagList(language).privacy;

const canonicalLink =
type === 'terms' ? i18nUrlList.terms?.ja : i18nUrlList.privacy?.ja;

const alternateUrls = languages.map((hreflang) => {
if (hreflang === 'ja') {
return { link: canonicalLink, hreflang };
}

const link =
type === 'terms' ? i18nUrlList.terms?.en : i18nUrlList.privacy?.en;
const canonicalLink = createCanonicalLink(type, language);

return { link, hreflang };
});
const alternateUrls = createAlternateUrls(type);

return (
<DefaultLayout metaTag={metaTag} alternateUrls={alternateUrls}>
<DefaultLayout
metaTag={metaTag}
canonicalLink={canonicalLink}
alternateUrls={alternateUrls}
>
<OrgTermsOrPrivacyTemplate
type={type}
language={language}
Expand Down
24 changes: 15 additions & 9 deletions src/templates/UploadTemplate/UploadTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ const CatImage = () => (
<Image src={cat.src} width={302} height={302} alt="Cat" priority={true} />
);

const canonicalLink = i18nUrlList.upload?.ja;

const alternateUrls = languages.map((hreflang) => {
const link = hreflang === 'ja' ? canonicalLink : i18nUrlList.upload?.en;

return { link, hreflang };
});

type Props = {
language: Language;
};

export const UploadTemplate: FC<Props> = ({ language }) => {
const metaTag = metaTagList(language).upload;

const canonicalLink =
language === 'en' ? i18nUrlList.upload?.en : i18nUrlList.upload?.ja;

const alternateUrls = languages.map((hreflang) => {
const link =
hreflang === 'en' ? i18nUrlList.upload?.en : i18nUrlList.upload?.ja;

return { link, hreflang };
});

const { imageValidator } = useCatImageValidator(language);

const { imageUploader } = useCatImageUploader(language);

return (
<DefaultLayout metaTag={metaTag} alternateUrls={alternateUrls}>
<DefaultLayout
metaTag={metaTag}
canonicalLink={canonicalLink}
alternateUrls={alternateUrls}
>
<OrgUploadTemplate
language={language}
imageValidator={imageValidator}
Expand Down

1 comment on commit 597ec68

@vercel
Copy link

@vercel vercel bot commented on 597ec68 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.