Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prefer exact matches in getNodePath. #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sxn
Copy link

@sxn sxn commented May 3, 2021

We've run into an issue where some of our pages were incorrectly matched during sitemap generation. After unsuccessfully trying to solve the issue on our side through various means, we decided to try and see if fixing it on the plugin's side would be accepted.

Description

This PR updates getNodePath to prefer exact matches instead of partial ones. As it currently stands, node is matched to the first entry in allSitePage.edges that matches const slugRegex = new RegExp(${node.path.replace(//$/, ``)}$, gi`)`

Given the following:

const node = { path: '/test/',};
const allSitePage = { 
  edges: [
    { node: { url: '/some/test/',},},
    { node: { url: '/test/',},},
  ],};

getNodePath as it currently stands will (incorrectly) match node to allSitePage.edges[0] instead of the more appropriate allSitePage.edges[1].

This PR tries to fix this issue by doing both a partial and an exact match. If an exact match is found, then getNodePath immediately returns. If a partial match is found, it continues executing until either an exact match is found or the list is exhausted, at which point it will return the last partial match it finds.

@sxn sxn force-pushed the feature/prefer-exact-matches branch from 0261ef7 to bc10c84 Compare July 27, 2021 06:53
@sxn sxn force-pushed the feature/prefer-exact-matches branch from bc10c84 to bf2e425 Compare November 10, 2021 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant