Skip to content

Commit 201d686

Browse files
authored
feat(templates): website template now has configured image sizes, updated readme and simplified env vars for setting up (#9036)
1 parent ebd3c02 commit 201d686

File tree

6 files changed

+220
-28
lines changed

6 files changed

+220
-28
lines changed

templates/website/.env.example

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,5 @@ DATABASE_URI=mongodb://127.0.0.1/payload-template-website
44
# Used to encrypt JWT tokens
55
PAYLOAD_SECRET=YOUR_SECRET_HERE
66

7-
# Used to format links and URLs
8-
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
7+
# Used to configure CORS, format links and more. No trailing slash
98
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
10-
11-
# Allow robots to index the site (optional)
12-
NEXT_PUBLIC_IS_LIVE=
13-
14-
# Used to preview drafts
15-
PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
16-
NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret
17-
18-
# Used to revalidate static pages
19-
REVALIDATION_KEY=demo-revalation-key
20-
NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key

templates/website/README.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This template is right for you if you are working on:
66

77
- A personal or enterprise-grade website, blog, or portfolio
88
- A content publishing platform with a fully featured publication workflow
9-
- A lead generation website with premium content gated behind authentication
9+
- Exploring the capabilities of Payload
1010

1111
Core features:
1212

@@ -36,13 +36,17 @@ Go to Payload Cloud and [clone this template](https://payloadcms.com/new/clone/w
3636

3737
Use the `create-payload-app` CLI to clone this template directly to your machine:
3838

39-
npx create-payload-app@beta my-project -t website
39+
```bash
40+
pnpx create-payload-app@beta my-project -t website
41+
```
4042

4143
#### Method 3
4244

4345
Use the `git` CLI to clone this template directly to your machine:
4446

45-
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"
47+
```bash
48+
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"
49+
```
4650

4751
### Development
4852

@@ -77,7 +81,7 @@ See the [Collections](https://payloadcms.com/docs/beta/configuration/collections
7781

7882
- #### Media
7983

80-
This is the uploads enabled collection used by pages, posts, and projects to contain media like images, videos, downloads, and other assets.
84+
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.
8185

8286
- #### Categories
8387

@@ -137,6 +141,10 @@ In addition to draft previews you can also enable live preview to view your end
137141

138142
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.
139143

144+
## Search
145+
146+
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.
147+
140148
## Redirects
141149

142150
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:
153161
- [Payload Admin Bar](https://github.com/payloadcms/payload-admin-bar)
154162
- [TailwindCSS styling](https://tailwindcss.com/)
155163
- [shadcn/ui components](https://ui.shadcn.com/)
156-
- Authentication
164+
- User Accounts and Authentication
157165
- Fully featured blog
158166
- Publication workflow
159-
- User accounts
160167
- Dark mode
161168
- Pre-made layout building blocks
162169
- SEO
170+
- Search
163171
- Redirects
164172
- Live preview
165173

@@ -207,14 +215,57 @@ The easiest way to deploy your project is to use [Payload Cloud](https://payload
207215

208216
### Deploying to Vercel
209217

210-
Coming soon.
218+
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:
219+
220+
```bash
221+
pnpm add @payloadcms/db-vercel-postgres
222+
```
223+
224+
```ts
225+
// payload.config.ts
226+
import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'
227+
228+
export default buildConfig({
229+
// ...
230+
db: vercelPostgresAdapter({
231+
pool: {
232+
connectionString: process.env.POSTGRES_URL || '',
233+
},
234+
}),
235+
// ...
236+
```
237+
238+
We also support Vercel's blob storage:
239+
240+
```bash
241+
pnpm add @payloadcms/storage-vercel-blob
242+
```
243+
244+
```ts
245+
// payload.config.ts
246+
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
247+
248+
export default buildConfig({
249+
// ...
250+
plugins: [
251+
vercelBlobStorage({
252+
collections: {
253+
[Media.slug]: true,
254+
},
255+
token: process.env.BLOB_READ_WRITE_TOKEN || '',
256+
}),
257+
],
258+
// ...
259+
```
260+
261+
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.
211262
212263
### Self-hosting
213264
214265
Before deploying your app, you need to:
215266
216267
1. Ensure your app builds and serves in production. See [Production](#production) for more details.
217-
2. Serve it from a
268+
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.
218269
219270
You can also deploy your app manually, check out the [deployment documentation](https://payloadcms.com/docs/beta/production/deployment) for full details.
220271

templates/website/src/collections/Media.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,32 @@ export const Media: CollectionConfig = {
4141
upload: {
4242
// Upload to the public/media directory in Next.js making them publicly accessible even outside of Payload
4343
staticDir: path.resolve(dirname, '../../public/media'),
44+
imageSizes: [
45+
{
46+
name: 'square',
47+
width: 500,
48+
height: 500,
49+
},
50+
{
51+
name: 'thumbnail',
52+
width: 300,
53+
},
54+
{
55+
name: 'small',
56+
width: 600,
57+
},
58+
{
59+
name: 'medium',
60+
width: 900,
61+
},
62+
{
63+
name: 'large',
64+
width: 1400,
65+
},
66+
{
67+
name: 'xlarge',
68+
width: 1400,
69+
},
70+
],
4471
},
4572
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare global {
2+
namespace NodeJS {
3+
interface ProcessEnv {
4+
PAYLOAD_SECRET: string
5+
DATABASE_URI: string
6+
NEXT_PUBLIC_SERVER_URL: string
7+
}
8+
}
9+
}
10+
11+
// If this file has no import/export statements (i.e. is a script)
12+
// convert it into a module by adding an empty export statement.
13+
export {}

templates/website/src/payload-types.ts

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface Config {
2424
'payload-preferences': PayloadPreference;
2525
'payload-migrations': PayloadMigration;
2626
};
27-
collectionsSelect: {
27+
collectionsSelect?: {
2828
pages: PagesSelect<false> | PagesSelect<true>;
2929
posts: PostsSelect<false> | PostsSelect<true>;
3030
media: MediaSelect<false> | MediaSelect<true>;
@@ -45,7 +45,7 @@ export interface Config {
4545
header: Header;
4646
footer: Footer;
4747
};
48-
globalsSelect: {
48+
globalsSelect?: {
4949
header: HeaderSelect<false> | HeaderSelect<true>;
5050
footer: FooterSelect<false> | FooterSelect<true>;
5151
};
@@ -164,6 +164,56 @@ export interface Media {
164164
height?: number | null;
165165
focalX?: number | null;
166166
focalY?: number | null;
167+
sizes?: {
168+
square?: {
169+
url?: string | null;
170+
width?: number | null;
171+
height?: number | null;
172+
mimeType?: string | null;
173+
filesize?: number | null;
174+
filename?: string | null;
175+
};
176+
thumbnail?: {
177+
url?: string | null;
178+
width?: number | null;
179+
height?: number | null;
180+
mimeType?: string | null;
181+
filesize?: number | null;
182+
filename?: string | null;
183+
};
184+
small?: {
185+
url?: string | null;
186+
width?: number | null;
187+
height?: number | null;
188+
mimeType?: string | null;
189+
filesize?: number | null;
190+
filename?: string | null;
191+
};
192+
medium?: {
193+
url?: string | null;
194+
width?: number | null;
195+
height?: number | null;
196+
mimeType?: string | null;
197+
filesize?: number | null;
198+
filename?: string | null;
199+
};
200+
large?: {
201+
url?: string | null;
202+
width?: number | null;
203+
height?: number | null;
204+
mimeType?: string | null;
205+
filesize?: number | null;
206+
filename?: string | null;
207+
};
208+
xlarge?: {
209+
url?: string | null;
210+
width?: number | null;
211+
height?: number | null;
212+
mimeType?: string | null;
213+
filesize?: number | null;
214+
filename?: string | null;
215+
};
216+
};
167217
}
168218
/**
169219
* This interface was referenced by `Config`'s JSON-Schema
@@ -888,6 +938,70 @@ export interface MediaSelect<T extends boolean = true> {
888938
height?: T;
889939
focalX?: T;
890940
focalY?: T;
941+
sizes?:
942+
| T
943+
| {
944+
square?:
945+
| T
946+
| {
947+
url?: T;
948+
width?: T;
949+
height?: T;
950+
mimeType?: T;
951+
filesize?: T;
952+
filename?: T;
953+
};
954+
thumbnail?:
955+
| T
956+
| {
957+
url?: T;
958+
width?: T;
959+
height?: T;
960+
mimeType?: T;
961+
filesize?: T;
962+
filename?: T;
963+
};
964+
small?:
965+
| T
966+
| {
967+
url?: T;
968+
width?: T;
969+
height?: T;
970+
mimeType?: T;
971+
filesize?: T;
972+
filename?: T;
973+
};
974+
medium?:
975+
| T
976+
| {
977+
url?: T;
978+
width?: T;
979+
height?: T;
980+
mimeType?: T;
981+
filesize?: T;
982+
filename?: T;
983+
};
984+
large?:
985+
| T
986+
| {
987+
url?: T;
988+
width?: T;
989+
height?: T;
990+
mimeType?: T;
991+
filesize?: T;
992+
filename?: T;
993+
};
994+
xlarge?:
995+
| T
996+
| {
997+
url?: T;
998+
width?: T;
999+
height?: T;
1000+
mimeType?: T;
1001+
filesize?: T;
1002+
filename?: T;
1003+
};
1004+
};
8911005
}
8921006
/**
8931007
* This interface was referenced by `Config`'s JSON-Schema
@@ -1287,4 +1401,4 @@ export interface Auth {
12871401

12881402
declare module 'payload' {
12891403
export interface GeneratedTypes extends Config {}
1290-
}
1404+
}

templates/website/src/payload.config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ export default buildConfig({
120120
}),
121121
// database-adapter-config-start
122122
db: mongooseAdapter({
123-
url: process.env.DATABASE_URI!,
123+
url: process.env.DATABASE_URI,
124124
}),
125125
// database-adapter-config-end
126126
collections: [Pages, Posts, Media, Categories, Users],
127-
cors: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean),
128-
csrf: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean),
127+
cors: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
129128
endpoints: [
130129
// The seed endpoint is used to populate the database with some example data
131130
// You should delete this endpoint before deploying your site to production
@@ -203,7 +202,7 @@ export default buildConfig({
203202
}),
204203
payloadCloudPlugin(), // storage-adapter-placeholder
205204
],
206-
secret: process.env.PAYLOAD_SECRET!,
205+
secret: process.env.PAYLOAD_SECRET,
207206
sharp,
208207
typescript: {
209208
outputFile: path.resolve(dirname, 'payload-types.ts'),

0 commit comments

Comments
 (0)