diff --git a/fern/products/docs/pages/changelog/2026-01-30.mdx b/fern/products/docs/pages/changelog/2026-01-30.mdx new file mode 100644 index 000000000..0162a3054 --- /dev/null +++ b/fern/products/docs/pages/changelog/2026-01-30.mdx @@ -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). diff --git a/fern/products/docs/pages/getting-started/preview-changes-locally.mdx b/fern/products/docs/pages/getting-started/preview-changes-locally.mdx index 9ec32d111..cc23e928b 100644 --- a/fern/products/docs/pages/getting-started/preview-changes-locally.mdx +++ b/fern/products/docs/pages/getting-started/preview-changes-locally.mdx @@ -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 Install the following: @@ -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<> $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 @@ -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<> $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 @@ -136,4 +216,4 @@ jobs: ``` - \ No newline at end of file +