feat(templates): website template now has configured image sizes, updated readme and simplified env vars for setting up (#9036)

This commit is contained in:
Paul
2024-11-05 11:59:29 -06:00
committed by GitHub
parent ebd3c025b7
commit 201d68663e
6 changed files with 220 additions and 28 deletions

View File

@@ -4,17 +4,5 @@ DATABASE_URI=mongodb://127.0.0.1/payload-template-website
# Used to encrypt JWT tokens # Used to encrypt JWT tokens
PAYLOAD_SECRET=YOUR_SECRET_HERE PAYLOAD_SECRET=YOUR_SECRET_HERE
# Used to format links and URLs # Used to configure CORS, format links and more. No trailing slash
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_SERVER_URL=http://localhost:3000 NEXT_PUBLIC_SERVER_URL=http://localhost:3000
# Allow robots to index the site (optional)
NEXT_PUBLIC_IS_LIVE=
# Used to preview drafts
PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret
# Used to revalidate static pages
REVALIDATION_KEY=demo-revalation-key
NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key

View File

@@ -6,7 +6,7 @@ This template is right for you if you are working on:
- A personal or enterprise-grade website, blog, or portfolio - A personal or enterprise-grade website, blog, or portfolio
- A content publishing platform with a fully featured publication workflow - A content publishing platform with a fully featured publication workflow
- A lead generation website with premium content gated behind authentication - Exploring the capabilities of Payload
Core features: Core features:
@@ -36,13 +36,17 @@ Go to Payload Cloud and [clone this template](https://payloadcms.com/new/clone/w
Use the `create-payload-app` CLI to clone this template directly to your machine: Use the `create-payload-app` CLI to clone this template directly to your machine:
npx create-payload-app@beta my-project -t website ```bash
pnpx create-payload-app@beta my-project -t website
```
#### Method 3 #### Method 3
Use the `git` CLI to clone this template directly to your machine: Use the `git` CLI to clone this template directly to your machine:
git clone -n --depth=1 --filter=tree:0 https://github.com/payloadcms/payload my-project && cd my-project && git sparse-checkout set --no-cone templates/website && git checkout && rm -rf .git && git init && git add . && git mv -f templates/website/{.,}* . && git add . && git commit -m "Initial commit" ```bash
git clone -n --depth=1 --filter=tree:0 https://github.com/payloadcms/payload my-project && cd my-project && git sparse-checkout set --no-cone templates/website && git checkout && rm -rf .git && git init && git add . && git mv -f templates/website/{.,}* . && git add . && git commit -m "Initial commit"
```
### Development ### Development
@@ -77,7 +81,7 @@ See the [Collections](https://payloadcms.com/docs/beta/configuration/collections
- #### Media - #### Media
This is the uploads enabled collection used by pages, posts, and projects to contain media like images, videos, downloads, and other assets. This is the uploads enabled collection used by pages, posts, and projects to contain media like images, videos, downloads, and other assets. It features pre-configured sizes, focal point and manual resizing to help you manage your pictures.
- #### Categories - #### Categories
@@ -137,6 +141,10 @@ In addition to draft previews you can also enable live preview to view your end
This template comes pre-configured with the official [Payload SEO Plugin](https://payloadcms.com/docs/beta/plugins/seo) for complete SEO control from the admin panel. All SEO data is fully integrated into the front-end website that comes with this template. See [Website](#website) for more details. This template comes pre-configured with the official [Payload SEO Plugin](https://payloadcms.com/docs/beta/plugins/seo) for complete SEO control from the admin panel. All SEO data is fully integrated into the front-end website that comes with this template. See [Website](#website) for more details.
## Search
This template also pre-configured with the official [Payload Saerch Plugin](https://payloadcms.com/docs/beta/plugins/search) to showcase how SSR search features can easily be implemented into Next.js with Payload. See [Website](#website) for more details.
## Redirects ## Redirects
If you are migrating an existing site or moving content to a new URL, you can use the `redirects` collection to create a proper redirect from old URLs to new ones. This will ensure that proper request status codes are returned to search engines and that your users are not left with a broken link. This template comes pre-configured with the official [Payload Redirects Plugin](https://payloadcms.com/docs/beta/plugins/redirects) for complete redirect control from the admin panel. All redirects are fully integrated into the front-end website that comes with this template. See [Website](#website) for more details. If you are migrating an existing site or moving content to a new URL, you can use the `redirects` collection to create a proper redirect from old URLs to new ones. This will ensure that proper request status codes are returned to search engines and that your users are not left with a broken link. This template comes pre-configured with the official [Payload Redirects Plugin](https://payloadcms.com/docs/beta/plugins/redirects) for complete redirect control from the admin panel. All redirects are fully integrated into the front-end website that comes with this template. See [Website](#website) for more details.
@@ -153,13 +161,13 @@ Core features:
- [Payload Admin Bar](https://github.com/payloadcms/payload-admin-bar) - [Payload Admin Bar](https://github.com/payloadcms/payload-admin-bar)
- [TailwindCSS styling](https://tailwindcss.com/) - [TailwindCSS styling](https://tailwindcss.com/)
- [shadcn/ui components](https://ui.shadcn.com/) - [shadcn/ui components](https://ui.shadcn.com/)
- Authentication - User Accounts and Authentication
- Fully featured blog - Fully featured blog
- Publication workflow - Publication workflow
- User accounts
- Dark mode - Dark mode
- Pre-made layout building blocks - Pre-made layout building blocks
- SEO - SEO
- Search
- Redirects - Redirects
- Live preview - Live preview
@@ -207,14 +215,57 @@ The easiest way to deploy your project is to use [Payload Cloud](https://payload
### Deploying to Vercel ### Deploying to Vercel
Coming soon. This template can also be deployed to Vercel for free. You can get started by choosing the Vercel DB adapter during the setup of the template or by manually installing and configuring it:
```bash
pnpm add @payloadcms/db-vercel-postgres
```
```ts
// payload.config.ts
import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'
export default buildConfig({
// ...
db: vercelPostgresAdapter({
pool: {
connectionString: process.env.POSTGRES_URL || '',
},
}),
// ...
```
We also support Vercel's blob storage:
```bash
pnpm add @payloadcms/storage-vercel-blob
```
```ts
// payload.config.ts
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
export default buildConfig({
// ...
plugins: [
vercelBlobStorage({
collections: {
[Media.slug]: true,
},
token: process.env.BLOB_READ_WRITE_TOKEN || '',
}),
],
// ...
```
There is also a simplified [one click deploy](https://github.com/payloadcms/payload/tree/beta/templates/with-vercel-postgres) to Vercel should you need it.
### Self-hosting ### Self-hosting
Before deploying your app, you need to: Before deploying your app, you need to:
1. Ensure your app builds and serves in production. See [Production](#production) for more details. 1. Ensure your app builds and serves in production. See [Production](#production) for more details.
2. Serve it from a 2. You can then deploy Payload as you would any other Node.js or Next.js application either directly on a VPS, DigitalOcean's Apps Platform, via Coolify or more. More guides coming soon.
You can also deploy your app manually, check out the [deployment documentation](https://payloadcms.com/docs/beta/production/deployment) for full details. You can also deploy your app manually, check out the [deployment documentation](https://payloadcms.com/docs/beta/production/deployment) for full details.

View File

@@ -41,5 +41,32 @@ export const Media: CollectionConfig = {
upload: { upload: {
// Upload to the public/media directory in Next.js making them publicly accessible even outside of Payload // Upload to the public/media directory in Next.js making them publicly accessible even outside of Payload
staticDir: path.resolve(dirname, '../../public/media'), staticDir: path.resolve(dirname, '../../public/media'),
imageSizes: [
{
name: 'square',
width: 500,
height: 500,
},
{
name: 'thumbnail',
width: 300,
},
{
name: 'small',
width: 600,
},
{
name: 'medium',
width: 900,
},
{
name: 'large',
width: 1400,
},
{
name: 'xlarge',
width: 1400,
},
],
}, },
} }

13
templates/website/src/environment.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
PAYLOAD_SECRET: string
DATABASE_URI: string
NEXT_PUBLIC_SERVER_URL: string
}
}
}
// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
export {}

View File

@@ -24,7 +24,7 @@ export interface Config {
'payload-preferences': PayloadPreference; 'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration; 'payload-migrations': PayloadMigration;
}; };
collectionsSelect: { collectionsSelect?: {
pages: PagesSelect<false> | PagesSelect<true>; pages: PagesSelect<false> | PagesSelect<true>;
posts: PostsSelect<false> | PostsSelect<true>; posts: PostsSelect<false> | PostsSelect<true>;
media: MediaSelect<false> | MediaSelect<true>; media: MediaSelect<false> | MediaSelect<true>;
@@ -45,7 +45,7 @@ export interface Config {
header: Header; header: Header;
footer: Footer; footer: Footer;
}; };
globalsSelect: { globalsSelect?: {
header: HeaderSelect<false> | HeaderSelect<true>; header: HeaderSelect<false> | HeaderSelect<true>;
footer: FooterSelect<false> | FooterSelect<true>; footer: FooterSelect<false> | FooterSelect<true>;
}; };
@@ -164,6 +164,56 @@ export interface Media {
height?: number | null; height?: number | null;
focalX?: number | null; focalX?: number | null;
focalY?: number | null; focalY?: number | null;
sizes?: {
square?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
thumbnail?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
small?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
medium?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
large?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
xlarge?: {
url?: string | null;
width?: number | null;
height?: number | null;
mimeType?: string | null;
filesize?: number | null;
filename?: string | null;
};
};
} }
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
@@ -888,6 +938,70 @@ export interface MediaSelect<T extends boolean = true> {
height?: T; height?: T;
focalX?: T; focalX?: T;
focalY?: T; focalY?: T;
sizes?:
| T
| {
square?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
thumbnail?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
small?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
medium?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
large?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
xlarge?:
| T
| {
url?: T;
width?: T;
height?: T;
mimeType?: T;
filesize?: T;
filename?: T;
};
};
} }
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
@@ -1287,4 +1401,4 @@ export interface Auth {
declare module 'payload' { declare module 'payload' {
export interface GeneratedTypes extends Config {} export interface GeneratedTypes extends Config {}
} }

View File

@@ -120,12 +120,11 @@ export default buildConfig({
}), }),
// database-adapter-config-start // database-adapter-config-start
db: mongooseAdapter({ db: mongooseAdapter({
url: process.env.DATABASE_URI!, url: process.env.DATABASE_URI,
}), }),
// database-adapter-config-end // database-adapter-config-end
collections: [Pages, Posts, Media, Categories, Users], collections: [Pages, Posts, Media, Categories, Users],
cors: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean), cors: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
csrf: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean),
endpoints: [ endpoints: [
// The seed endpoint is used to populate the database with some example data // The seed endpoint is used to populate the database with some example data
// You should delete this endpoint before deploying your site to production // You should delete this endpoint before deploying your site to production
@@ -203,7 +202,7 @@ export default buildConfig({
}), }),
payloadCloudPlugin(), // storage-adapter-placeholder payloadCloudPlugin(), // storage-adapter-placeholder
], ],
secret: process.env.PAYLOAD_SECRET!, secret: process.env.PAYLOAD_SECRET,
sharp, sharp,
typescript: { typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'), outputFile: path.resolve(dirname, 'payload-types.ts'),