惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
博客园_首页
量子位
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
V
Visual Studio Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
D
Docker
大猫的无限游戏
大猫的无限游戏
Y
Y Combinator Blog
H
Help Net Security
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale

Blog — PlanetScale

Keeping a Postgres queue healthy — PlanetScale Patterns for Postgres Traffic Control — PlanetScale Graceful degradation in Postgres — PlanetScale High memory usage in Postgres is good, actually — PlanetScale Stripe Projects partnership: Provision PlanetScale Postgres and MySQL databases from the Stripe CLI — PlanetScale Enhanced tagging in Postgres Query Insights — PlanetScale Behind the scenes: How Database Traffic Control works — PlanetScale Introducing Database Traffic Control — PlanetScale Scaling Postgres connections with PgBouncer — PlanetScale Drizzle joins PlanetScale — PlanetScale Video Conferencing with Postgres — PlanetScale Faster PlanetScale Postgres connections with Cloudflare Hyperdrive — PlanetScale Introducing the PlanetScale MCP server — PlanetScale Database Transactions — PlanetScale Automating our changelog with Cursor commands — PlanetScale Postgres 18 is now available — PlanetScale Using MotherDuck with PlanetScale — PlanetScale $50 PlanetScale Metal is GA for Postgres — PlanetScale AI-Powered Postgres index suggestions — PlanetScale $5 PlanetScale is live — PlanetScale Announcing Vitess 23 — PlanetScale $50 PlanetScale Metal — PlanetScale Report on our investigation of the 2025-10-20 incident in AWS us-east-1 — PlanetScale $5 PlanetScale — PlanetScale Benchmarking Postgres 17 vs 18 — PlanetScale Larger than RAM Vector Indexes for Relational Databases — PlanetScale Partnering with Cloudflare to bring you the fastest globally distributed applications — PlanetScale Processes and Threads — PlanetScale PlanetScale for Postgres is now GA — PlanetScale Postgres High Availability with CDC — PlanetScale
Personalizing your onboarding with Markdoc — PlanetScale
Ayrton · 2023-10-06 · via Blog — PlanetScale

Ayrton |

We recently released a new and improved onboarding flow for PlanetScale. The goal of our new onboarding is to help developers quickly connect and query their PlanetScale databases.

How to connect varies greatly by the language and framework your application uses. Each framework has small quirks, so it was important to us that no matter what language/framework your application uses, we offer a one-track path for you to get connected.

Onboarding page - create a new database Onboarding page - select a framework

The key to building out this onboarding was Markdoc. This post will go into more detail about how we built our product onboarding using Markdoc.

More flexibility with Markdoc

Markdoc, created by Stripe, is a Markdown-based syntax for creating custom documentation sites.

One of the reasons we're able to ship so quickly at PlanetScale is because we prioritize easy-to-use tools that allow anyone at the company to contribute. For this reason, using Markdown and GitHub for our product onboarding was an obvious choice for us.

As we started building, we quickly realized we wanted to have more interactive and personalized content. Static Markdown content just wasn't going to cut it. This is when we had the idea to explore using Markdoc.

The Markdoc syntax is a superset of Markdown, specifically the CommonMark specification. This means you can write content in the Markdown you know and love, but also allows you to extend it to add custom attributes, custom tags, and use functions and/or variables.

Building out the onboarding

Let's dive into some of the code. The following snippet is part of the Markdown used to render a connection tutorial in the onboarding flow.

```bash
rails credentials:edit --environment production
```

Add the following:

```bash {% file="config/credentials.yml.enc" %}
planetscale:
  username: {% $user %}
  host: {% $host %}
  database: {% $database %}
  password: {% $password %}
```

Onboarding page showing Rails-specific tutorial

You'll notice that we are using variables here inside the Markdown, i.e., $user, $host, $database, and $password. The goal was for each path in onboarding to be custom to the user and as easy as possible for them to follow. Providing easily copy and pastable code specific to the selected framework was key. And this is where variables became important.

Variables in Markdoc

Variables let you customize your Markdoc documents at runtime. We use variables to inline the users credentials directly into the content rather than using a static placeholder value.

This is a lot like blade templates in Laravel and erb templates in Ruby on Rails. The following snippet shows how we set up variables to populate those Markdown fields.

Note

All credentials have been invalidated prior to publishing this. We are leaving the full, unblurred credentials in for clarity.

import React from 'react'
import { parse, renderers, transform } from '@markdoc/markdoc'

export default function Page() {
  const config = {
    variables: {
      host: 'us-east.connect.psdb.cloud',
      user: 'mpl0y3jv3a92h4qc4ufn',
      database: 'beam',
      password: 'pscale_pw_V8db13jnq5mrOWcGFn6GTs6AerDI7A0womsmnJ1qxOc',
      ssl_ca: '/etc/ssl/certs/ca-certificates.crt'
    }
  }

  const doc = `# Configure your application\n…`
  const ast = parse(doc)
  const content = transform(ast, config)
  const children = renderers.react(content, React, {})

  return <div>{children}</div>
}

Nodes in Markdoc

To help contextualize the file that the onboarding code snippets live in, we want to extend the code blocks to accept an additional file attribute. Markdoc nodes enable you to customize how your document renders without using any custom syntax.

The following example extends the code snippet from the previous section by adding a new fence node, which displays the filename above a code snippet.

import React from 'react'
import { parse, renderers, transform } from '@markdoc/markdoc'

