Payload Website

repository·main·Indexed 20 days ago

https://github.com/payloadcms/website

The official website for Payload CMS, built using Payload and Next.js 15. This repository serves as a showcase for Payload's local API, Stripe integration, and dynamic documentation rendering, including features for syncing Markdown files from GitHub to the CMS and managing beta/legacy documentation versions.

Tokens
90.1K
Snippets
286
Records
327
Agent score
70%

What's inside payload-website

  1. Preview documentation from a specific GitHub branch

    main

    By default, the site pulls documentation from the main branch of the Payload repository. To preview documentation from a different branch without performing a full CMS sync, use the /docs/dynamic/ route with a branch query parameter.

    Example usage:

    • Main branch: https://payloadcms.com/docs/getting-started/concepts
    • Specific branch: https://payloadcms.com/docs/dynamic/getting-started/concepts?branch=feat/myfeature

    In the CMS, you can use the branch selector to choose which branch to work on. When you save changes to a document, the Lexical docs are converted back to MDX and pushed to the selected branch on GitHub.

  2. Run the Payload Website project locally

    main

    To set up the development environment for the Payload Website repository, follow these steps:

    1. Clone the repository.
    2. Install dependencies using pnpm i.
    3. Create an environment file by running cp .env.example .env.
    4. Populate the .env file with the appropriate values for your environment.
    5. Start the development server with pnpm dev.

    Important: Hosts File Configuration Because of http-only cookie policies and GitHub App redirect requirements, the application must run on local.payloadcms.com:3000. You must add the following entry to your system's hosts file:

    • Mac: /etc/hosts
    • Windows: C:\Windows\System32\drivers\etc\hosts
    127.0.0.1 local.payloadcms.com
    pnpm i
    cp .env.example .env
    pnpm dev
  3. Preview local Markdown files in the website

    main

    You can preview local Markdown files in the website without modifying the database by using the /docs/local/ route.

    1. Set the DOCS_DIR_V3 environment variable to the absolute path of your local docs directory.
    2. Access the documentation via the /docs/local/ path prefix.

    Example: If DOCS_DIR_V3=/documents/github/payload/docs, you can view a concept page at http://localhost:3000/docs/local/getting-started/concepts.

    Changes to local MDX files are reflected on page reload via on-the-fly conversion to Lexical.

    DOCS_DIR_V3=/documents/github/payload/docs
  4. Sync documentation from GitHub to the CMS

    main

    The website documentation is stored as Markdown files in the Payload repository on GitHub. You can synchronize these docs into the CMS using the "Sync Docs" button within the CMS interface.

    When triggered, the sync process:

    1. Pulls docs from the Payload GitHub repository.
    2. Converts MDX to Lexical format.
    3. Stores the converted docs in the CMS.
    4. Revalidates the frontend documentation pages.

    To enable GitHub synchronization, configure the following environment variables in your .env file:

    # For reading from GitHub
    GITHUB_ACCESS_TOKEN=ghp_
    GITHUB_CLIENT_SECRET=
    
    # For writing to GitHub
    COMMIT_DOCS_API_URL=
    COMMIT_DOCS_API_KEY=
  5. How LiveLogs streaming works

    main

    The internal LiveLogs component manages the WebSocket connection to fetch logs for a specific deployment type (BUILD or DEPLOY).

    WebSocket URL Construction

    The component connects to a WebSocket endpoint derived from the NEXT_PUBLIC_CLOUD_CMS_URL environment variable. The URL is constructed as follows:

    ws://{CLOUD_CMS_URL_WITHOUT_HTTP}/api/deployments/{deploymentID}/logs?logType={type}&env={environmentSlug}

    Log Message Handling

    When a message is received via WebSocket, the component expects a JSON payload with the following structure:

    {
      "data": [ ... ],
      "logType": "historic" | "live"
    }
    • logType: 'historic': The received logs replace the current log state.
    • logType: 'live': The received logs are appended to the existing log list.

    Logs are processed through the styleLogs utility before being rendered by the SimpleLogs component.

  6. Form Submission Behavior and API

    main

    When a user submits a CMSForm, the component performs the following actions:

    1. reCAPTCHA Validation: It checks for a valid reCAPTCHA token using the site key provided in process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY. If no token is found, it displays a toast error.
    2. Data Transformation: The form data is transformed into an array of objects where each object contains a field name and its corresponding value.
    3. API Request: A POST request is sent to /api/form-submissions with the following JSON body:
      • form: The ID of the form.
      • hubspotCookie: The value of the hubspotutk cookie (if present).
      • pageName: The name of the current page (derived from the URL path).
      • pageUri: The full URL of the current page (using process.env.NEXT_PUBLIC_SITE_URL).
      • recaptcha: The reCAPTCHA token.
      • submissionData: The array of field/value pairs.
    4. Post-Submission Actions:
      • Message Confirmation: If confirmationType is set to 'message', the component displays the confirmationMessage using a RichText component.
      • Redirect: If confirmationType is set to 'redirect', the component redirects the user to the URL specified in form.redirect.url. It handles both relative paths (using router.push) and absolute URLs (using window.location.assign).
  7. Deployment status phases and troubleshooting

    main

    When a project is undergoing infrastructure changes, it moves through several infraStatus phases. If a deployment fails, the InfraOffline component provides specific troubleshooting steps based on the error type.

    Deployment Phases (infraStatus):

    • notStarted: Setting up your project.
    • awaitingDatabase: Deploying project database.
    • deploying: Deploying your project.
    • reinstating: Reinstating your project.
    • done: Deployment complete.
    • suspended: Project is suspended.

    Common Troubleshooting Scenarios:

    • Branch Issues: Ensure the deploymentBranch exists in your repository.
    • Local Build: Verify the project can build successfully on a local machine.
    • Run Script: Ensure the Project's Run Script matches the package.json script.
    • Environment Variables: Ensure MONGODB_URI or DATABASE_URI and PAYLOAD_SECRET are correctly configured.
    • Port Configuration: By default, Payload Cloud listens on port 3000. If using a different port, set the PORT environment variable in Settings.
  8. Configure Beta and Legacy documentation versions

    main

    The website supports rendering different versions of documentation using specific environment variables:

    Beta Docs

    • Enable beta docs: Set NEXT_PUBLIC_ENABLE_BETA_DOCS=true.
    • Specify version: Set NEXT_PUBLIC_BETA_DOCS_REF to a branch, commit, or tag (defaults to beta).

    Legacy Docs

    • Enable legacy docs: Set NEXT_PUBLIC_ENABLE_LEGACY_DOCS=true.
    • Specify version: Set NEXT_PUBLIC_LEGACY_DOCS_REF to a branch, commit, or tag (defaults to null, which falls back to the main branch).
  9. How CMSLink resolves references

    main

    When type="reference" is used, CMSLink resolves the href based on the relationTo field in the reference object:

    • pages: Attempts to use the last item in the breadcrumbs array to find the url. If breadcrumbs are unavailable, it falls back to /${relationTo}/${value.slug}.
    • posts: Resolves to /blog/${value.slug}.
    • case_studies: Resolves to /case-studies/${value.slug}.
    • Other collections: Falls back to the pattern /${relationTo}/${value.slug}.

    Note: The value in the reference can be either a full object (containing slug, breadcrumbs, etc.) or a simple string ID.

  10. Deployment status stages and indicators

    main

    The deployment system uses specific status strings to determine the UI state. The InfraOnline component categorizes these into 'final' stages to decide if a deployment is considered successful or failed.

    Final Deployment Stages

    Statuses that represent a completed state:

    • ACTIVE (considered 'Online/Success')
    • SUPERSEDED (considered 'Online/Success')

    Other Statuses

    • Success/Progressing: BUILDING, DEPLOYING (shown with a spinner)
    • Pending: PENDING_BUILD, PENDING_DEPLOY (shown with a spinner)
    • Error/Failure: ERROR, CANCELED (shown as 'Offline/Error')
  11. Use the Button component

    main

    The Button component is a versatile UI element that can render as an <a>, <button>, <div>, or a Next.js Link (via the el='link' prop). It supports various visual appearances, sizes, and icons, and can automatically resolve URLs from CMS references.

    Key Features

    • Dynamic Element Rendering: Use el to switch between 'a', 'button', 'div', or 'link'.
    • CMS Integration: If type='reference' is provided along with a reference object, the component automatically generates the correct href based on the relation type (e.g., pages, posts, case_studies).
    • Visual Variants: Control the look using appearance (e.g., primary, secondary, danger) and size (e.g., default, large, pill).
    • Icons: Supports built-in icons: arrow, copy, github, loading, plus, and search.
    import { Button } from './components/Button';
    
    // Basic button
    <Button label="Click Me" appearance="primary" />
    
    // Link button using Next.js Link
    <Button 
      el="link" 
      href="/about" 
      label="About Us" 
      icon="arrow" 
    />
    
    // Button with CMS reference
    <Button 
      el="link" 
      type="reference" 
      reference={cmsReferenceObject} 
      label="Read Post" 
    />
  12. Configure the HoverHighlights block

    main

    The HoverHighlights block is a Payload CMS block used to create content sections featuring text highlights and associated media. It is structured using blockFields and includes fields for text areas, an array of highlights, and links.

    Field Structure

    • hoverHighlightsFields (Group):
      • beforeHighlights (Textarea): Text content to display before the highlights.
      • highlights (Array): A list of highlight items, each containing:
        • text (Text, required): The highlight text.
        • media (Group): A group containing top and bottom upload fields (relation to media) for image assets.
        • link (Link): A link object (configured with appearances: false and disableLabel: true).
      • afterHighlights (Textarea): Text content to display after the highlights.
      • link (Link): A link object (configured with appearances: false).
    import { HoverHighlights } from './blocks/HoverHighlights'
    
    // Usage in a collection or page config
    export const Pages = {
      slug: 'pages',
      fields: [
        {
          name: 'layout',
          type: 'blocks',
          blocks: [
            HoverHighlights,
            // ... other blocks
          ],
        },
      ],
    }