Skip to content

Commit

Permalink
chore: remove trailing slash from canonical (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
lacolaco authored Aug 23, 2024
1 parent 1b1f0c5 commit baf8d5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
12 changes: 1 addition & 11 deletions tools/adev-patches/replace-canonical-host.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ index ee21c0a837..afe9b7819c 100644

/**
* Information about the deployment of this application.
@@ -20,7 +20,9 @@ export class HeaderService {
setCanonical(absolutePath: string): void {
const pathWithoutFragment = this.normalizePath(absolutePath).split('#')[0];
const fullPath = `${ANGULAR_DEV}/${pathWithoutFragment}`;
- this.document.querySelector('link[rel=canonical]')?.setAttribute('href', fullPath);
+ // Cloudflare Pages redirects /foo to /foo/
+ const fullPathWithSlash = fullPath.endsWith('/') ? fullPath : `${fullPath}/`;
+ this.document.querySelector('link[rel=canonical]')?.setAttribute('href', fullPathWithSlash);
}

private normalizePath(path: string): string {

diff --git a/adev/src/index.html b/adev/src/index.html
index f6d4c0eb48..d0087eaf2a 100644
--- a/adev/src/index.html
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function generateSitemap(distPath: string) {
});

for (const file of htmlFiles) {
stream.write({ url: file.replace(/index\.html$/, '') });
stream.write({ url: file.replace(/\/index\.html$/, '') });
}
stream.end();

Expand Down

0 comments on commit baf8d5a

Please sign in to comment.