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.

5 changes: 4 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,10 @@ 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 && !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.

)
.map(({ slug }) => ({
params: {
slug,
Expand Down
4 changes: 1 addition & 3 deletions libs/shared/utils/src/getPaths/isSlugRestricted.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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 === restrictedSlug);
};
10 changes: 6 additions & 4 deletions libs/shared/utils/src/getPaths/restrictedSlugs.ts
Original file line number Diff line number Diff line change
@@ -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.

export const restrictedSlugs: string[] = [
// Consulting
'homepage',
'team',
'layout',
'about-us',
'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.

Expand Down