Skip to content

Commit 49f117e

Browse files
authored
chore: adds website template (#2928)
1 parent 8df4b15 commit 49f117e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+11444
-0
lines changed

templates/website/.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
end_of_line = lf
10+
max_line_length = null

templates/website/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PORT=8000
2+
MONGODB_URI=mongodb://localhost/payload-template-website
3+
PAYLOAD_SECRET=3c543dbf662b4d12d8e30854
4+
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:8000
5+
PAYLOAD_PUBLIC_SITE_URL=http://localhost:3000

templates/website/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@payloadcms'],
4+
ignorePatterns: ['**/payload-types.ts'],
5+
}

templates/website/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
dist
3+
/media
4+
node_modules
5+
.DS_Store
6+
.env

templates/website/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/payload-types.ts

templates/website/.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
printWidth: 100,
3+
parser: "typescript",
4+
semi: false,
5+
singleQuote: true,
6+
trailingComma: "all",
7+
arrowParens: "avoid",
8+
};

templates/website/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM node:18.8-alpine as base
2+
3+
FROM base as builder
4+
5+
WORKDIR /home/node/app
6+
COPY package*.json ./
7+
8+
COPY . .
9+
RUN yarn install
10+
RUN yarn build
11+
12+
FROM base as runtime
13+
14+
ENV NODE_ENV=production
15+
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
16+
17+
WORKDIR /home/node/app
18+
COPY package*.json ./
19+
20+
RUN yarn install --production
21+
COPY --from=builder /home/node/app/dist ./dist
22+
COPY --from=builder /home/node/app/build ./build
23+
24+
EXPOSE 3000
25+
26+
CMD ["node", "dist/server.js"]

