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) => 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.

);
};