Skip to content

Commit 6e9e80c

Browse files
committed
add docs link utility script to scripts folder
1 parent daa4ebb commit 6e9e80c

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

scripts/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Documentation Utility Scripts
2+
3+
This directory contains utility scripts for maintaining the Replicated documentation.
4+
5+
## Available Scripts
6+
7+
### `update_docs_links.sh`
8+
9+
This script updates cross-reference link text throughout the documentation to maintain consistency when page titles change.
10+
11+
#### Usage
12+
13+
1. Edit the `patterns` array in the script to include the search and replacement patterns in the format `"[old title]:[new title]"`
14+
2. Run the script from the root of the repository:
15+
```
16+
bash scripts/update_docs_links.sh
17+
```
18+
3. Review the changes with `git diff`
19+
4. Run `npm run build` to verify that links still work
20+
5. Commit the changes
21+
22+
#### Features
23+
24+
- Updates both "see [Title]" and "See [Title]" references
25+
- Searches in docs/reference, docs/enterprise, docs/partials, and docs/vendor directories
26+
- Excludes .history directories from the search
27+
28+
## Adding New Scripts
29+
30+
When adding new utility scripts to this directory:
31+
32+
- Make sure the script is executable: `chmod +x scripts/your_script.sh`
33+
- Document the script's purpose and usage in this README
34+
- Include helpful comments within the script itself

scripts/update_docs_links.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Script to update cross-reference link text
4+
# Run from the root of the replicated-docs repository after changing the title of one or more pages
5+
6+
echo "Updating cross-references..."
7+
8+
# Define replacement patterns with the format "[search pattern]:[replacement]"
9+
patterns=(
10+
# "Adding Nodes to kURL Clusters:Add Nodes to kURL Clusters"
11+
)
12+
13+
# # Count of files processed and replacements made
14+
# files_processed=0
15+
# replacements_made=0
16+
17+
echo "Searching in the /docs directory..."
18+
19+
# Process each file in the docs directory
20+
# Exclude .history
21+
find docs -type f -name "*.md*" -not -path "*/\.history/*" | while read file; do
22+
file_modified=false
23+
24+
# Process each replacement pair
25+
for pattern_pair in "${patterns[@]}"; do
26+
# Split the pattern_pair into search and replacement parts
27+
IFS=':' read -r search replacement <<< "$pattern_pair"
28+
29+
# Check if file contains the pattern
30+
if grep -q "see \[${search}\]" "$file" || grep -q "See \[${search}\]" "$file"; then
31+
# Make the replacements
32+
sed -i '' "s/see \[${search}\]/see \[${replacement}\]/g" "$file"
33+
sed -i '' "s/See \[${search}\]/See \[${replacement}\]/g" "$file"
34+
35+
echo "In $file:"
36+
echo " Replaced: '$search' → '$replacement'"
37+
38+
file_modified=true
39+
((replacements_made++))
40+
fi
41+
done
42+
43+
if $file_modified; then
44+
((files_processed++))
45+
fi
46+
done
47+
48+
echo "Done!"
49+
# echo "Files processed: $files_processed"
50+
# echo "Total replacements made: $replacements_made"
51+
# Instructions for verifying changes
52+
echo "Next steps:"
53+
echo "1. Review the changes using 'git diff'"
54+
echo "2. Run 'npm run build' to check for broken links"
55+
echo "3. Commit the changes if everything looks good"

update_docs_links.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# Script to update cross-reference link text
4+
# To run: 'bash scripts/update_docs_links.sh' from the root of the replicated-docs repository
5+
# Run this script after changing the title of one or more pages in the docs directory
6+
7+
# Define replacement patterns with the format "[search pattern]:[replacement]"
8+
patterns=(
9+
# "Adding Nodes to kURL Clusters:Add Nodes to kURL Clusters"
10+
)
11+
12+
# # Count of files processed and replacements made
13+
# files_processed=0
14+
# replacements_made=0
15+
16+
echo "Searching in the /docs directory and updating cross-references..."
17+
18+
# Process each file in the docs directory
19+
# Exclude .history
20+
find docs -type f -name "*.md*" -not -path "*/\.history/*" | while read file; do
21+
file_modified=false
22+
23+
# Process each replacement pair
24+
for pattern_pair in "${patterns[@]}"; do
25+
# Split the pattern_pair into search and replacement parts
26+
IFS=':' read -r search replacement <<< "$pattern_pair"
27+
28+
# Check if file contains the pattern
29+
if grep -q "see \[${search}\]" "$file" || grep -q "See \[${search}\]" "$file"; then
30+
# Make the replacements
31+
sed -i '' "s/see \[${search}\]/see \[${replacement}\]/g" "$file"
32+
sed -i '' "s/See \[${search}\]/See \[${replacement}\]/g" "$file"
33+
34+
echo "In $file:"
35+
echo " Replaced: '$search' → '$replacement'"
36+
37+
file_modified=true
38+
((replacements_made++))
39+
fi
40+
done
41+
42+
if $file_modified; then
43+
((files_processed++))
44+
fi
45+
done
46+
47+
echo "Done!"
48+
# echo "Files processed: $files_processed"
49+
# echo "Total replacements made: $replacements_made"
50+
# Instructions for verifying changes
51+
echo "Next steps:"
52+
echo "1. Review the changes using 'git diff'"
53+
echo "2. Run 'npm run build' to check for broken links"
54+
echo "3. Commit the changes if everything looks good"

0 commit comments

Comments
 (0)