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

Fix test-homepage by fixing paths filter #662

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

gabalafou
Copy link
Contributor

@gabalafou gabalafou commented Feb 9, 2023

@bskinn discovered that /test-homepage in the Consulting Storyblok was not getting deployed to a Vercel preview build.

I think it's because of the way paths were being filtered in the app, rejecting any slug if it it contained any word from a restricted list. One of the words on that list is 'homepage,' so it would match 'test-homepage' (unless I've misread the code somehow).

@vercel
Copy link

vercel bot commented Feb 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
consulting ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 9:31PM (UTC)
labs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 10, 2023 at 9:31PM (UTC)

@gabalafou
Copy link
Contributor Author

I haven't tested this PR and we will need to test it rather thoroughly before merging because it could really break things.

@gabalafou gabalafou requested a review from bskinn February 9, 2023 22:25
Copy link
Contributor

@bskinn bskinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts related to the issue of the blog posts getting double-built, once at post/{postname} and once at post%2F{postname}.

Copy link
Contributor

@bskinn bskinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions

return !restrictedSlugs.some((restrictedSlug) =>
slug.includes(restrictedSlug),
return restrictedSlugs.some((restrictedSlug) =>
new RegExp(restrictedSlug, 'i').test(slug),
Copy link
Contributor

@bskinn bskinn Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular functional advantage to the switch to a regex here? Case-insensitive matching, I guess... expanding the range of what this matches on.

For now, the restrictedSlugs are all plain strings. I'm guessing this is in anticipation of wanting to tighten the matching on restrictedSlugs in the future (or even the present)?

Copy link
Contributor

@bskinn bskinn Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, now I see the odd semantics that were here before... I agree, it makes much more sense for the .some() not to be negated within isSlugRestricted() here, but instead to have the negation at the point of use in getPaths.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We don't need the RegExp for case insensitivity. I will change it.

Copy link
Contributor Author

@gabalafou gabalafou Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what I wrote is just plain wrong, i.e., won't fix the test-homepage issue. 😅

@@ -5,7 +5,9 @@ export const getPaths = <LinkEntry extends { isFolder: boolean; slug: string }>(
items: LinkEntry[],
): TGetPaths[] =>
items
.filter(({ isFolder, slug }) => slug && !isFolder && isSlugRestricted(slug))
.filter(
({ isFolder, slug }) => slug && !isFolder && !isSlugRestricted(slug),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how you fix the other issue:

Suggested change
({ isFolder, slug }) => slug && !isFolder && !isSlugRestricted(slug),
({ isFolder, slug }) =>
slug && !isFolder && !isSlugForPost(slug) && !isSlugRestricted(slug),

return !restrictedSlugs.some((restrictedSlug) =>
slug.includes(restrictedSlug),
return restrictedSlugs.some((restrictedSlug) =>
new RegExp(restrictedSlug, 'i').test(slug),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We don't need the RegExp for case insensitivity. I will change it.

libs/shared/utils/src/getPaths/isSlugRestricted.ts Outdated Show resolved Hide resolved
return !restrictedSlugs.some((restrictedSlug) =>
slug.includes(restrictedSlug),
return restrictedSlugs.some((restrictedSlug) =>
new RegExp(restrictedSlug, 'i').test(slug),
Copy link
Contributor Author

@gabalafou gabalafou Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what I wrote is just plain wrong, i.e., won't fix the test-homepage issue. 😅

return !restrictedSlugs.some((restrictedSlug) =>
slug.includes(restrictedSlug),
return restrictedSlugs.some(
(restrictedSlug) => slug.toLowerCase() === restrictedSlug,
Copy link
Contributor Author

@gabalafou gabalafou Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well now I see why it was written as slug.includes rather than slug ===... Storyblok returns slugs for every Labs team member, e.g.: /team-members/gabriel-fouasnon, but the Next.js /[slug] page cannot build a team member data type, so any slug that includes team-members should be excluded. I'm going to rewrite the restricted slugs as an array of regular expressions, brb

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Regex for the win, then. They should probably all be e.g. ^/home, ^/team-members/, etc., I figure.

Copy link
Contributor Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've simplified things and solved multiple problems. If Vercel preview builds don't fail, then this is ready for review again.

@gabalafou
Copy link
Contributor Author

Here's a dump of all the links

.filter(({ isFolder, slug }) => slug && !isFolder && isSlugRestricted(slug))
.filter(
({ isFolder, slug }) =>
slug && !isFolder && !slug.includes('/') && !isSlugRestricted(slug),
Copy link
Contributor

@bskinn bskinn Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, at least for now. I don't anticipate us wanting a path hierarchy for regular site pages on either the Consulting or the Labs sites... easy enough to change if we do end up wanting it, though.

'library',
'team-members',
'about',
// Labs
'home',
'team',
'blog',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooh, I didn't even think about this being both sites. Good call, esp adding the comments.

@@ -1,10 +1,12 @@
// These are all of the Storyblok slugs that should not match pages/[slug]
// because they are matched to other pages. For example, Labs 'blog' is matched
// to apps/labs/pages/blog/index.tsx.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// to apps/labs/pages/blog/index.tsx.
// to apps/labs/pages/blog/index.tsx.
// Note that all these names will be excluded from pages/[slug]
// on *both* sites, since this is shared code.

@bskinn bskinn added consulting 🤝 Items on the Quansight Consulting site type: bug 🐛 Something isn't working labs 🔭 Items related to the Labs website area: Vercel labels Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Vercel consulting 🤝 Items on the Quansight Consulting site labs 🔭 Items related to the Labs website type: bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants