JSS Next.jsアプリでビルドタイムの静的パスをカスタマイズできます
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
多くのページや商品、記事を持つ大規模なウェブサイトでは、すべてのページの静的生成に時間がかかることがあります。静的生成の一部のページやアイテムを除外することで、静的生成アプリケーションのビルド時間を短縮できます。
これは、SitecoreSitemapFetcherクラス内で初期化・使用されているGraphQLSitemapService/MultisiteGraphQLSitemapServiceインスタンスを修正することで実現できます。
!重要パフォーマンスの理由から、手動で含める・除外できるパスの数はEdgeによって制限されています。この制限を超えるクエリはGraphQLエラーを返します。
JSS Next.jsアプリでビルド時の静的パスをカスタマイズするには:
-
レンダリングアプリケーションフォルダのsrc/lib/sitemap-fetcher/plugins/graphql-sitemap-service.tsファイル内で、GraphqlSitemapServicePlugin構造体を次のように修正します:
!注Next.jsマルチサイトアドオンを使用する場合、siteName: config.jssAppNameの代わりに、サイトリゾルバsites: ...new Set(siteResolver.sites.map((site: SiteInfo) => site.name))からサイトのリストを提供します。
-
パスを含めるには、GraphQLSitemapServiceインスタンスのincludedPathsパラメータにパスの配列を提供します。includedPathsを指定すると、クエリは提供されたパターンに一致するパスのみを返します。例えば、/products/で始まるすべてのパスを含める場合:
constructor() { this._graphqlSitemapService = new GraphQLSitemapService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, siteName: config.jssAppName, includedPaths: "/products/" }); }
-
パスを除外するには、GraphQLSitemapServiceインスタンスのexcludedPathsパラメータへのパス配列を提供します。例えば、/products/で始まるパスを含めるには、古い電話に関するパスは除きます:
constructor() { this._graphqlSitemapService = new GraphQLSitemapService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, siteName: config.jssAppName, includedPaths: "/products/", excludedPaths: "/products/old-phones/" }); }
-
一部の経路を除くすべての経路を取得するには、excludedPathsパラメータのみを使用できます。例えば、積のすべての経路を除外する場合:
constructor() { this._graphqlSitemapService = new GraphQLSitemapService({ endpoint: config.graphQLEndpoint, apiKey: config.sitecoreApiKey, siteName: config.jssAppName, exludedPaths: "/products/" }); }
-