From 19921ac567ac6b7cd32f67e9529633d570d9353d Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 12 Jun 2024 14:33:25 -0600 Subject: [PATCH 1/4] - update .gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 6f1e718..f94c050 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # next.js /.next/ /out/ +next-env.d.ts # production /build @@ -24,6 +25,8 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +logs +*.log # local env files .env.local @@ -38,3 +41,7 @@ yarn-error.log* .faust globalStylesheet.css possibleTypes.json + +## Build artifacts for sitemaps +/public/sitemap*.xml +/public/robots.txt From 78f17cdd245a1b960405dbdd0d3543ba09c49372 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 12 Jun 2024 14:34:34 -0600 Subject: [PATCH 2/4] - add next-sitemap as dependency - add postbuild command to build sitemap - add next-sitemap.config.js - add wordpress-sitemap.xml.js --- next-sitemap.config.js | 24 ++++++++++++ package.json | 4 +- pages/wordpress-sitemap.xml.js | 71 ++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 next-sitemap.config.js create mode 100644 pages/wordpress-sitemap.xml.js diff --git a/next-sitemap.config.js b/next-sitemap.config.js new file mode 100644 index 0000000..e60e5cd --- /dev/null +++ b/next-sitemap.config.js @@ -0,0 +1,24 @@ +/** @type {import('next-sitemap').IConfig} */ + +const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL + +module.exports = { + siteUrl: SITE_URL, + generateRobotsTxt: true, + exclude: ["/docs-sitemap.xml", "/docs/*"], + robotsTxtOptions: { + additionalSitemaps: [ + `${SITE_URL}/wordpress-sitemap.xml`, // <==== Add here + ], + }, + transform: (config, path) => { + if (path.match(/\/\d{4}\/\d{2}\/\d{2}\/.*/gim)) { + return null + } + + return { + loc: path, + lastmod: config.autoLastmod ? new Date().toISOString() : undefined, + } + }, +} diff --git a/package.json b/package.json index ad892b8..62c54ba 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "lint": "eslint . --ext js,jsx,ts,tsx", "lint:fix": "eslint . --ext js,jsx,ts,tsx --fix", "predev": "npm run generate", - "prebuild": "npm run generate" + "prebuild": "npm run generate", + "postbuild": "next-sitemap" }, "dependencies": { "@algolia/autocomplete-core": "^1.9.2", @@ -56,6 +57,7 @@ "mdast-util-to-string": "^3.1.0", "mdx-annotations": "^0.1.1", "next": "^13.1.6", + "next-sitemap": "^3.1.3", "next-themes": "^0.2.1", "postcss-focus-visible": "^6.0.4", "postcss-import": "^14.1.0", diff --git a/pages/wordpress-sitemap.xml.js b/pages/wordpress-sitemap.xml.js new file mode 100644 index 0000000..433de26 --- /dev/null +++ b/pages/wordpress-sitemap.xml.js @@ -0,0 +1,71 @@ +import { gql } from "@apollo/client" +import { getApolloClient } from "@faustwp/core/dist/mjs/client" +import { getServerSideSitemapLegacy } from "next-sitemap" + +const client = getApolloClient() + +const SITEMAP_QUERY = gql` +query SitemapQuery($after: String) { + contentNodes( + where: { + contentTypes: [ + FIELD_TYPE + POST + PAGE + ] + } + first: 50 + after: $after + ) { + pageInfo { + hasNextPage + endCursor + } + nodes { + uri + modifiedGmt + } + } + } +` + +async function getAllWPContent(after = null, acc = []) { + const { data } = await client.query({ + query: SITEMAP_QUERY, + variables: { + after, + }, + }) + + console.log(data.contentNodes.nodes) + acc = [...acc, ...data.contentNodes.nodes] + + if (data.contentNodes.pageInfo.hasNextPage) { + acc = await getAllWPContent(data.contentNodes.pageInfo.endCursor, acc) + } + + return acc +} + +// Sitemap component +export default function WPSitemap() {} + +// collect all the post +export const getServerSideProps = async (ctx) => { + const nodes = await getAllWPContent() + + const allRoutes = nodes.reduce((acc, node) => { + if (!node.uri) { + return acc + } + + acc.push({ + loc: node.uri, + lastmod: new Date(node.modifiedGmt).toISOString(), + }) + + return acc + }, []) + + return await getServerSideSitemapLegacy(ctx, allRoutes) +} From c47f1cabbd63d80282f52e337ebf5d68abeddf9f Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Wed, 12 Jun 2024 14:36:48 -0600 Subject: [PATCH 3/4] fix misc linting issues --- components/Callout.jsx | 2 +- components/DocsSidebarNavigation.jsx | 4 ++-- components/MobileNavigation.jsx | 4 ++-- components/PrimaryNavigation.jsx | 2 +- components/QuickLinks.jsx | 2 +- components/Search.jsx | 4 ++-- components/SiteHeader.jsx | 4 ++-- components/ThemeSelector.jsx | 14 +++++++------- components/ui/accordion.tsx | 2 +- components/ui/context-menu.jsx | 10 +++++----- components/ui/dropdown-menu.tsx | 10 +++++----- components/ui/navigation-menu.tsx | 4 ++-- wp-blocks/AcfFieldTypeSettingsBlock.js | 18 +++++++++--------- 13 files changed, 40 insertions(+), 40 deletions(-) diff --git a/components/Callout.jsx b/components/Callout.jsx index f6e39aa..e459ea9 100644 --- a/components/Callout.jsx +++ b/components/Callout.jsx @@ -27,7 +27,7 @@ export function Callout({ type = 'note', title, children }) { return (
- +

