faustjs icon indicating copy to clipboard operation
faustjs copied to clipboard

Feature recommendation: fetching all paths during getStaticPaths (of pages, of posts, and of custom post types).

Open roeean opened this issue 1 year ago • 0 comments

Hi,

My project has many pages and posts - most of them are "custom-type" posts. In Faust.js documentation, you showed an example of how to pull the "first five pages" while I created a function that I think might interest you:

To guarantee the revalidation of all pages and posts, the function is pulling all their paths in getStaticPaths:

export const getStaticPaths = async () => {
  const { query, inlineResolved } = client.client;

  //* Fetch all post types that exist in graphQL
  const postTypes = await inlineResolved(() => [...query.contentTypes().nodes]
    .map(({ graphqlPluralName }) => graphqlPluralName)
    .filter(type => type !== 'mediaItems')
  );

  //* Fetch all paths
  const paths = await inlineResolved(() => postTypes.reduce(
    (prev, cur) => {
      const typeFn = cur[0].toLowerCase() + cur.substring(1);
      return [...prev, ...query[typeFn]()?.nodes.map(({ uri }) => uri)];
    }, []));

  return {
    fallback: 'blocking',
    paths
  };
};

Maybe consider adding such an option in one of the following versions,

Roee Angel

roeean avatar Aug 09 '22 10:08 roeean