Reference URLs:
# Reference: https://explainshell.com/explain?cmd=find+.%2Fdist+-name+%27index.html%27+-mindepth+2+-type+f+%5C+++++-exec+sh+%5C+++++-c+%27parent%3D%22%24%28dirname+%22%241%22%29%22%3B+mv+%22%241%22+%22%24parent%2F..%2F%24%28basename+%22%24parent%22%29.html%22%3B%27+%5C+++++find-sh+%7B%7D+%5C%3B
find ./dist -name 'index.html' -mindepth 2 -type f \
-exec sh \
-c 'parent="$(dirname "$1")"; mv "$1" "$parent/../$(basename "$parent").html";' \
find-sh {} \;
# Reference: https://explainshell.com/explain?cmd=find+.%2Fdist+-empty+-type+d+-delete
find ./dist -empty -type d -delete
See:
This command searches for index.html
files within the ./dist
directory, but only at a depth greater than 1
(i.e., not directly under ./dist
but further inside its subdirectories). Upon finding each index.html
file,
it executes a shell command to rename and move the file.
This script works by
- converting =>
/blog/post-slug-name/index.html
- to =>
/blog/post-slug-name.html
- Put
migrate-index.sh
in./src/scripts
(of my CF pages project) npm run build && bash ./src/scripts/migrate-index.sh
Of course you could add the migration into your npm run build
directly.