Last active
September 28, 2018 11:26
-
-
Save moshfeu/a795765dd134d77d8adab39a8002d3d6 to your computer and use it in GitHub Desktop.
pre-commit file to github pages to generate tags pages
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
#!/bin/bash | |
# run chmod +x .git/hooks/pre-commit | |
TAGS=() | |
for f in $(find . -name '*.md' -mindepth 1 -maxdepth 10 -type f) ; | |
do | |
# echo "$f" | |
while read line | |
do | |
if [[ $line =~ (tags: )(\[(.*)\]) ]]; | |
then | |
for i in ${BASH_REMATCH[2]//,/ } | |
do | |
tag=${i//\'}; | |
tag=${tag/[}; | |
tag=${tag/]}; | |
if ! [[ ${TAGS[*]} =~ ${tag} ]] | |
then | |
# echo "not contains: ${tag}"; | |
TAGS+=(${tag}); | |
fi | |
done | |
fi | |
done < "$f" | |
done | |
mkdir -p tags | |
for tag in "${TAGS[@]}" | |
do | |
echo -e "---\ntitle: ${tag}\nlayout: tag\npermalink: /tags/${tag}/\n---" > tags/${tag}.md; | |
echo "created: ${tag}"; | |
done | |
echo 'done'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment