Skip to content

Instantly share code, notes, and snippets.

@moshfeu
Last active September 28, 2018 11:26
Show Gist options
  • Save moshfeu/a795765dd134d77d8adab39a8002d3d6 to your computer and use it in GitHub Desktop.
Save moshfeu/a795765dd134d77d8adab39a8002d3d6 to your computer and use it in GitHub Desktop.
pre-commit file to github pages to generate tags pages
#!/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