feat: agregar funcionalidad para obtener organizaciones públicas y actualizar el sitemap con rutas dinámicas
This commit is contained in:
@@ -3,6 +3,7 @@ import ApiServerService from "@services/Api.Server.Service";
|
||||
import { PublicOrganizationView } from "@core/Models/Company.model";
|
||||
import OrganizationHeader from "@core/app/components/Home/OrganizationHeader/OrganizationHeader";
|
||||
import OrganizationDataConnector from "./components/OrganizationData";
|
||||
import type { Metadata } from "next";
|
||||
|
||||
const GetOrganizationData = async (companyId: string): Promise<PublicOrganizationView> => {
|
||||
try {
|
||||
@@ -28,6 +29,49 @@ type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<Params> }): Promise<Metadata> {
|
||||
const { oid } = await params;
|
||||
const orgData = await GetOrganizationData(oid);
|
||||
|
||||
if (!orgData || !orgData.id) {
|
||||
return {
|
||||
robots: { index: false, follow: false },
|
||||
};
|
||||
}
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "https://turnosxpress.com.ar";
|
||||
const canonicalUrl = `${baseUrl}/landing/org/${oid}`;
|
||||
const description =
|
||||
orgData.description && orgData.description.trim().length > 0
|
||||
? orgData.description
|
||||
: `${orgData.name} - TurnosXpress`;
|
||||
|
||||
return {
|
||||
title: `${orgData.name} | TurnosXpress`,
|
||||
description,
|
||||
alternates: {
|
||||
canonical: canonicalUrl,
|
||||
},
|
||||
openGraph: {
|
||||
type: "website",
|
||||
title: `${orgData.name} | TurnosXpress`,
|
||||
description,
|
||||
url: canonicalUrl,
|
||||
siteName: "TurnosXpress",
|
||||
locale: "es_AR",
|
||||
},
|
||||
twitter: {
|
||||
card: "summary",
|
||||
title: `${orgData.name} | TurnosXpress`,
|
||||
description,
|
||||
},
|
||||
robots: {
|
||||
index: true,
|
||||
follow: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function OrganizationPublicProfile({ params, children }: Props) {
|
||||
const { oid } = await params;
|
||||
const orgData = await GetOrganizationData(oid);
|
||||
|
||||
@@ -165,7 +165,44 @@ export async function GET() {
|
||||
console.error("Error generating sitemap:", error);
|
||||
}
|
||||
|
||||
const allRoutes = [...staticRoutes, ...videoRoutes, ...authRoutes, ...marketingRoutes, ...explorationRoutes, ...legalRoutes, ...serviceRoutes];
|
||||
let orgRoutes: SitemapRoute[] = [];
|
||||
|
||||
try {
|
||||
let currentPage = 1;
|
||||
let totalPages = 1;
|
||||
|
||||
do {
|
||||
const orgsResult = await ApiServerService.post<{
|
||||
data: { slug: string; name: string; description: string; creationDate?: string }[];
|
||||
page: number;
|
||||
pages: number;
|
||||
}>("views/public-organizations", {
|
||||
page: currentPage,
|
||||
limit: 1000,
|
||||
});
|
||||
|
||||
if (orgsResult && orgsResult.data) {
|
||||
totalPages = orgsResult.pages || 1;
|
||||
|
||||
const newRoutes = orgsResult.data.map((org) => ({
|
||||
url: `${baseUrl}/landing/org/${org.slug}`,
|
||||
changeFrequency: "weekly" as const,
|
||||
priority: 0.8,
|
||||
}));
|
||||
|
||||
orgRoutes = [...orgRoutes, ...newRoutes];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
currentPage++;
|
||||
} while (currentPage <= totalPages);
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error generating org sitemap:", error);
|
||||
}
|
||||
|
||||
const allRoutes = [...staticRoutes, ...videoRoutes, ...authRoutes, ...marketingRoutes, ...orgRoutes, ...explorationRoutes, ...legalRoutes, ...serviceRoutes];
|
||||
|
||||
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
|
||||
Reference in New Issue
Block a user