Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vale/styles/FernStyles/Acronyms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ exceptions:
- SSG
- REST
- MDN
- UUID
8 changes: 6 additions & 2 deletions fern/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ redirects:
- source: /learn/docs/getting-started/global-configuration
destination: /learn/docs/configuration/site-level-settings
- source: /learn/docs/getting-started/development
destination: /learn/docs/preview-publish/previewing-changes-locally
destination: /learn/docs/preview-publish/preview-changes
- source: /learn/docs/getting-started/publish-your-docs
destination: /learn/docs/preview-publish/publishing-your-docs

Expand Down Expand Up @@ -334,7 +334,11 @@ redirects:
- source: /learn/docs/navigation/hiding-content
destination: /learn/docs/customization/hiding-content
- source: /learn/docs/building-and-customizing-your-docs/pull-request-preview
destination: /learn/docs/preview-publish/previewing-changes-in-a-pr
destination: /learn/docs/preview-publish/preview-changes
- source: /learn/docs/preview-publish/previewing-changes-in-a-pr
destination: /learn/docs/preview-publish/preview-changes
- source: /learn/docs/preview-publish/previewing-changes-locally
destination: /learn/docs/preview-publish/preview-changes
- source: /learn/docs/building-and-customizing-your-docs/product-switching
destination: /learn/docs/configuration/products
- source: /learn/docs/navigation/products
Expand Down
4 changes: 1 addition & 3 deletions fern/products/docs/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ navigation:
- section: Preview & publish
collapsed: true
contents:
- page: Previewing changes locally
- page: Preview changes
path: ./pages/getting-started/preview-changes-locally.mdx
- page: Previewing changes in a PR
path: ./pages/getting-started/pr-preview.mdx
- page: Publishing your docs
path: ./pages/getting-started/publishing-your-docs.mdx
- page: Setting up your domain
Expand Down
2 changes: 1 addition & 1 deletion fern/products/docs/pages/authentication/sso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Fern’s Single Sign-On (SSO) is an enterprise feature that lets your team secur
When SSO is enabled for your organization, authenticated users of Fern can:

