web: optimize news fetching

This commit is contained in:
2026-05-25 19:57:00 +02:00
parent 0b0fba174e
commit c9a2720d64
5 changed files with 38 additions and 11 deletions
+7 -2
View File
@@ -1,16 +1,21 @@
import { Metadata, ResolvingMetadata } from "next";
import { getClient } from "@/app/client";
import {
NewsIndexView,
loadNewsIndexProps,
} from "@/components/news/NewsIndexView";
import { NewsIndexFragment } from "@/gql/graphql";
import { newsIndexMetadataQuery } from "@/lib/news";
import { getSeoMetadata } from "@/lib/seo";
export async function generateMetadata(
_: unknown,
parent: ResolvingMetadata
): Promise<Metadata | null> {
const { index } = await loadNewsIndexProps();
return getSeoMetadata(index, parent);
const { data, error } = await getClient().query(newsIndexMetadataQuery, {});
if (error) throw new Error(error.message);
if (!data?.index) return null;
return getSeoMetadata(data.index as NewsIndexFragment, parent);
}
export default async function Page() {
+3 -3
View File
@@ -1,11 +1,11 @@
import { getClient } from "@/app/client";
import { PageHeader } from "@/components/general/PageHeader";
import { NewsList } from "@/components/news/NewsList";
import { NewsFragment, NewsIndexFragment, newsQuery } from "@/lib/news";
import { NewsIndexFragment, NewsListItemFragment, newsQuery } from "@/lib/news";
export type NewsIndexViewProps = {
index: NewsIndexFragment;
news: NewsFragment[];
news: NewsListItemFragment[];
};
export async function loadNewsIndexProps(overrides?: {
@@ -15,7 +15,7 @@ export async function loadNewsIndexProps(overrides?: {
if (error) throw new Error(error.message);
const index = overrides?.indexOverride ?? (data?.index as NewsIndexFragment | undefined);
if (!index) throw new Error("Failed to load /aktuelt");
const news = (data?.news ?? []) as NewsFragment[];
const news = (data?.news ?? []) as NewsListItemFragment[];
return { index, news };
}
+9 -3
View File
@@ -73,7 +73,8 @@ type Documents = {
"\n fragment NewsListItem on NewsPage {\n __typename\n id\n slug\n title\n firstPublishedAt\n excerpt\n featuredImage {\n ...Image\n }\n }\n": typeof types.NewsListItemFragmentDoc,
"\n fragment News on NewsPage {\n __typename\n id\n slug\n seoTitle\n searchDescription\n title\n firstPublishedAt\n excerpt\n lead\n featuredImage {\n ...Image\n }\n body {\n ...Blocks\n }\n }\n": typeof types.NewsFragmentDoc,
"\n fragment NewsIndex on NewsIndex {\n __typename\n id\n slug\n seoTitle\n searchDescription\n title\n lead\n }\n": typeof types.NewsIndexFragmentDoc,
"\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...News\n }\n }\n }\n": typeof types.NewsDocument,
"\n query newsIndexMetadata {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n }\n": typeof types.NewsIndexMetadataDocument,
"\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...NewsListItem\n }\n }\n }\n": typeof types.NewsDocument,
"\n query openingHoursSets {\n openingHoursSets {\n ...OpeningHoursSet\n }\n }\n": typeof types.OpeningHoursSetsDocument,
"\n fragment OpeningHoursSet on OpeningHoursSet {\n name\n effectiveFrom\n effectiveTo\n announcement\n items {\n id\n function\n week {\n __typename\n ... on OpeningHoursWeekBlock {\n ...OpeningHoursWeekBlock\n }\n }\n }\n }\n": typeof types.OpeningHoursSetFragmentDoc,
"\n fragment OpeningHoursRangeBlock on OpeningHoursRangeBlock {\n timeFrom\n timeTo\n custom\n }\n": typeof types.OpeningHoursRangeBlockFragmentDoc,
@@ -139,7 +140,8 @@ const documents: Documents = {
"\n fragment NewsListItem on NewsPage {\n __typename\n id\n slug\n title\n firstPublishedAt\n excerpt\n featuredImage {\n ...Image\n }\n }\n": types.NewsListItemFragmentDoc,
"\n fragment News on NewsPage {\n __typename\n id\n slug\n seoTitle\n searchDescription\n title\n firstPublishedAt\n excerpt\n lead\n featuredImage {\n ...Image\n }\n body {\n ...Blocks\n }\n }\n": types.NewsFragmentDoc,
"\n fragment NewsIndex on NewsIndex {\n __typename\n id\n slug\n seoTitle\n searchDescription\n title\n lead\n }\n": types.NewsIndexFragmentDoc,
"\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...News\n }\n }\n }\n": types.NewsDocument,
"\n query newsIndexMetadata {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n }\n": types.NewsIndexMetadataDocument,
"\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...NewsListItem\n }\n }\n }\n": types.NewsDocument,
"\n query openingHoursSets {\n openingHoursSets {\n ...OpeningHoursSet\n }\n }\n": types.OpeningHoursSetsDocument,
"\n fragment OpeningHoursSet on OpeningHoursSet {\n name\n effectiveFrom\n effectiveTo\n announcement\n items {\n id\n function\n week {\n __typename\n ... on OpeningHoursWeekBlock {\n ...OpeningHoursWeekBlock\n }\n }\n }\n }\n": types.OpeningHoursSetFragmentDoc,
"\n fragment OpeningHoursRangeBlock on OpeningHoursRangeBlock {\n timeFrom\n timeTo\n custom\n }\n": types.OpeningHoursRangeBlockFragmentDoc,
@@ -399,7 +401,11 @@ export function graphql(source: "\n fragment NewsIndex on NewsIndex {\n __ty
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...News\n }\n }\n }\n"): (typeof documents)["\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...News\n }\n }\n }\n"];
export function graphql(source: "\n query newsIndexMetadata {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n }\n"): (typeof documents)["\n query newsIndexMetadata {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...NewsListItem\n }\n }\n }\n"): (typeof documents)["\n query news {\n index: newsIndex {\n ... on NewsIndex {\n ...NewsIndex\n }\n }\n news: pages(contentType: \"news.NewsPage\", order: \"-first_published_at\", limit: 1000) {\n ... on NewsPage {\n ...NewsListItem\n }\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
File diff suppressed because one or more lines are too long
+11 -1
View File
@@ -49,6 +49,16 @@ const NewsIndexFragmentDefinition = graphql(`
}
`);
export const newsIndexMetadataQuery = graphql(`
query newsIndexMetadata {
index: newsIndex {
... on NewsIndex {
...NewsIndex
}
}
}
`);
export const newsQuery = graphql(`
query news {
index: newsIndex {
@@ -58,7 +68,7 @@ export const newsQuery = graphql(`
}
news: pages(contentType: "news.NewsPage", order: "-first_published_at", limit: 1000) {
... on NewsPage {
...News
...NewsListItem
}
}
}