|
| 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). |
0 commit comments