-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
189 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Database connection string | ||
POSTGRES_URL=postgresql://127.0.0.1:5432/payload-template-website | ||
POSTGRES_URL=mongodb://127.0.0.1/payload-template-website | ||
# Or use a PG connection string | ||
#DATABASE_URI=postgresql://127.0.0.1:5432/payload-template-website | ||
# Used to encrypt JWT tokens | ||
PAYLOAD_SECRET=YOUR_SECRET_HERE | ||
# Used to configure CORS, format links and more. No trailing slash | ||
NEXT_PUBLIC_SERVER_URL=http://localhost:3000 | ||
|
||
# Your Vercel Blob storage write token | ||
BLOB_READ_WRITE_TOKEN='vercel_blob_rw_test_123' | ||
NEXT_PUBLIC_SERVER_URL=http://localhost:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ node_modules | |
|
||
# Payload default media upload directory | ||
public/media/ | ||
|
||
public/robots.txt | ||
public/sitemap*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
legacy-peer-deps=true | ||
legacy-peer-deps=true | ||
enable-pre-post-scripts=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type {import('next-sitemap').IConfig} */ | ||
const SITE_URL = | ||
process.env.NEXT_PUBLIC_SERVER_URL || | ||
process.env.VERCEL_PROJECT_PRODUCTION_URL || | ||
'https://example.com' | ||
|
||
module.exports = { | ||
siteUrl: SITE_URL, | ||
generateRobotsTxt: true, | ||
exclude: ['/posts-sitemap.xml', '/pages-sitemap.xml', '/*', '/posts/*'], | ||
robotsTxtOptions: { | ||
additionalSitemaps: [`${SITE_URL}/pages-sitemap.xml`, `${SITE_URL}/posts-sitemap.xml`], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
templates/with-vercel-website/src/app/(frontend)/(sitemaps)/pages-sitemap.xml/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { getServerSideSitemap } from 'next-sitemap' | ||
import { getPayload } from 'payload' | ||
import config from '@payload-config' | ||
import { unstable_cache } from 'next/cache' | ||
|
||
const getPagesSitemap = unstable_cache( | ||
async () => { | ||
const payload = await getPayload({ config }) | ||
const SITE_URL = | ||
process.env.NEXT_PUBLIC_SERVER_URL || | ||
process.env.VERCEL_PROJECT_PRODUCTION_URL || | ||
'https://example.com' | ||
|
||
const results = await payload.find({ | ||
collection: 'pages', | ||
overrideAccess: false, | ||
draft: false, | ||
depth: 0, | ||
limit: 1000, | ||
pagination: false, | ||
where: { | ||
_status: { | ||
equals: 'published', | ||
}, | ||
}, | ||
select: { | ||
slug: true, | ||
updatedAt: true, | ||
}, | ||
}) | ||
|
||
const dateFallback = new Date().toISOString() | ||
|
||
const defaultSitemap = [ | ||
{ | ||
loc: `${SITE_URL}/search`, | ||
lastmod: dateFallback, | ||
}, | ||
{ | ||
loc: `${SITE_URL}/posts`, | ||
lastmod: dateFallback, | ||
}, | ||
] | ||
|
||
const sitemap = results.docs | ||
? results.docs | ||
.filter((page) => Boolean(page?.slug)) | ||
.map((page) => { | ||
return { | ||
loc: page?.slug === 'home' ? `${SITE_URL}/` : `${SITE_URL}/${page?.slug}`, | ||
lastmod: page.updatedAt || dateFallback, | ||
} | ||
}) | ||
: [] | ||
|
||
return [...defaultSitemap, ...sitemap] | ||
}, | ||
['pages-sitemap'], | ||
{ | ||
tags: ['pages-sitemap'], | ||
}, | ||
) | ||
|
||
export async function GET() { | ||
const sitemap = await getPagesSitemap() | ||
|
||
return getServerSideSitemap(sitemap) | ||
} |
55 changes: 55 additions & 0 deletions
55
templates/with-vercel-website/src/app/(frontend)/(sitemaps)/posts-sitemap.xml/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getServerSideSitemap } from 'next-sitemap' | ||
import { getPayload } from 'payload' | ||
import config from '@payload-config' | ||
import { unstable_cache } from 'next/cache' | ||
|
||
const getPostsSitemap = unstable_cache( | ||
async () => { | ||
const payload = await getPayload({ config }) | ||
const SITE_URL = | ||
process.env.NEXT_PUBLIC_SERVER_URL || | ||
process.env.VERCEL_PROJECT_PRODUCTION_URL || | ||
'https://example.com' | ||
|
||
const results = await payload.find({ | ||
collection: 'posts', | ||
overrideAccess: false, | ||
draft: false, | ||
depth: 0, | ||
limit: 1000, | ||
pagination: false, | ||
where: { | ||
_status: { | ||
equals: 'published', | ||
}, | ||
}, | ||
select: { | ||
slug: true, | ||
updatedAt: true, | ||
}, | ||
}) | ||
|
||
const dateFallback = new Date().toISOString() | ||
|
||
const sitemap = results.docs | ||
? results.docs | ||
.filter((post) => Boolean(post?.slug)) | ||
.map((post) => ({ | ||
loc: `${SITE_URL}/posts/${post?.slug}`, | ||
lastmod: post.updatedAt || dateFallback, | ||
})) | ||
: [] | ||
|
||
return sitemap | ||
}, | ||
['posts-sitemap'], | ||
{ | ||
tags: ['posts-sitemap'], | ||
}, | ||
) | ||
|
||
export async function GET() { | ||
const sitemap = await getPostsSitemap() | ||
|
||
return getServerSideSitemap(sitemap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters