chore: Use web-friendly file names

This commit is contained in:
David Lapshin 2023-07-16 11:23:27 +03:00
parent b00b21c98a
commit ca245c78c7
Signed by: daudix
GPG key ID: 93ECF15D3053D81C
5 changed files with 56 additions and 4 deletions

View file

@ -26,3 +26,9 @@ bundle exec jekyll serve --livereload --host 0.0.0.0
```
_Building guide were shamelessly taken from [here](https://talk.jekyllrb.com/t/local-testing-of-existing-github-jekyll-site/7459/4)_
## Rename posts to web-friendly filenames
```shell
./rename.sh posts/
```

View file

@ -25,6 +25,6 @@ Hi there! this is my little snug nook, take your cup of coffee and let's dive in
## Posts
[Gemini: Exploring the Cozy World of Capsules and Space](posts/Gemini: Exploring the Cozy World of Capsules and Space.md){: .page-link}
[Gemini: Exploring the Cozy World of Capsules and Space](posts/gemini-exploring-the-cozy-world-of-capsules-and-space.md){: .page-link}
[Migration from GitHub to Codeberg](posts/Migration from GitHub to Codeberg.md){: .page-link}
[Migration from GitHub to Codeberg](posts/migration-from-github-to-codeberg.md){: .page-link}

View file

@ -336,4 +336,4 @@ There are more things I want to tell you about, I want to write more in-depth po
- [andregarzia.com/2022/01/gemini-is-a-little-gem.html](https://andregarzia.com/2022/01/gemini-is-a-little-gem.html)
- [voidspace.blog/ramble/capsule-importance.gmi](gemini://voidspace.blog/ramble/capsule-importance.gmi)
[Go Back](<javascript:window.history.go(-1);>){: .inline-button}
[Go Home](/){: .inline-button}

View file

@ -162,4 +162,4 @@ Guys over Codeberg seem to be very nice so if you value your code then you may w
This is all for now, take ~~cake~~ care!
[Go Back](<javascript:window.history.go(-1);>){: .inline-button}
[Go Home](/){: .inline-button}

46
rename.sh Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Check if a directory argument is provided
if [[ -n "$1" ]]; then
# Use the specified directory
target_directory="$1"
else
# Use the current directory if no argument is provided
target_directory="."
fi
# Function to rename blog files
rename_blog_files() {
# Loop through each file in the specified directory
for file in "$target_directory"/*; do
# Check if the file is a regular file (to avoid directories)
if [[ -f "$file" ]]; then
# Get the filename without the directory path
filename=$(basename "$file")
# Separate filename and extension
filename_no_ext="${filename%.*}"
extension="${filename##*.}"
# Convert the filename to lowercase
new_filename=$(echo "$filename_no_ext" | tr '[:upper:]' '[:lower:]')
# Replace spaces with hyphens
new_filename=${new_filename// /-}
# Remove all non-alphabet characters and hyphens
new_filename=$(echo "$new_filename" | tr -cd 'a-z0-9-')
# Combine the new filename and the original extension
new_filename="$new_filename.$extension"
# Check if the new filename is different from the current one
if [[ "$filename" != "$new_filename" ]]; then
# Rename the file
mv "$file" "$target_directory/$new_filename"
echo "Renamed '$file' to '$target_directory/$new_filename'"
fi
fi
done
}
# Call the function to rename blog files
rename_blog_files