- **Use the Fern Editor**: Make edits to your docs from the browser
- **Send Authenticated Preview Links** Only authenticated users can view [preview links](/learn/docs/preview-publish/previewing-changes-locally)
- **Send Authenticated Preview Links** Only authenticated users can view [preview links](/learn/docs/preview-publish/preview-changes#preview-links)

## How it works

Expand Down
118 changes: 0 additions & 118 deletions fern/products/docs/pages/getting-started/pr-preview.mdx

This file was deleted.

153 changes: 122 additions & 31 deletions fern/products/docs/pages/getting-started/preview-changes-locally.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
---
title: "Preview changes locally"
subtitle: "View and share updates to your documentation"
description: "View and share updates to your documentation"
title: Preview changes
description: Preview changes to your docs locally or with shareable preview links.
---

Fern offers two ways to preview changes to your documentation: a [local development environment](#local-development) and [unique preview links](#generate-a-preview-link).
Fern offers two ways to preview documentation changes:

- **[Local development](#local-development)** - Fast iteration with hot reload, best for active development
- **[Preview links](#preview-links)** - Shareable URLs for reviews and collaboration

## Local development

Fern enables you to view changes to your documentation in a locally hosted environment.
Run a local preview server to view documentation changes instantly with hot reload. Offline access is available after the first online run.

<Note>
Some features are disabled in local development:
- Search
- SEO (favicon, auto-generated meta tags, etc.)
- Authentication
</Note>

<Info>**Prerequisite**: Please install Node.js (version 18+) before proceeding.</Info>
<Steps>
<Step title="Install Node.js">

Follow these steps to install and run the Fern CLI:
Install Node.js version 18 or higher from [nodejs.org](https://nodejs.org).

**Step 1**: Install the Fern CLI:
</Step>
<Step title="Install the Fern CLI">

<CodeGroup>

Expand All @@ -27,50 +38,130 @@ yarn global add fern-api
```

</CodeGroup>
</Step>
<Step title="Preview docs">

**Step 2**: Navigate to the docs directory (where the `fern` folder is located) and execute the following command:
Navigate to the docs directory (where the `fern` folder is located) and [run the following command](/learn/cli-api-reference/cli-reference/commands#fern-docs-dev):

```bash
fern docs dev
```

A local preview of your documentation will be available at `http://localhost:3000`. The functionality is available offline if you have run local development mode online at least once.

<Note>
Some features are disabled in the local development environment, including:
- Search
- SEO (favicon, auto-generated meta tags, etc.)
- Authentication
</Note>

### Custom ports

By default, Fern uses port 3000. You can customize the port on which Fern runs by using the `--port` flag. For example, to run Fern on port 3002, use this command:
Your documentation will be available at `http://localhost:3000`.
<Anchor id="custom-ports">
<Note title="Custom ports">
By default, Fern uses port 3000. Customize the port on which Fern runs by [using the `--port` flag](/learn/cli-api-reference/cli-reference/commands#port):

```bash
fern docs dev --port 3002
```

If you attempt to run Fern on a port that's already in use, it will use the next available port:
If you attempt to run Fern on a port that's already in use, it will use the next available port.
</Note>
</Anchor>
</Step>
</Steps>

## Generate a preview link

Fern allows you to generate a shareable preview link that displays the current state of your docs. Each preview link is appended with a UUID and is not indexed. Currently, these links do not expire (this behavior is subject to change in the future).
## Preview links

**Usage**:
Generate shareable preview URLs to review and collaborate on documentation changes before publishing. Each preview link includes a unique UUID and isn't indexed by search engines. Links don't expire

```bash
fern generate --docs --preview
```

**Example**:

```bash
fern generate --docs --preview

```bash Example output
[docs]: Found 0 errors and 1 warnings. Run fern check --warnings to print out the warnings.
[docs]: Published docs to https://fern-preview-c973a36e-337b-44f5-ab83-aab.docs.buildwithfern.com/learn
┌─
│ ✓ docs.example.com
└─
```
```

### Automate with GitHub Actions

Generate preview links automatically for every pull request by adding a GitHub Actions workflow. [Add your `FERN_TOKEN` to the repository secrets](/learn/cli-api-reference/cli-reference/commands#fern-token) before using these workflows.

<CodeBlock title = ".github/workflows/preview-docs.yml">
```yaml
name: Preview Docs

on:
pull_request

jobs:
run:
runs-on: ubuntu-latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[FernStyles.Current] Avoid time-relative terms like 'latest' that become outdated

permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Fern
run: npm install -g fern-api

- name: Generate preview URL
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
OUTPUT=$(fern generate --docs --preview 2>&1) || true
echo "$OUTPUT"
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
echo "🌿 Preview your docs: $URL" > preview_url.txt

- name: Comment URL in PR
uses: thollander/actions-comment-pull-request@v2.4.3
with:
filePath: preview_url.txt
```
</CodeBlock>

<Accordion title="For repositories that accept pull requests from forks">

If your repository accepts contributions from forks, use `pull_request_target` instead of `pull_request` to allow the workflow to access your `FERN_TOKEN` secret:

<CodeBlock title = ".github/workflows/preview-docs.yml">
```yaml
name: Preview Docs

on:
pull_request_target:
branches:
- main

jobs:
run:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Fern
run: npm install -g fern-api

- name: Checkout PR
run: |
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }}
git checkout pr-${{ github.event.pull_request.number }}

- name: Generate preview URL
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
OUTPUT=$(fern generate --docs --preview 2>&1) || true
echo "$OUTPUT"
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
echo "🌿 Preview your docs: $URL" > preview_url.txt

- name: Comment URL in PR
uses: thollander/actions-comment-pull-request@v2.4.3
with:
filePath: preview_url.txt
```
</CodeBlock>

</Accordion>
2 changes: 1 addition & 1 deletion fern/products/docs/pages/getting-started/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Follow this guide to get started with Fern in under 5 minutes.
</Step>
<Step title="Preview your docs">

Before publishing, [preview your changes](/docs/preview-publish/previewing-changes-locally) in your local development environment or generate shareable preview links.
Before publishing, [preview your changes](/docs/preview-publish/preview-changes) in your local development environment or generate shareable preview links.

<Tabs>
<Tab title="Local preview">
Expand Down
Loading