Skip to content

Commit

Permalink
Merge pull request #1188 from moonshotcommons/feature/HQ-748-canonica…
Browse files Browse the repository at this point in the history
…ls-canonicalized

feat: canonicals canonicalized
  • Loading branch information
qige12138 committed Mar 5, 2024
2 parents d77f2ae + a7a2fda commit 96861fd
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.title,
alternates: {
canonical: `https://www.hackquest.io/practices/${courseId}`
canonical: `https://www.hackquest.io/practices/${encodeURIComponent(courseId)}`
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.title,
alternates: {
canonical: `https://www.hackquest.io/electives/${courseId}`
canonical: `https://www.hackquest.io/electives/${encodeURIComponent(courseId)}`
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.name,
alternates: {
canonical: `https://www.hackquest.io/learning-track/${learningTrackId}`
canonical: `https://www.hackquest.io/learning-track/${encodeURIComponent(learningTrackId)}`
}
};

Expand Down
4 changes: 2 additions & 2 deletions app/(web)/(base page)/(learn)/learning-track/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Metadata } from 'next';
import LearninTrack from './components';

export const metadata: Metadata = {
title: 'HackQuest Learnin Track',
title: 'HackQuest Learning Track',
alternates: {
canonical: 'https://www.hackquest.io/electives'
canonical: 'https://www.hackquest.io/learning-track'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.title,
alternates: {
canonical: `https://www.hackquest.io/practices/${courseId}`
canonical: `https://www.hackquest.io/practices/${encodeURIComponent(courseId)}`
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/(web)/(base page)/(resource)/blog/[blogId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function generateMetadata({
title: blog.title,
description: blog.description,
alternates: {
canonical: `https://www.hackquest.io/blog/${params.blogId}`
canonical: `https://www.hackquest.io/blog/${encodeURIComponent(params.blogId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function generateMetadata({
title: glossary.title,
description: glossary.description,
alternates: {
canonical: `https://www.hackquest.io/glossary/${params.glossaryId}`
canonical: `https://www.hackquest.io/glossary/${encodeURIComponent(params.glossaryId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateMetadata({
title: hackathon.name,
description: hackathon.about,
alternates: {
canonical: `https://www.hackquest.io/hackathon/${params.hackathonId}`
canonical: `https://www.hackquest.io/hackathon/${encodeURIComponent(params.hackathonId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function generateMetadata({
title: hackathon.name,
description: hackathon.description,
alternates: {
canonical: `https://www.hackquest.io/project/${params.projectId}`
canonical: `https://www.hackquest.io/projects/${encodeURIComponent(params.projectId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.title,
alternates: {
canonical: `https://www.hackquest.io/electives/${courseId}`
canonical: `https://www.hackquest.io/electives/${encodeURIComponent(courseId)}`
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Metadata } from 'next';
import LearninTrack from '../components';

export const metadata: Metadata = {
title: 'HackQuest Learnin Track'
title: 'HackQuest Learning Track',
alternates: {
canonical: 'https://www.hackquest.io/learning-track'
}
};

export default LearninTrack;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.name,
alternates: {
canonical: `https://www.hackquest.io/learning-track/${learningTrackId}`
canonical: `https://www.hackquest.io/learning-track/${encodeURIComponent(learningTrackId)}`
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function generateMetadata(
const metadata: Metadata = {
title: courseDetail.title,
alternates: {
canonical: `https://www.hackquest.io/practices/${courseId}`
canonical: `https://www.hackquest.io/practices/${encodeURIComponent(courseId)}`
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/mobile/(base page)/(resource)/blog/[blogId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function generateMetadata({
title: blog.title,
description: blog.description,
alternates: {
canonical: `https://www.hackquest.io/blog/${params.blogId}`
canonical: `https://www.hackquest.io/blog/${encodeURIComponent(params.blogId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function generateMetadata({
title: glossary.title,
description: glossary.description,
alternates: {
canonical: `https://www.hackquest.io/glossary/${params.glossaryId}`
canonical: `https://www.hackquest.io/glossary/${encodeURIComponent(params.glossaryId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateMetadata({
title: hackathon.name,
description: hackathon.about,
alternates: {
canonical: `https://www.hackquest.io/hackathon/${params.hackathonId}`
canonical: `https://www.hackquest.io/hackathon/${encodeURIComponent(params.hackathonId)}`
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function generateMetadata({
title: hackathon.name,
description: hackathon.description,
alternates: {
canonical: `https://www.hackquest.io/project/${params.projectId}`
canonical: `https://www.hackquest.io/projects/${encodeURIComponent(params.projectId)}`
}
};
}
Expand Down
10 changes: 6 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export function middleware(request: NextRequest) {
const userAgent = request.headers.get('user-agent');
if (!userAgent) return NextResponse.next();

if (isMobile(userAgent!) && !request.nextUrl.pathname.startsWith('/mobile')) {
const url = `/mobile${request.nextUrl.pathname}${request.nextUrl.search}`;
const pathname = request.nextUrl.pathname;

if (isMobile(userAgent!) && !pathname.startsWith('/mobile')) {
const url = `/mobile${pathname}${request.nextUrl.search}`;
return NextResponse.redirect(new URL(url, request.url));
}

if (!isMobile(userAgent!) && request.nextUrl.pathname.startsWith('/mobile')) {
const newPathname = request.nextUrl.pathname.replace(/^\/mobile/, '');
if (!isMobile(userAgent!) && pathname.startsWith('/mobile')) {
const newPathname = pathname.replace(/^\/mobile/, '');
const url = `${newPathname}${request.nextUrl.search}`;
return NextResponse.redirect(new URL(url, request.url));
}
Expand Down

0 comments on commit 96861fd

Please sign in to comment.