mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(docs-infra): avoid double slash in sitemap urls
Previously, the URLs in the generated sitemap contained double slashes between the host and the path. It's not the case anymore. fix #65022
This commit is contained in:
@@ -3,6 +3,10 @@ import {join} from 'path';
|
||||
import {readFileSync, writeFileSync} from 'fs';
|
||||
|
||||
export async function generateSitemap(deployment: Deployment, distDir: string) {
|
||||
const servingUrlWithoutEndingSlash = deployment.servingUrl.endsWith('/')
|
||||
? deployment.servingUrl.slice(0, -1)
|
||||
: deployment.servingUrl;
|
||||
|
||||
/** Timestamp string used to of the last file update. */
|
||||
const lastModifiedTimestamp = new Date().toISOString();
|
||||
/** An object containing all of the routes available within the application. */
|
||||
@@ -11,16 +15,17 @@ export async function generateSitemap(deployment: Deployment, distDir: string) {
|
||||
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${Object.keys(routes.routes)
|
||||
.map(
|
||||
(route) => `
|
||||
.map((route) => {
|
||||
const routeWithoutLeadingSlash = route.startsWith('/') ? route.slice(1) : route;
|
||||
return `
|
||||
<url>
|
||||
<loc>${deployment.servingUrl}${route}</loc>
|
||||
<loc>${servingUrlWithoutEndingSlash}/${routeWithoutLeadingSlash}</loc>
|
||||
<lastmod>${lastModifiedTimestamp}</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
`,
|
||||
)
|
||||
`;
|
||||
})
|
||||
.join('')}
|
||||
</urlset>`;
|
||||
writeFileSync(join(distDir, 'browser', 'sitemap.xml'), sitemap, 'utf-8');
|
||||
|
||||
@@ -48194,18 +48194,22 @@ async function getDeployments() {
|
||||
import { join as join4 } from "path";
|
||||
import { readFileSync as readFileSync4, writeFileSync } from "fs";
|
||||
async function generateSitemap(deployment, distDir) {
|
||||
const servingUrlWithoutEndingSlash = deployment.servingUrl.endsWith("/") ? deployment.servingUrl.slice(0, -1) : deployment.servingUrl;
|
||||
const lastModifiedTimestamp = (/* @__PURE__ */ new Date()).toISOString();
|
||||
const routes = JSON.parse(readFileSync4(join4(distDir, "prerendered-routes.json"), "utf-8"));
|
||||
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${Object.keys(routes.routes).map((route) => `
|
||||
${Object.keys(routes.routes).map((route) => {
|
||||
const routeWithoutLeadingSlash = route.startsWith("/") ? route.slice(1) : route;
|
||||
return `
|
||||
<url>
|
||||
<loc>${deployment.servingUrl}${route}</loc>
|
||||
<loc>${servingUrlWithoutEndingSlash}/${routeWithoutLeadingSlash}</loc>
|
||||
<lastmod>${lastModifiedTimestamp}</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
`).join("")}
|
||||
`;
|
||||
}).join("")}
|
||||
</urlset>`;
|
||||
writeFileSync(join4(distDir, "browser", "sitemap.xml"), sitemap, "utf-8");
|
||||
console.log(`Generated sitemap with ${Object.keys(routes.routes).length} entries.`);
|
||||
|
||||
Reference in New Issue
Block a user