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
4 changes: 2 additions & 2 deletions apps/consulting/utils/getArticlesPaths/getArticlesPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { TLinkEntry } from '@quansight/shared/types';

import { LinkEntry } from '../../api/types/basic';
import { formatSlugParam } from './formatSlugParam';
import { isSlugRestricted } from './isSlugRestricted';
import { isSlugForPost } from './isSlugForPost';
bskinn marked this conversation as resolved.
Show resolved Hide resolved
import { TGetArticlesPaths } from './types';

export const getArticlesPaths = (
items: TLinkEntry<LinkEntry>[],
): TGetArticlesPaths[] =>
items
.filter(({ isFolder, slug }) => slug && !isFolder && isSlugRestricted(slug))
.filter(({ isFolder, slug }) => slug && !isFolder && isSlugForPost(slug))
.map(({ slug }) => ({
params: {
slug: formatSlugParam(slug),
Expand Down
4 changes: 4 additions & 0 deletions apps/consulting/utils/getArticlesPaths/isSlugForPost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ARTICLES_DIRECTORY_SLUG } from './constants';

export const isSlugForPost = (slug: string): boolean =>
slug.startsWith(ARTICLES_DIRECTORY_SLUG);
bskinn marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 0 additions & 4 deletions apps/consulting/utils/getArticlesPaths/isSlugRestricted.ts

This file was deleted.

4 changes: 3 additions & 1 deletion libs/shared/utils/src/getPaths/getPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),

)
.map(({ slug }) => ({
params: {
slug,
Expand Down
4 changes: 2 additions & 2 deletions libs/shared/utils/src/getPaths/isSlugRestricted.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { restrictedSlugs } from './restrictedSlugs';
bskinn marked this conversation as resolved.
Show resolved Hide resolved

export const isSlugRestricted = (slug: string): boolean => {
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. 😅

gabalafou marked this conversation as resolved.
Show resolved Hide resolved
);
};