Loading...
; if (error) returnError! {error.message}
; - const { title, date, author, editorBlocks } = post; + const { title, date, author, uri, excerpt, editorBlocks } = post; const blockList = flatListToHierarchical(editorBlocks, { childrenKey: "innerBlocks", }); return (
{author.node.name} ·{" "}
@@ -43,6 +49,8 @@ SinglePost.query = gql`
post(id: $slug, idType: SLUG) {
title
date
+ uri
+ excerpt
author {
node {
name
diff --git a/src/pages/blog/index.jsx b/src/pages/blog/index.jsx
index 280529bc..6a9b7256 100644
--- a/src/pages/blog/index.jsx
+++ b/src/pages/blog/index.jsx
@@ -5,6 +5,7 @@ import Link from "next/link";
import { useState, useEffect } from "react";
import Card from "@/components/card";
import Date from "@/components/date";
+import Seo from "@/components/seo";
const GET_POSTS = gql`
query getPosts($first: Int!, $after: String) {
@@ -83,6 +84,11 @@ export default function BlogIndex() {
return (
Faust.js news
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index 575f7cbf..b2a1fefd 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -8,11 +8,16 @@ import {
} from "@heroicons/react/24/outline";
import Card from "@/components/card";
import Link from "@/components/link";
+import Seo from "@/components/seo";
-// The Component is required
export default function Index() {
return (
Faust.js™ Showcase
diff --git a/src/pages/wp-sitemap.xml/index.jsx b/src/pages/wp-sitemap.xml/index.jsx
new file mode 100644
index 00000000..3073bcc1
--- /dev/null
+++ b/src/pages/wp-sitemap.xml/index.jsx
@@ -0,0 +1,57 @@
+import { env } from "node:process";
+import { URL } from "node:url";
+import { gql } from "@apollo/client";
+import { getApolloClient } from "@faustwp/core";
+import { getServerSideSitemapLegacy } from "next-sitemap";
+
+export const getServerSideProps = async (ctx) => {
+ const client = getApolloClient();
+
+ async function getPaginatedQuery(query, previousPosts = []) {
+ const res = await client.query(query);
+
+ const newPosts = [...previousPosts, ...res.data.posts.nodes];
+ if (res.data.posts.pageInfo.hasNextPage) {
+ return getPaginatedQuery(
+ {
+ query: query.query,
+ variables: {
+ after: res.data.posts.pageInfo.endCursor,
+ first: query.variables.first,
+ },
+ },
+ newPosts,
+ );
+ }
+
+ return newPosts;
+ }
+
+ const posts = await getPaginatedQuery({
+ query: gql`
+ query getPosts($first: Int!, $after: String) {
+ posts(first: $first, after: $after) {
+ nodes {
+ uri
+ modified
+ }
+ pageInfo {
+ hasNextPage
+ endCursor
+ }
+ }
+ }
+ `,
+ variables: { first: 10 },
+ });
+
+ const fields = posts.map((post) => ({
+ loc: new URL(post.uri, env.NEXT_PUBLIC_SITE_URL).href, // Absolute url
+ lastmod: post.modified,
+ }));
+
+ return getServerSideSitemapLegacy(ctx, fields);
+};
+
+// Default export to prevent next.js errors
+export default function Sitemap() {}