export default function Page() {
  const config = {
    nodes: {
      fence: Fence.scheme
    },
    variables: {
      host: 'us-east.connect.psdb.cloud',
      user: 'mpl0y3jv3a92h4qc4ufn',
      database: 'beam',
      password: 'pscale_pw_V8db13jnq5mrOWcGFn6GTs6AerDI7A0womsmnJ1qxOc',
      ssl_ca: '/etc/ssl/certs/ca-certificates.crt'
    }
  }

  const doc = `# Configure your application\n…`
  const ast = parse(doc)
  const content = transform(ast, config)
  const children = renderers.react(content, React, { components: { Fence } })

  return <div>{children}</div>
}

function Fence({ children, file, language }) {
  return (
    <div>
      <div>{file}</div>

      <pre>
        <code className={`language-${language}`}>children</code>
      </pre>
    </div>
  )
}

Fence.scheme = {
  render: Fence.name,
  children: ['pre', 'code'],
  attributes: {
    file: {
      type: String
    },
    language: {
      type: String
    }
  }
}

Further customizations

One challenge we have seen users face is deciding which SSL certificate to use when connecting securely to PlanetScale. To address this, we built a common component that will swap out the certificate based on the users detected operating system.

This also extends the snippet from the previous section, adding in functions to detect the user's operating system and return the correct string for the ssl_ca variable.

import React from 'react'
import { parse, renderers, transform } from '@markdoc/markdoc'

export default function Page({ userAgent }) {
  const platform = connectPlatform(userAgent)
  const sslCertificate = connectSslCertificate(platform)

  const config = {
    nodes: {
      fence: Fence.scheme
    },
    variables: {
      host: 'us-east.connect.psdb.cloud',
      user: 'mpl0y3jv3a92h4qc4ufn',
      database: 'beam',
      password: 'pscale_pw_V8db13jnq5mrOWcGFn6GTs6AerDI7A0womsmnJ1qxOc',
      ssl_ca: sslCertificate
    }
  }

  const doc = `# Configure your application\n…`
  const ast = parse(doc)
  const content = transform(ast, config)
  const children = renderers.react(content, React, { components: { Fence } })

  return <div>{children}</div>
}

function connectPlatform(userAgent) {
  userAgent = userAgent.toLowerCase()

  switch (true) {
    case /linux/.test(userAgent):
      return 'linux'
    case /mac/.test(userAgent):
      return 'mac'
    case /windows/.test(userAgent):
      return 'windows'
    default:
      return 'ubuntu'
  }
}

function connectSslCertificate(platform) {
  switch (platform) {
    case 'linux':
      return '/etc/ssl/certs/ca-certificates.crt'
    case 'mac':
      return '/etc/ssl/cert.pem'
    default:
      return '/etc/ssl/certs/ca-certificates.crt'
  }
}

function Fence({ children, file, language }) {
  return (
    <pre>
      <div>{file}</div>

      <code className={`language-${language}`}>children</code>
    </pre>
  )
}

Fence.scheme = {
  // …
}

Because a user's development environment is often different from their production environment, we also had to add a selector that allows users to select the certificate on their own. The final code for that is shown below.

import React, { createContext, useState } from 'react'
import { parse, renderers, transform } from '@markdoc/markdoc'

const Platform = createContext({ platform: null, setPlatform: () => {} })

export default function Page({ userAgent }) {
  const initialPlatform = connectPlatform(userAgent)
  const [platform, setPlatform] = useState(initialPlatform)

  const sslCertificate = connectSslCertificate(platform)

  const config = {
    nodes: {
      fence: Fence.scheme
    },
    variables: {
      host: 'us-east.connect.psdb.cloud',
      user: 'mpl0y3jv3a92h4qc4ufn',
      password: 'pscale_pw_V8db13jnq5mrOWcGFn6GTs6AerDI7A0womsmnJ1qxOc',
      ssl_ca: sslCertificate
    }
  }

  const doc = `# Configure your application\n…`
  const ast = parse(doc)
  const content = transform(ast, config)
  const children = renderers.react(content, React, { components: { Fence } })

  return (
    <Platform.Provider value={{ platform, setPlatform }}>
      <div>{children}</div>
    </Platform.Provider>
  )
}

function connectPlatform(userAgent) {
  // …
}
function connectSslCertificate(platform) {
  // …
}

function Fence({ children, file, language }) {
  const { platform } = useContext(Platform)

  const isDotEnvFile = file === '.env'
  const isWindowsPlatform = platform === 'windows'

  return (
    <div>
      <div>
        <div>{file}</div>

        {isDotEnvFile && (
          <select
            onChange={(event) => {
              setPlatform(event.target.value)
            }}
            value={platform}
          >
            <option value='linux'>Linux</option>
            <option value='mac'>macOS</option>
            <option value='windows'>Windows</option>
          </select>
        )}
      </div>

      <pre>
        <code className={`language-${language}`}>children</code>
      </pre>

      {isDotEnvFile && (
        <div>
          {isWindowsPlatform && (
            <>
              For Windows you may need to download a root certificate to connect securely.{' '}
              <a href='/docs/vitess/connecting/secure-connections#windows'>Learn more</a>
            </>
          )}
          {!isWindowsPlatform && (
            <>
              View the{' '}
              <a href='/docs/vitess/connecting/secure-connections#ca-root-configuration'>
                certificate authority root
              </a>{' '}
              paths for the SSL CA details.
            </>
          )}
        </div>
      )}
    </div>
  )
}

Fence.scheme = {
  // …
}

Outcomes using Markdoc

We are extremely happy with how the onboarding turned out, and based on some early data, it seems to be a huge win for new users as well. Working with Markdoc made the building process incredibly simple and straightforward. We're already finding that maintenance, like adding new frameworks, is very manageable as well.

We'd love to hear if you've been able to get your hands on Markdoc yet. If you'd like to experience our onboarding process first-hand, make sure you sign up for a PlanetScale account to give it a go.