Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions fern/products/docs/pages/changelog/2026-01-30.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Direct links to changed pages in preview comments

The GitHub Actions workflow for preview links now includes direct links to the specific pages you've modified. When a PR is opened, the preview comment lists each changed MDX file with a clickable link to its preview URL.

This makes it easier for reviewers to jump directly to the pages that were updated rather than navigating through the entire preview site.

Learn more about [automating preview links with GitHub Actions](/learn/docs/preview-publish/preview-changes#automate-with-github-actions).
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description: Learn how to preview documentation changes with Fern using local de

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**](#local-development): Fast iteration with hot reload, best for active development
- [**Preview links**](#preview-links): Shareable URLs for reviews and collaboration

<Info title="Prerequisites">
Install the following:
Expand Down Expand Up @@ -81,6 +81,46 @@ jobs:
echo "$OUTPUT"
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
echo "🌿 Preview your docs: $URL" > preview_url.txt
echo "preview_url=$URL" >> $GITHUB_OUTPUT
echo "Preview URL: $URL"

- name: Get page links for changed MDX files
id: page-links
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
PREVIEW_URL="${{ steps.generate-docs.outputs.preview_url }}"
CHANGED_FILES=$(git diff --name-only origin/main...HEAD -- '*.mdx' 2>/dev/null || echo "")

if [ -z "$CHANGED_FILES" ] || [ -z "$PREVIEW_URL" ]; then
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
fi

BASE_URL=$(echo "$PREVIEW_URL" | grep -oP 'https?://[^/]+')

FILES_PARAM=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//')
RESPONSE=$(curl -sf -H "FERN_TOKEN: $FERN_TOKEN" "${PREVIEW_URL}/api/fern-docs/get-slug-for-file?files=${FILES_PARAM}" 2>/dev/null) || {
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
}

PAGE_LINKS=$(echo "$RESPONSE" | jq -r --arg url "$BASE_URL" \
'.mappings[] | select(.slug != null) | "- [\(.slug)](\($url)/\(.slug))"')

if [ -n "$PAGE_LINKS" ]; then
{ echo "page_links<<EOF"; echo "$PAGE_LINKS"; echo "EOF"; } >> $GITHUB_OUTPUT
else
echo "page_links=" >> $GITHUB_OUTPUT
fi

- name: Create comment content
run: |
echo ":herb: **Preview your docs:** <${{ steps.generate-docs.outputs.preview_url }}>" > preview_url.txt

if [ -n "${{ steps.page-links.outputs.page_links }}" ]; then
echo "" >> preview_url.txt
echo "Here are the markdown pages you've updated:" >> preview_url.txt
echo "${{ steps.page-links.outputs.page_links }}" >> preview_url.txt
fi

- name: Comment URL in PR
uses: thollander/actions-comment-pull-request@v2.4.3
Expand Down Expand Up @@ -128,6 +168,46 @@ jobs:
echo "$OUTPUT"
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
echo "🌿 Preview your docs: $URL" > preview_url.txt
echo "preview_url=$URL" >> $GITHUB_OUTPUT
echo "Preview URL: $URL"

- name: Get page links for changed MDX files
id: page-links
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
PREVIEW_URL="${{ steps.generate-docs.outputs.preview_url }}"
CHANGED_FILES=$(git diff --name-only origin/main...HEAD -- '*.mdx' 2>/dev/null || echo "")

if [ -z "$CHANGED_FILES" ] || [ -z "$PREVIEW_URL" ]; then
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
fi

BASE_URL=$(echo "$PREVIEW_URL" | grep -oP 'https?://[^/]+')

FILES_PARAM=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//')
RESPONSE=$(curl -sf -H "FERN_TOKEN: $FERN_TOKEN" "${PREVIEW_URL}/api/fern-docs/get-slug-for-file?files=${FILES_PARAM}" 2>/dev/null) || {
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
}

PAGE_LINKS=$(echo "$RESPONSE" | jq -r --arg url "$BASE_URL" \
'.mappings[] | select(.slug != null) | "- [\(.slug)](\($url)/\(.slug))"')

if [ -n "$PAGE_LINKS" ]; then
{ echo "page_links<<EOF"; echo "$PAGE_LINKS"; echo "EOF"; } >> $GITHUB_OUTPUT
else
echo "page_links=" >> $GITHUB_OUTPUT
fi

- name: Create comment content
run: |
echo ":herb: **Preview your docs:** <${{ steps.generate-docs.outputs.preview_url }}>" > preview_url.txt

if [ -n "${{ steps.page-links.outputs.page_links }}" ]; then
echo "" >> preview_url.txt
echo "Here are the markdown pages you've updated:" >> preview_url.txt
echo "${{ steps.page-links.outputs.page_links }}" >> preview_url.txt
fi

- name: Comment URL in PR
uses: thollander/actions-comment-pull-request@v2.4.3
Expand All @@ -136,4 +216,4 @@ jobs:
```
</CodeBlock>

</Accordion>
</Accordion>