{title} diff --git a/components/DocsSidebarNavigation.jsx b/components/DocsSidebarNavigation.jsx index d1ca716..243d8ed 100644 --- a/components/DocsSidebarNavigation.jsx +++ b/components/DocsSidebarNavigation.jsx @@ -25,7 +25,7 @@ export function DocsSidebarNavigation({ className, data, navigation }) { if (!currentNode) { return false; } - + return section.links.some(link => link.href.includes(currentNode.uri)); }; @@ -61,7 +61,7 @@ export function DocsSidebarNavigation({ className, data, navigation }) { > - + setIsOpen(false)} aria-label="Close navigation" > - + diff --git a/components/PrimaryNavigation.jsx b/components/PrimaryNavigation.jsx index 51981ba..2de4c41 100644 --- a/components/PrimaryNavigation.jsx +++ b/components/PrimaryNavigation.jsx @@ -63,7 +63,7 @@ export function PrimaryNavigation({ navigation }) {

  • diff --git a/components/QuickLinks.jsx b/components/QuickLinks.jsx index 0ea3dee..2e38467 100644 --- a/components/QuickLinks.jsx +++ b/components/QuickLinks.jsx @@ -15,7 +15,7 @@ export function QuickLink({ title, description, href, icon }) {
    - +

    diff --git a/components/Search.jsx b/components/Search.jsx index adcd3f0..c1641e3 100644 --- a/components/Search.jsx +++ b/components/Search.jsx @@ -124,13 +124,13 @@ export function Search({ ...props }) { return (

    diff --git a/components/ThemeSelector.jsx b/components/ThemeSelector.jsx index 6c28da3..dabca58 100644 --- a/components/ThemeSelector.jsx +++ b/components/ThemeSelector.jsx @@ -1,9 +1,9 @@ "use client" - + import { MoonIcon, SunIcon } from "@radix-ui/react-icons" import { useTheme } from "next-themes" import * as React from "react" - + import { Button } from "@/components/ui/button" import { DropdownMenu, @@ -11,16 +11,16 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" - + export function ModeToggle() { const { setTheme } = useTheme() - + return ( @@ -37,4 +37,4 @@ export function ModeToggle() { ) -} \ No newline at end of file +} diff --git a/components/ui/accordion.tsx b/components/ui/accordion.tsx index 0a65dcc..3a309e9 100644 --- a/components/ui/accordion.tsx +++ b/components/ui/accordion.tsx @@ -34,7 +34,7 @@ const AccordionTrigger = React.forwardRef< {...props} > {children} - + )) diff --git a/components/ui/context-menu.jsx b/components/ui/context-menu.jsx index 946532d..e909b9b 100644 --- a/components/ui/context-menu.jsx +++ b/components/ui/context-menu.jsx @@ -26,7 +26,7 @@ const ContextMenuSubTrigger = React.forwardRef(({ className, inset, children, .. )} {...props}> {children} - + )) ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName @@ -76,9 +76,9 @@ const ContextMenuCheckboxItem = React.forwardRef(({ className, children, checked )} checked={checked} {...props}> - + - + {children} @@ -95,9 +95,9 @@ const ContextMenuRadioItem = React.forwardRef(({ className, children, ...props } className )} {...props}> - + - + {children} diff --git a/components/ui/dropdown-menu.tsx b/components/ui/dropdown-menu.tsx index 6aae945..08a43bd 100644 --- a/components/ui/dropdown-menu.tsx +++ b/components/ui/dropdown-menu.tsx @@ -38,7 +38,7 @@ const DropdownMenuSubTrigger = React.forwardRef< {...props} > {children} - + )) DropdownMenuSubTrigger.displayName = @@ -110,9 +110,9 @@ const DropdownMenuCheckboxItem = React.forwardRef< checked={checked} {...props} > - + - + {children} @@ -133,9 +133,9 @@ const DropdownMenuRadioItem = React.forwardRef< )} {...props} > - + - + {children} diff --git a/components/ui/navigation-menu.tsx b/components/ui/navigation-menu.tsx index d45d53d..154ba3a 100644 --- a/components/ui/navigation-menu.tsx +++ b/components/ui/navigation-menu.tsx @@ -55,7 +55,7 @@ const NavigationMenuTrigger = React.forwardRef< > {children}{' '}