Skip to content

Commit

Permalink
Reworked Sitemap and minor bugfixes and UI improvements
Browse files Browse the repository at this point in the history
You can now access paths directly via /path, meaning that sitemaps have been updated to respect conventional sitemapping. Additionally, some UI improvements and bugfxies have been made.
  • Loading branch information
gregory-buffard committed Aug 19, 2024
1 parent 3266c65 commit d6c4b29
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 101 deletions.
33 changes: 0 additions & 33 deletions web/app/server-sitemap-en.xml/route.ts

This file was deleted.

33 changes: 0 additions & 33 deletions web/app/server-sitemap-fr.xml/route.ts

This file was deleted.

44 changes: 44 additions & 0 deletions web/app/server-sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getServerSideSitemap, ISitemapField } from "next-sitemap";
import { fetchSitemap } from "@/actions/actions";
import IDoc from "@/types/server-sitemap";

export const GET = async (request: Request) => {
const data = await fetchSitemap(),
URLs: ISitemapField[] = [];

const addURLs = (category: string, basePath: { en: string; fr: string }) => {
data[category].docs.forEach((doc: IDoc) => {
URLs.push({
loc: `https://www.g-yachts.com/${basePath.en}/${doc.id}`,
lastmod: doc.updatedAt,
priority: 0.8,
alternateRefs: [
{
href: `https://www.g-yachts.com/${basePath.fr}/${doc.id}`,
hreflang: "fr",
},
{
href: `https://www.g-yachts.com/en/${basePath.en}/${doc.id}`,
hreflang: "en",
},
{
href: `https://www.g-yachts.com/fr/${basePath.fr}/${doc.id}`,
hreflang: "fr",
},
],
});
});
};

addURLs("Yachts", { en: "sales", fr: "ventes" });
addURLs("Charters", { en: "charters", fr: "charters" });
addURLs("NewConstructions", {
en: "new-constructions",
fr: "nouvelles-constructions",
});
addURLs("Destinations", { en: "destinations", fr: "destinations" });
addURLs("Articles", { en: "news", fr: "actualites" });
addURLs("Events", { en: "events", fr: "evenements" });

return getServerSideSitemap(URLs);
};
File renamed without changes.
7 changes: 6 additions & 1 deletion web/components/yachts/listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { useTranslations } from "next-intl";
import { Link } from "@/navigation";
import { useViewContext } from "@/context/view";
import Bookmark from "@/public/pictures/sales/bookmark";
import { ListingModifier, Range, Select, Radio } from "@/components/filters";
import {
ListingModifier,
Range,
Select,
Radio,
} from "@/components/yachts/filters";
import { ISale, ICharter, INewConstruction } from "@/types/yacht";

interface IFilters {
Expand Down
2 changes: 1 addition & 1 deletion web/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"label": "Yacht type",
"all": "All",
"motor": "Motor",
"sail": "Sail"
"sail": "Sailing"
},
"year": "Year",
"length": "Yacht length ({unit, select, m {meters} ft {feet} other {}})",
Expand Down
5 changes: 4 additions & 1 deletion web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export default function (req: NextRequest): NextResponse {
}

export const config = {
matcher: ["/", "/(fr|en)/:path*"],
matcher: [
"/([\\w-]+)?/((?!api|_next|_vercel|admin|images|pictures|videos|media|.*\\..*).*)",
"/(fr|en)/:path*",
],
};
54 changes: 22 additions & 32 deletions web/next-sitemap.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ module.exports = {
generateRobotsTxt: true,
sitemapSize: 5000,
robotsTxtOptions: {
additionalSitemaps: [
"https://www.g-yachts.com/server-sitemap-en.xml",
"https://www.g-yachts.com/server-sitemap-fr.xml",
],
additionalSitemaps: ["https://www.g-yachts.com/server-sitemap.xml"],
},
additionalPaths: async (config) => {
const result = [],
Expand Down Expand Up @@ -47,36 +44,29 @@ module.exports = {
},
];

staticPaths.map((paths) => {
paths.paths.forEach((path) => {
result.push({
loc: `/${paths.locale}/${path}`,
lastmod: new Date().toISOString(),
priority: 0.7,
});
for (let i = 0; i < staticPaths[0].paths.length; i++) {
result.push({
loc: `/${staticPaths[0].paths[i]}`,
lastmod: new Date().toISOString(),
priority: 0.7,
alternateRefs: [
{
href: `${config.siteUrl}/${staticPaths[1].paths[i]}`,
hreflang: staticPaths[1].locale,
},
{
href: `${config.siteUrl}/${staticPaths[0].locale}/${staticPaths[0].paths[i]}`,
hreflang: staticPaths[0].locale,
},
{
href: `${config.siteUrl}/${staticPaths[1].locale}/${staticPaths[1].paths[i]}`,
hreflang: staticPaths[1].locale,
},
],
});
});
}

return result;
},
alternateRefs: [
{
href: "https://www.g-yachts.com/",
hreflang: "x-default",
},
{
href: "https://www.g-yachts.com/en",
hreflang: "en",
},
{
href: "https://www.g-yachts.com/fr",
hreflang: "fr",
},
],
exclude: [
"/admin",
"/admin/*",
"/server-sitemap-en.xml",
"/server-sitemap-fr.xml",
],
exclude: ["/admin", "/admin/*", "/server-sitemap.xml"],
};

0 comments on commit d6c4b29

Please sign in to comment.