Skip to content

Commit

Permalink
Merge pull request #14 from mobeigi/more-seo-changes
Browse files Browse the repository at this point in the history
Improve management of links and canonicals
  • Loading branch information
mobeigi authored Aug 20, 2024
2 parents 4302d6e + 0cd21f7 commit cd37e0f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
name="description"
content="Chessort is a Chess puzzle game where you sort moves based on the chess engine's evaluation."
/>
<meta name="keywords" content="chessort, chess, puzzle, sort, sorting, order, ordering, game, engine, evaluation, lichess, stockfish">
<meta property="og:title" content="Chessort" />
<meta
property="og:description"
Expand Down Expand Up @@ -59,7 +60,7 @@
<!-- Misc end -->

<!-- Header includes end -->
<title>Chessort</title>
<title>Chessort: The Chess Puzzle Sorting Game</title>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 7 additions & 0 deletions app/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ server {
listen 80;
server_name chessort.com;

absolute_redirect off;

root /usr/share/nginx/html;

# Add trailing slash to /game/
if ($request_uri ~* ^/game/[^/]+$) {
return 301 $request_uri/;
}

# React SPA
# Redirect all routes to index.html
location / {
Expand Down
1 change: 1 addition & 0 deletions app/src/constants/app.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const APP_NAME = 'Chessort';
export const APP_TAGLINE = 'The Chess Puzzle Sorting Game';
export const CHESSORT_APP_BASE_URL = import.meta.env.VITE_CHESSORT_APP_BASE_URL;
7 changes: 5 additions & 2 deletions app/src/containers/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../../constants/analytics';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { useEffect } from 'react';
import { APP_NAME } from '../../constants/app';
import { APP_NAME, APP_TAGLINE, CHESSORT_APP_BASE_URL } from '../../constants/app';

// Set modal element
Modal.setAppElement('#root');
Expand Down Expand Up @@ -56,7 +56,10 @@ const AppContainer = () => {
<Header />
<ToastContainer />
<Helmet>
<title>{APP_NAME}</title>
<title>
{APP_NAME}: {APP_TAGLINE}
</title>
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/`} />
</Helmet>
<Routes>
<Route path="/" element={<Game />} />
Expand Down
2 changes: 1 addition & 1 deletion app/src/containers/App/NotFoundPage/NotFoundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const NotFoundPage = () => {
<>
<Helmet>
<title>{APP_NAME}: 404 Not Found</title>
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/404`} />
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/404/`} />
</Helmet>
<NotFoundContainer>
<h1>404 Not Found</h1>
Expand Down
14 changes: 11 additions & 3 deletions app/src/containers/Panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export const Panel = () => {
* To support back/forward browser navigation.
*/
useEffect(() => {
// Don't rewrite url for the very first game
if (isFirstGame) {
// Don't rewrite url for the very first game on homepage
if (isFirstGame && location.pathname === '/') {
return;
}

Expand Down Expand Up @@ -319,6 +319,12 @@ export const Panel = () => {
if (isInitLoadCompleted && initError) {
return (
<PanelContainer>
<Helmet>
<title>
{APP_NAME}: Failed to load game (#{gameId})
</title>
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/game/${gameId}/`} />
</Helmet>
<div>
<i className="bx bx-error"></i> <span>Failed to load game.</span>
</div>
Expand All @@ -333,7 +339,9 @@ export const Panel = () => {
<title>
{APP_NAME} (#{gameId})
</title>
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/game/${gameId}`} />
{!(isFirstGame && location.pathname === '/') && (
<link rel="canonical" href={`${CHESSORT_APP_BASE_URL}/game/${gameId}/`} />
)}
</Helmet>
)}
<PanelContainer>
Expand Down

0 comments on commit cd37e0f

Please sign in to comment.