Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion INSTALL
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
curl https://raw.github.com/hybridgroup/GitHub-Wikifier/master/pre-commit > .git/hooks/pre-commit;
curl https://raw.githubusercontent.com/hybridgroup/GitHub-Wikifier/master/pre-commit > .git/hooks/pre-commit;
chmod +x .git/hooks/pre-commit;
43 changes: 37 additions & 6 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,44 @@ function wikify() {
fi
}

# to enable log, run
# git config wikify.log true
#
# result:
# [INFO] some info blah blah
#
# to remove logging,
# git config --unset wikify.log
function log_info() {
local should_log=$(git config --get wikify.log)
if [[ -n "$should_log" && "$should_log" = "true" ]]; then
if [[ -n "$2" ]]; then
local log_level="$(echo "$1" | tr 'a-z' 'A-Z')"
local log_message="$2"
echo "[$log_level] $log_message"
else
echo "[INFO] $@"
fi
fi
}

# Filter some files and directories.
function continue_if_filtered() {
if [[ "$@" =~ "images$" ]]; then
# $1 filename
# $2 directory

if [[ "$1" =~ "images$" ]]; then
log_info "$1: images so ignored."
continue
elif [[ ( -n "$2" && $(file "$2/$1" | grep ".*: .* image.*," | sed "s;.*: .*\(image\)[^,]*, .*;\1;") == "image" ) || ( $(file "$1" | grep ".*: .* image.*," | sed "s;.*: .*\(image\)[^,]*, .*;\1;") == "image" ) ]]; then
# check file type and ignore it if it's image
log_info "$1: image so ignored."
continue
elif [[ "$@" =~ "(_sidebar|_footer|_header)" ]]; then
elif [[ "$1" =~ "(_sidebar|_footer|_header)" ]]; then
log_info "$1 in (_sidebar|_footer|_header) so ignored."
continue
elif [[ "$@" == "." ]]; then
elif [[ "$1" == "." ]]; then
log_info "$1: ignored"
continue
fi
}
Expand Down Expand Up @@ -116,14 +147,14 @@ function wikify() {

# Directory write
if [[ "$depth" -eq "0" ]]; then
echo "$(subject_to_header $@.md)" >> "$subjects/Home.md"
echo "$(subject_to_header $@.md)\n---" > "$@/_sidebar.md"
echo "$(subject_to_header $@)" >> "$subjects/Home.md"
echo "$(subject_to_header $@)\n---" > "$@/_sidebar.md"
echo "[email protected]" >> /tmp/wikify.txt
echo "$@/_sidebar.md" >> /tmp/wikify.txt
fi

for file in $(gls_or_ls -l -v $@ | awk '{ print $9 }'); do;
continue_if_filtered $file
continue_if_filtered $file $@
file="$@/$file"

if [[ "$(file -ib $file)" =~ "directory" ]]; then
Expand Down