Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add canonical link setup #266

Merged
merged 30 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fae34e
chore: add changelog index
tobySolutions Sep 13, 2024
2757cd1
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 16, 2024
48e4bdb
feat: add OFAC documentation to domains page
tobySolutions Sep 16, 2024
c6045ff
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 17, 2024
8d0e460
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 22, 2024
84fb7cd
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 23, 2024
0e5058b
chore: pullng
tobySolutions Sep 24, 2024
669dc46
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 24, 2024
d59b7ea
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 24, 2024
e6498e5
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 26, 2024
84c3002
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Sep 27, 2024
5717d97
chore: checkout
tobySolutions Sep 27, 2024
0336b4f
chore: pulling
tobySolutions Sep 30, 2024
c8baac7
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 1, 2024
4dea0be
chore: checkout
tobySolutions Oct 1, 2024
7c4d9fd
chore: pulling
tobySolutions Oct 3, 2024
5af2745
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 4, 2024
e6d944f
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 11, 2024
bb9150d
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 14, 2024
d9df0c9
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 14, 2024
15593e3
Merge branch 'develop' of https://github.com/fleek-platform/website i…
tobySolutions Oct 15, 2024
f035f9e
chore: pulling
tobySolutions Oct 15, 2024
877ccef
feat: add canonical link setup
tobySolutions Oct 15, 2024
fe1a9c0
chore: pulling
tobySolutions Oct 15, 2024
e128800
feat: handle URL edge cases
tobySolutions Oct 16, 2024
832c375
feat: handle URL edge cases
tobySolutions Oct 16, 2024
8d39b07
feat: handle docs URL edge cases
tobySolutions Oct 16, 2024
b790467
Update src/layouts/DocsHtml.astro
tobySolutions Oct 16, 2024
461c2d2
feat: handle docs URL edge cases
tobySolutions Oct 16, 2024
0534e97
feat: handle docs URL edge cases
tobySolutions Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/layouts/BaseHtml.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Announcement } from '@components/Announcement';
import Footer from '@components/Footer';
import { Navbar } from '@components/Navbar';
import SupportMenu from '@components/Support/SupportMenu';
import { generateCanonicalUrl } from '@utils/generateCanonicalUrl';

interface Props {
title: string;
Expand All @@ -23,6 +24,9 @@ interface Props {
const { ogMeta } = Astro.props;
const baseUrl = getSiteUrl();
const hasSecondaryMenu = hasSecondaryMenuItem(Astro.url.pathname);

const contentSlug = ogMeta?.slug || Astro.url.pathname;
tobySolutions marked this conversation as resolved.
Show resolved Hide resolved
const canonicalUrl = generateCanonicalUrl(contentSlug);
---

<!doctype html>
Expand All @@ -31,6 +35,7 @@ const hasSecondaryMenu = hasSecondaryMenuItem(Astro.url.pathname);
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<link rel="canonical" href={`${canonicalUrl}`} />
<link rel="sitemap" href="/sitemap-index.xml" />
<link
rel="preload"
Expand Down
9 changes: 7 additions & 2 deletions src/layouts/DocPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ import { Announcement } from '@components/Announcement';
type Props = {
title: string;
description: string;
pageSlug: string;
headings: MarkdownHeading[];
prevItem: DocsLink | null;
nextItem: DocsLink | null;
};

const { title, description, headings, prevItem, nextItem } = Astro.props;
const { title, description, headings, prevItem, nextItem, pageSlug } =
Astro.props;

const {
collection,
id,
Expand Down Expand Up @@ -76,9 +79,11 @@ const indexNameDocs = import.meta.env.PUBLIC_MEILISEARCH_INDEX_DOCS;
// TODO: Fails after prod build
const isHome = Astro.url.pathname === '/docs';

const isDocsHomepage = data.slug === 'index' && pageSlug === 'index';

const slug = generateFullSlug({
basePath: settings.site.metadata.docs.slug,
slug: data.slug === 'index' ? '' : data.slug,
slug: isDocsHomepage ? '' : pageSlug,
});

const image = settings.site.metadata.docs.image;
Expand Down
4 changes: 4 additions & 0 deletions src/layouts/DocsHtml.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import settings from '@base/settings.json';
import { Toaster } from 'react-hot-toast';
import { Navbar } from '@components/Navbar';
import PostHog from '@components/PostHog.astro';
import { generateCanonicalUrl } from '@utils/generateCanonicalUrl';

interface Props {
title: string;
Expand All @@ -18,6 +19,8 @@ interface Props {

const { ogMeta } = Astro.props;
const baseUrl = getSiteUrl();
const docsPageSlug = ogMeta?.slug || Astro.url.pathname;
const canonicalUrl = generateCanonicalUrl(docsPageSlug);
---

<!doctype html>
Expand All @@ -27,6 +30,7 @@ const baseUrl = getSiteUrl();
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<link rel="sitemap" href="/sitemap-index.xml" />
<link rel="canonical" href={`${canonicalUrl}`} />
<link
rel="preload"
href="/fonts/atyp/AtypDisplay-Regular.woff2"
Expand Down
4 changes: 4 additions & 0 deletions src/layouts/LandingPageHtml.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import '@styles/globals.css';
import { getSiteUrl } from '@utils/url';
import settings from '@base/settings.json';
import PostHog from '@components/PostHog.astro';
import { generateCanonicalUrl } from '@utils/generateCanonicalUrl';

const baseUrl = getSiteUrl();
const canonicalUrl = generateCanonicalUrl();
---

<!doctype html>
Expand All @@ -14,6 +17,7 @@ const baseUrl = getSiteUrl();
name="viewport"
content="width=device-width, height=device-height, initial-scale=1, viewport-fit=cover"
/>
<link rel="canonical" href={`${canonicalUrl}`} />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<link rel="sitemap" href="/sitemap-index.xml" />
<link
Expand Down
2 changes: 2 additions & 0 deletions src/pages/docs/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function getStaticPaths() {
const { entry, prevItem, nextItem, currentCategory } = Astro.props;
const { Content, headings } = await entry.render();
const title = handlePageTitle('Docs');
const pageSlug = entry.slug;

function handlePageTitle(collection: string) {
if (entry.data.title && currentCategory !== 'root') {
Expand All @@ -81,6 +82,7 @@ function handlePageTitle(collection: string) {
<DocPageLayout
title={title}
description={entry.data.desc || ''}
pageSlug={pageSlug}
headings={headings}
prevItem={prevItem}
nextItem={nextItem}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/docs/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const { Content, headings } = await entry.render();

const title = entry.data.title || settings.site.metadata.docs.title;
const description = entry.data.desc || settings.site.metadata.docs.description;
const pageSlug = entry.slug;
---

<Layout
title={title}
description={description}
headings={headings}
prevItem={null}
pageSlug={pageSlug}
nextItem={nextItem}
>
<Content />
Expand Down
15 changes: 15 additions & 0 deletions src/utils/generateCanonicalUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getSiteUrl } from './url';

const BASE_URL = getSiteUrl();

export function generateCanonicalUrl(slug?: string) {
if (!slug) return `${BASE_URL}/`;

const sanitizedSlug = slug
.trim()
.split('/')
.filter((item) => item)
.join('/');

return `${BASE_URL}/${sanitizedSlug}/`;
}