templates/website/README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Payload Website Template
2+
3+
A template for [Payload](https://github.com/payloadcms/payload) to power websites from small to enterprise. This repo may have been created by running `npx create-payload-app` and selecting the "website" template or by cloning this template on [Payload Cloud](https://payloadcms.com/new/clone/blank).
4+
5+
Core features:
6+
7+
- [Pre-configured Payload Config](#how-it-works)
8+
- [Access Control](#access-control)
9+
- [Preview](#preview)
10+
- [ISR](#isr)
11+
- [Nested Docs](#nested-docs)
12+
- [Layout Builder](#layout-builder)
13+
- [SEO](#seo)
14+
- [Redirects](#redirects)
15+
16+
For details on how to get this template up and running locally, see the [development](#development) section.
17+
18+
## How it works
19+
20+
The Payload config is tailored specifically to the needs of most websites. It is pre-configured in the following ways:
21+
22+
### Collections
23+
24+
See the [collections documentation](https://payloadcms.com/docs/configuration/collections) for details on how to extend this functionality.
25+
26+
- #### Users
27+
28+
Users are auth-enabled and encompass both admins and public users based on the value of their `roles` field. Only `admin` users can access your admin panel to manage your website's content whereas `user` has limited access to the platform, see [Access Control](#access-control) for more details.
29+
30+
For additional help, see the official [Auth Example](https://github.com/payloadcms/payload/tree/master/examples/auth/cms#readme) or the [authentication docs](https://payloadcms.com/docs/authentication/overview#authentication-overview).
31+
32+
- #### Pages
33+
34+
All pages are layout-builder enabled so you can generate unique layouts for each page using layout-building blocks, see [Layout Builder](#layout-builder) for more details. They can also be nested inside of one another, for example "About > Team". See [Nested Docs](#nested-docs) for more details.
35+
36+
- #### Posts
37+
38+
All posts are layout-builder enabled so you can generate unique layouts for each post using layout-building blocks, see [Layout Builder](#layout-builder) for more details. They can also be nested inside of one another, for example "News > World". See [Nested Docs](#nested-docs) for more details.
39+
40+
- #### Media
41+
42+
This is the uploads-enabled collection used by pages and products to contain media, etc.
43+
44+
- #### Categories
45+
46+
A taxonomy used to group posts together. Categories can be nested inside of one another, for example "News > World". See the official [Payload Nested Docs Plugin](https://github.com/payloadcms/plugin-nested-docs) for more details.
47+
48+
### Globals
49+
50+
See the [globals documentation](https://payloadcms.com/docs/configuration/globals) for details on how to extend this functionality.
51+
52+
- `Header`
53+
54+
The data required by the header on your front-end, i.e. nav links, etc.
55+
56+
- `Footer`
57+
58+
Same as above but for the footer of your site.
59+
60+
## Access Control
61+
62+
Basic role-based access control is setup to determine what users can and cannot do based on their roles, which are:
63+
64+
- `admin`: They can access the Payload admin panel to manage your website. They can see all data and make all operations.
65+
- `user`: They cannot access the Payload admin panel and have a limited access to operations based on their user (see below).
66+
67+
This applies to each collection in the following ways:
68+
69+
- `users`: Only admins and the user themselves can access their profile. Only admins can create and delete users.
70+
- `pages`: Everyone can see published pages but only admins can see drafts and create, update, and delete pages.
71+
- `posts`: Same as pages.
72+
73+
For more details on how to extend this functionality, see the [Payload Access Control](https://payloadcms.com/docs/access-control/overview#access-control) docs.
74+
75+
## Preview
76+
77+
To enter preview mode we format a custom URL using a [preview function](https://payloadcms.com/docs/configuration/collections#preview) in the collection config. When a user clicks the "Preview" button, they are routed to this URL along with their http-only cookies and revalidation key. Your front-end can then use the `payload-token` and revalidation key to verify the request and enter into its own preview mode.
78+
79+
For more information, see the official [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms#readme).
80+
81+
## ISR
82+
83+
If your front-end is statically generated then you may also want to regenerate the HTML for each page as they are published, sometimes referred to as Incremental Static Regeneration. To do this, we add an `afterChange` hook to the collection that fires a request to your front-end in the background each time the document is updated. You can handle this request on your front-end and regenerate the HTML for your page however needed.
84+
85+
For more information, see the official [Preview Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms#isr) which includes ISR.
86+
87+
## Nested Docs
88+
89+
This template comes pre-configured with the official [Payload Nested Docs Plugin](https://github.com/payloadcms/plugin-nested-docs) so you can easily create hierarchies of pages, posts, and categories.
90+
91+
## Layout Builder
92+
93+
Pages and posts can be built using a powerful layout builder. This allows you to create unique layouts for each page or post. This template comes pre-configured with the following layout building blocks:
94+
95+
- Hero
96+
- Content
97+
- Media
98+
- Call To Action
99+
- Archive
100+
101+
## SEO
102+
103+
This template comes pre-configured with the official [Payload SEO Plugin](https://github.com/payloadcms/plugin-seo) so you can easily manage metadata for each page of your website.
104+
105+
## Redirects
106+
107+
This template comes pre-configured with the official [Payload Redirects Plugin](https://github.com/payloadcms/plugin-redirects) so you can properly redirect content as your website scales.
108+
109+
For additional help, see the official [Redirects Example](https://github.com/payloadcms/payload/tree/master/examples/preview/cms#readme).
110+
111+
## Development
112+
113+
To spin up the template locally, follow these steps:
114+
115+
1. First clone the repo
116+
1. Then `cd YOUR_PROJECT_REPO && cp .env.example .env`
117+
1. Next `yarn && yarn dev` (or `docker-compose up`, see [Docker](#docker))
118+
1. Now `open http://localhost:8000/admin` to access the admin panel
119+
1. Create your first admin user using the form on the page
120+
121+
That's it! Changes made in `./src` will be reflected in your app—but your database is blank. You can optionally seed the database with a few pages and posts, more details on that [here](#seed).
122+
123+
### Docker
124+
125+
Alternatively, you can use [Docker](https://www.docker.com) to spin up this template locally. To do so, follow these steps:
126+
127+
1. Follow [steps 1 and 2 from above](#development), the docker-compose file will automatically use the `.env` file in your project root
128+
1. Next run `docker-compose up`
129+
1. Follow [steps 4 and 5 from above](#development) to login and create your first admin user
130+
131+
That's it! The Docker instance will help you get up and running quickly while also standardizing the development environment across your teams.
132+
133+
### Seed
134+
135+
To seed the database with a few pages and posts you can run `yarn seed`.
136+
137+
> NOTICE: seeding the database is destructive because it drops your current database to populate a fresh one from the seed template. Only run this command if you are starting a new project or can afford to lose your current data.
138+
139+
## Production
140+
141+
To run Payload in production, you need to build and serve the Admin panel. To do so, follow these steps:
142+
143+
1. First invoke the `payload build` script by running `yarn build` or `npm run build` in your project root. This creates a `./build` directory with a production-ready admin bundle.
144+
1. Then run `yarn serve` or `npm run serve` to run Node in production and serve Payload from the `./build` directory.
145+
146+
### Deployment
147+
148+
The easiest way to deploy your project is to use [Payload Cloud](https://payloadcms.com/new/import), a one-click hosting solution to deploy production-ready instances of your Payload apps directly from your GitHub repo. You can also deploy your app manually, check out the [deployment documentation](https://payloadcms.com/docs/production/deployment) for full details.
149+
150+
## Questions
151+
152+
If you have any issues or questions, reach out to us on [Discord](https://discord.com/invite/payload) or start a [GitHub discussion](https://github.com/payloadcms/payload/discussions).
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
5+
payload:
6+
image: node:18-alpine
7+
ports:
8+
- "3000:3000"
9+
volumes:
10+
- .:/home/node/app
11+
- node_modules:/home/node/app/node_modules
12+
working_dir: /home/node/app/
13+
command: sh -c "yarn install && yarn dev"
14+
depends_on:
15+
- mongo
16+
env_file:
17+
- .env
18+
19+
mongo:
20+
image: mongo:latest
21+
ports:
22+
- "27017:27017"
23+
command:
24+
- --storageEngine=wiredTiger
25+
volumes:
26+
- data:/data/db
27+
logging:
28+
driver: none
29+
30+
volumes:
31+
data:
32+
node_modules:

templates/website/nodemon.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ext": "ts",
3+
"exec": "ts-node src/server.ts"
4+
}

0 commit comments

Comments
 (0)