-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add broken links check script with api-reference filtering #861
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
3 commits
Select commit
Hold shift + click to select a range
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
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,73 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Change to the mintlify directory | ||
| cd "$(dirname "$0")" | ||
|
|
||
| # Run mint broken-links and capture output | ||
| echo "Checking for broken links in mintlify directory..." | ||
| output=$(mint broken-links 2>&1) | ||
|
|
||
| # Check if mint command failed completely | ||
| if [ $? -ne 0 ] && [ -z "$output" ]; then | ||
| echo "Error: Failed to run 'mint broken-links' command" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if no broken links were found at all | ||
| if echo "$output" | grep -q "No broken links found"; then | ||
| echo "✅ No broken links found" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Process the output to filter out api-reference links | ||
| # First, let's identify files that ONLY have api-reference links | ||
| has_non_api_links=false | ||
| current_file="" | ||
| file_has_non_api_links=false | ||
| filtered_lines="" | ||
|
|
||
| while IFS= read -r line; do | ||
| # Check if this is a file name line (ends with .mdx or .md) | ||
| if echo "$line" | grep -qE '\.(mdx?|md)$'; then | ||
| # If we had a previous file with non-api links, add it to output | ||
| if [ -n "$current_file" ] && [ "$file_has_non_api_links" = true ]; then | ||
| filtered_lines="${filtered_lines}${current_file}\n" | ||
| fi | ||
| current_file="$line" | ||
| file_has_non_api_links=false | ||
| # Check if this is a link line (contains ⎿ or →) | ||
| elif echo "$line" | grep -qE '⎿|→'; then | ||
| # Check if this link is NOT an api-reference link | ||
| if ! echo "$line" | grep -q "/api-reference"; then | ||
| file_has_non_api_links=true | ||
| has_non_api_links=true | ||
| filtered_lines="${filtered_lines}${line}\n" | ||
| fi | ||
| # Keep the summary line only if we have non-api links | ||
| elif echo "$line" | grep -q "found.*broken links"; then | ||
| continue # Skip for now, we'll add our own summary | ||
| fi | ||
| done <<< "$output" | ||
|
|
||
| # Add the last file if it had non-api links | ||
| if [ -n "$current_file" ] && [ "$file_has_non_api_links" = true ]; then | ||
| filtered_lines="${filtered_lines}${current_file}\n" | ||
| fi | ||
|
|
||
| # Output results | ||
| if [ "$has_non_api_links" = true ]; then | ||
| echo "❌ Broken links found (excluding /api-reference):" | ||
| echo "" | ||
| printf "$filtered_lines" | ||
|
|
||
| # Count the actual broken links | ||
| link_count=$(printf "$filtered_lines" | grep -c "⎿\|→" || echo "0") | ||
| if [ $link_count -gt 0 ]; then | ||
d-bytebase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "" | ||
| echo "Total broken links (excluding /api-reference): $link_count" | ||
| fi | ||
| exit 1 | ||
| else | ||
| echo "✅ No broken links found (excluding /api-reference)" | ||
| exit 0 | ||
| fi | ||
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.