-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: URL patterns should not be included in the sitemap (#3380)
## Description URL patterns should not be included in the sitemap. For instance, before this PR, we included paths like /:slug in the sitemap. ## Steps for reproduction Open https://fix-sitemap-slug.staging.webstudio.is/builder/8404e444-093d-4e70-b5c2-03fd89b9eb6d?pageId=EksrLskoGCCreyVN4xp2r See dynamic page is excluded ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory
- Loading branch information
Showing
5 changed files
with
35 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { expect, test } from "@jest/globals"; | ||
import { isPathnamePattern } from "./url-pattern"; | ||
|
||
test("check pathname is pattern", () => { | ||
expect(isPathnamePattern("/:name")).toEqual(true); | ||
expect(isPathnamePattern("/:slug*")).toEqual(true); | ||
expect(isPathnamePattern("/:id?")).toEqual(true); | ||
expect(isPathnamePattern("/*")).toEqual(true); | ||
|
||
expect(isPathnamePattern("")).toEqual(false); | ||
expect(isPathnamePattern("/")).toEqual(false); | ||
expect(isPathnamePattern("/blog")).toEqual(false); | ||
expect(isPathnamePattern("/blog/post-name")).toEqual(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// /:slug -> { name: "slug", modifier: "" } | ||
// /:slug* -> { name: "slug", modifier: "*" } | ||
// /:slug? -> { name: "slug", modifier: "?" } | ||
// /* -> { wildcard: "*" } | ||
const tokenRegex = /:(?<name>\w+)(?<modifier>[?*]?)|(?<wildcard>(?<!:\w+)\*)/; | ||
|
||
export const isPathnamePattern = (pathname: string) => | ||
tokenRegex.test(pathname); | ||
|
||
// use separate regex from matchAll because regex.test is stateful when used with g flag | ||
const tokenRegexGlobal = new RegExp(tokenRegex.source, "g"); | ||
|
||
export const matchPathnameParams = (pathname: string) => { | ||
return pathname.matchAll(tokenRegexGlobal); | ||
}; |