-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2190 from spryker/redirects-generator
Redirects generator v1
- Loading branch information
Showing
23 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,35 @@ | ||
#!/bin/bash | ||
|
||
# Function to process Markdown files in a folder and its subfolders recursively | ||
process_markdown_files() { | ||
local folder="$1" | ||
|
||
for file in "$folder"/*; do | ||
if [ -f "$file" ] && [[ "$file" == *.md ]]; then | ||
# Check if "redirect_from:" exists in the file | ||
if ! grep -q "redirect_from:" "$file"; then | ||
# Add "redirect_from:" after "template:" if it's missing | ||
awk '/template:/ && !p {print $0 RS "redirect_from:"; p=1; next} 1' "$file" > temp && mv temp "$file" | ||
|
||
echo "redirect_from added to: $file" | ||
fi | ||
elif [ -d "$file" ]; then | ||
# If it's a directory, recursively process its contents | ||
process_markdown_files "$file" | ||
fi | ||
done | ||
} | ||
|
||
# Specify the folder to add `redirect_from` to | ||
folder_path="" | ||
|
||
# Check if the folder exists | ||
if [ ! -d "$folder_path" ]; then | ||
echo "Folder does not exist: $folder_path" | ||
exit 1 | ||
fi | ||
|
||
# Call the function to process Markdown files and subfolders | ||
process_markdown_files "$folder_path" | ||
|
||
echo "Script completed." |
This file contains 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,54 @@ | ||
#!/bin/bash | ||
|
||
# Function to process files in a folder and its subfolders recursively | ||
process_files() { | ||
local folder="$1" | ||
local root_directory="$2" | ||
|
||
for file in "$folder"/*; do | ||
if [ -f "$file" ]; then | ||
# Get the absolute file path | ||
file_path=$(realpath "$file") | ||
|
||
# Get the relative file path | ||
relative_path=${file_path#$root_directory} | ||
|
||
# Add ' - ' at the start of the relative file path | ||
relative_path=" - $relative_path" | ||
|
||
# Replace ".md" with ".html" in the relative file path | ||
relative_path="${relative_path%.md}.html" | ||
|
||
# Get the content of the original file | ||
original_content=$(cat "$file") | ||
|
||
# Prepend the modified relative file path to the content | ||
updated_content="$relative_path"$'\n'"$original_content" | ||
|
||
# Overwrite the original file with the updated content | ||
echo "$updated_content" > "$file" | ||
|
||
echo "Modified file path added to: $file" | ||
elif [ -d "$file" ]; then | ||
# If it's a directory, recursively process its contents | ||
process_files "$file" "$root_directory" | ||
fi | ||
done | ||
} | ||
|
||
# Specify the folder containing the files to add paths to | ||
folder_path="" | ||
|
||
# Check if the folder exists | ||
if [ ! -d "$folder_path" ]; then | ||
echo "Folder does not exist: $folder_path" | ||
exit 1 | ||
fi | ||
|
||
# Specify the root directory to make paths relative to. Must end with `spryker-docs` | ||
root_directory="" | ||
|
||
# Call the function to process files and subfolders | ||
process_files "$folder_path" "$root_directory" | ||
|
||
echo "Script completed." |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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