-
Notifications
You must be signed in to change notification settings - Fork 45
[WEB-4447] Add MDX to Markdown transpilation with content negotiation #3000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59f4abc
Add MDX to Markdown transpilation during build
kennethkalmer 6b8e86b
Add tests for MDX to Markdown transpilation
kennethkalmer 3558d18
Add content negotiation for markdown documentation
kennethkalmer 5a81081
Add content negotiation test suite and fix map priority
kennethkalmer 40b46d7
Add User-Agent based bot detection for markdown serving
kennethkalmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Content Negotiation Test Suite | ||
| # Verifies that nginx serves markdown or HTML based on Accept header | ||
|
|
||
| source "$(dirname "$0")/nginx-utils.sh" | ||
| trap stop_nginx EXIT | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Disable auth for content negotiation tests | ||
| export ENABLE_BASIC_AUTH=false | ||
| export CONTENT_REQUEST_AUTH_TOKENS="" | ||
|
|
||
| # Set default port if not already set | ||
| export PORT=${PORT:-3001} | ||
|
|
||
| # Test helper function | ||
| # Parameters: | ||
| # $1: path - URL path to test | ||
| # $2: accept_header - Accept header value (empty string for default) | ||
| # $3: expected_status - Expected HTTP status code | ||
| # $4: expected_format - "html", "markdown", or "any" | ||
| # $5: test_name - Human-readable test description | ||
| # $6: user_agent - Optional User-Agent string | ||
| run_test() { | ||
| local path="$1" | ||
| local accept_header="$2" | ||
| local expected_status="$3" | ||
| local expected_format="$4" | ||
| local test_name="$5" | ||
| local user_agent="${6:-}" | ||
|
|
||
| echo "🧪 $test_name" | ||
|
|
||
| # Build curl command with optional Accept header and User-Agent | ||
| local curl_cmd="curl --silent --header \"X-Forwarded-Proto: https\"" | ||
|
|
||
| if [ -n "$user_agent" ]; then | ||
| curl_cmd="$curl_cmd --user-agent \"$user_agent\"" | ||
| fi | ||
|
|
||
| if [ -n "$accept_header" ]; then | ||
| curl_cmd="$curl_cmd --header \"Accept: $accept_header\"" | ||
| fi | ||
|
|
||
| curl_cmd="$curl_cmd --write-out \"\\n%{http_code}\\n%{content_type}\"" | ||
| curl_cmd="$curl_cmd \"http://localhost:\${PORT}\${path}\"" | ||
|
|
||
| # Execute request and capture response + metadata | ||
| local response | ||
| response=$(eval "$curl_cmd") | ||
|
|
||
| # Parse response components | ||
| local body=$(echo "$response" | sed '$d' | sed '$d') | ||
| local status=$(echo "$response" | tail -2 | head -1) | ||
| local content_type=$(echo "$response" | tail -1) | ||
|
|
||
| # Assert status code | ||
| if [ "$status" != "$expected_status" ]; then | ||
| echo " ❌ Expected status $expected_status, got $status" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify content format | ||
| if [ "$expected_format" = "markdown" ]; then | ||
| # Check for markdown heading (first line should start with #) | ||
| local first_line=$(echo "$body" | head -1) | ||
| if ! grep -q "^#" <<< "$first_line"; then | ||
| echo " ❌ Expected markdown (starting with #), got: ${first_line:0:50}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify Content-Type header (warning only, not fatal) | ||
| if ! grep -q "text/markdown" <<< "$content_type"; then | ||
| echo " ⚠️ Warning: Content-Type is '$content_type', expected 'text/markdown'" | ||
| fi | ||
| elif [ "$expected_format" = "html" ]; then | ||
| # Check for HTML doctype using here-string to avoid broken pipe | ||
| if ! grep -q "<!DOCTYPE html>" <<< "$body"; then | ||
| echo " ❌ Expected HTML (with DOCTYPE), but not found" | ||
| exit 1 | ||
| fi | ||
| fi | ||
| # "any" format means we don't validate content | ||
|
|
||
| echo " ✅ Passed (status: $status, format: $expected_format)" | ||
| } | ||
|
|
||
| # Main test suite | ||
| echo "================================" | ||
| echo "Content Negotiation Test Suite" | ||
| echo "================================" | ||
| echo | ||
|
|
||
| start_nginx | ||
|
|
||
| # Group 1: Basic Content Negotiation | ||
| echo "Group 1: Basic Content Negotiation" | ||
| echo "-----------------------------------" | ||
| run_test "/docs/channels" "" "200" "html" "Default serves HTML" | ||
| run_test "/docs/channels" "text/markdown" "200" "markdown" "Accept: text/markdown" | ||
| run_test "/docs/channels" "application/markdown" "200" "markdown" "Accept: application/markdown" | ||
| run_test "/docs/channels" "text/plain" "200" "markdown" "Accept: text/plain" | ||
| run_test "/docs/channels" "text/html" "200" "html" "Accept: text/html" | ||
| run_test "/docs/channels" "*/*" "200" "html" "Accept: */*" | ||
| echo | ||
|
|
||
| # Group 2: Browser Behavior | ||
| echo "Group 2: Browser Behavior" | ||
| echo "-------------------------" | ||
| run_test "/docs/channels" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" "200" "html" "Browser Accept header" | ||
| run_test "/docs/channels" "text/html, text/markdown" "200" "html" "HTML prioritized when first" | ||
| echo | ||
|
|
||
| # Group 3: Direct Access | ||
| echo "Group 3: Direct Access" | ||
| echo "----------------------" | ||
| run_test "/docs/channels.md" "" "200" "markdown" "Direct .md access" | ||
| run_test "/docs/channels/index.html" "" "200" "html" "Direct index.html access" | ||
| echo | ||
|
|
||
| # Group 4: Path Variations | ||
| echo "Group 4: Path Variations" | ||
| echo "------------------------" | ||
| run_test "/docs/chat/connect" "text/markdown" "200" "markdown" "Non-index path" | ||
| run_test "/docs/api/realtime-sdk" "text/markdown" "200" "markdown" "Nested index path" | ||
| run_test "/docs/basics" "text/markdown" "200" "markdown" "Simple path" | ||
| echo | ||
|
|
||
| # Group 5: Edge Cases | ||
| echo "Group 5: Edge Cases" | ||
| echo "-------------------" | ||
| run_test "/docs/nonexistent" "" "404" "any" "404 when path missing" | ||
| run_test "/docs/nonexistent" "text/markdown" "404" "any" "404 with markdown Accept" | ||
| run_test "/llms.txt" "" "200" "any" "Non-docs paths unaffected" | ||
| echo | ||
|
|
||
| # Group 6: Bot Detection (User-Agent) | ||
| echo "Group 6: Bot Detection (User-Agent)" | ||
| echo "------------------------------------" | ||
| run_test "/docs/channels" "" "200" "markdown" "Claude-User bot gets markdown" "Claude-User/1.0" | ||
| run_test "/docs/channels" "" "200" "markdown" "ClaudeBot gets markdown" "Mozilla/5.0 (compatible; ClaudeBot/1.0)" | ||
| run_test "/docs/channels" "" "200" "markdown" "ChatGPT-User bot gets markdown" "ChatGPT-User" | ||
| run_test "/docs/channels" "" "200" "markdown" "GPTBot gets markdown" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GPTBot/1.0)" | ||
| run_test "/docs/channels" "" "200" "markdown" "PerplexityBot gets markdown" "PerplexityBot" | ||
| run_test "/docs/channels" "" "200" "html" "Regular browser gets HTML" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" | ||
| echo | ||
|
|
||
| # Group 7: Combined Bot + Accept Header | ||
| echo "Group 7: Combined Bot + Accept Header" | ||
| echo "--------------------------------------" | ||
| run_test "/docs/channels" "text/html" "200" "markdown" "Bot overrides Accept: text/html" "Claude-User/1.0" | ||
| run_test "/docs/channels" "text/markdown" "200" "markdown" "Bot + markdown Accept both work" "GPTBot/1.0" | ||
| echo | ||
|
|
||
| echo "================================" | ||
| echo "✅ All 23 tests passed!" | ||
| echo "================================" | ||
|
|
||
| # Exit explicitly with success | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| title: Test Fixture | ||
| meta_description: "This is a test description" | ||
| redirect_from: | ||
| - /old-path | ||
| languages: | ||
| - javascript | ||
| some_other_field: "should be removed" | ||
| --- | ||
|
|
||
| import Something from '../component' | ||
| import { | ||
| MultiLine, | ||
| Import | ||
| } from 'module' | ||
|
|
||
| export const foo = 'bar'; | ||
| export default SomeComponent; | ||
|
|
||
| {/* This is a JSX comment */} | ||
| {/* | ||
| Multi-line JSX comment | ||
| with multiple lines | ||
| */} | ||
|
|
||
| ## Basic heading | ||
|
|
||
| ## Heading with anchor <a id="test-anchor"/> | ||
|
|
||
| ### Nested heading <a name="nested"/> | ||
|
|
||
| <script type="application/ld+json"> | ||
| {"@context": "https://schema.org"} | ||
| </script> | ||
|
|
||
| Regular content here. | ||
|
|
||
| ## Links and images | ||
|
|
||
| - [Internal link](/docs/channels) | ||
| - [External link](https://example.com) | ||
| - [Hash link](#test-anchor) | ||
| -  | ||
| -  | ||
| -  | ||
|
|
||
| ## Template variables | ||
|
|
||
| Use {{API_KEY}} and {{RANDOM_CHANNEL_NAME}} in your code. | ||
|
|
||
| ## Code blocks | ||
|
|
||
| <Code> | ||
| ```javascript | ||
| const channel = realtime.channels.get('{{RANDOM_CHANNEL_NAME}}'); | ||
| ``` | ||
| </Code> | ||
|
|
||
| Here's a code block with anchors and scripts that should be preserved: | ||
| ```html | ||
| <a id="preserve-this"/> | ||
| <script>console.log('preserve this too')</script> | ||
| {/* preserve JSX comments in code */} | ||
| ``` | ||
|
|
||
| ## JSX Components | ||
|
|
||
| <Aside data-type='note'> | ||
| This component should be preserved as-is. | ||
| </Aside> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.