<commit_before>#
# Load config file
#

if [ -f $FILE ]; then
	. config.sh
fi
cd $WORKING_DIR

#
# Define a function for logging
#

function say {
	if [[ $JAWS_COLOR -eq 1 ]]; then
		echo ""
		echo -e "\033[4;32m$1\033[0m"
	else
		echo ""
		echo $1
		echo "----------------------------------"
	fi
}

#
# immediately regenerate the site
#

say "Generating Site"

$JAWS_GENERATE

#
# Use absolute CDN paths for images, css, js
#

say "Replacing CDN Paths"

VERBOSE=
if [[ $JAWS_VERBOSE -eq 1 ]]; then
	VERBOSE="-exec echo {} ;"
fi

# Escape path for sed
STATICCDN=${JAWS_STATICCDN//\//\\\/}
IMAGECDN=${JAWS_IMAGECDN//\//\\\/}

find -regextype posix-extended _site \
	-type f \
	-regex '.*\.(html|js|css)' \
	$VERBOSE \
	-exec sed -ri '' "s/\"\/([^\/][^\"]+\.(css|js))\"/\"$STATICCDN\1?r=$JAWS_REVISION\"/g" {} \; \
	-exec sed -ri '' "s/\"\/([^\/][^\"]+\.(png|jpg|jpeg|gif))\"/\"$IMAGECDN\1?r=$JAWS_REVISION\"/g" {} \; \
	-exec sed -ri '' "s/'\/([^\/][^']+\.(css|js))'/'$STATICCDN\1?r=$JAWS_REVISION'/g" {} \; \
	-exec sed -ri '' "s/'\/([^\/][^']+\.(png|jpg|jpeg|gif))'/'$IMAGECDN\1?r=$JAWS_REVISION'/g" {} \;

# TODO - this should really be replaced by a proper parser to be safe

# Dissection of horrible regex:
# "/([^/]         - Quoted, absolute paths. Make sure to exclude no-protocol links e.g., //ajax.googleapis.com/
#   [^"]*+        - Any non-quote character. It's ok that this is greedy unless you do something like not closing your quotes
#   \.(css|js)    - Different file extensions for which to replace
# )"              - End

#
# Minify JS, CSS, and HTML files
#

say "Minifying JS"
<commit_msg>Updated sed to support Linux<commit_after>#
# Load config file
#

if [ -f $FILE ]; then
	. config.sh
fi
cd $WORKING_DIR

#
# Define a function for logging
#

function say {
	if [[ $JAWS_COLOR -eq 1 ]]; then
		echo ""
		echo -e "\033[4;32m$1\033[0m"
	else
		echo ""
		echo $1
		echo "----------------------------------"
	fi
}

#
# immediately regenerate the site
#

say "Generating Site"

$JAWS_GENERATE

#
# Use absolute CDN paths for images, css, js
#

say "Replacing CDN Paths"

VERBOSE=
if [[ $JAWS_VERBOSE -eq 1 ]]; then
	VERBOSE="-exec echo {} ;"
fi

# Escape path for sed
STATICCDN=${JAWS_STATICCDN//\//\\\/}
IMAGECDN=${JAWS_IMAGECDN//\//\\\/}

find _site \
	-regextype posix-extended  \
	-type f \
	-regex '.*\.(html|js|css)' \
	$VERBOSE \
	-exec sed -ri '' "s/\"\/([^\/][^\"]+\.(css|js))\"/\"$STATICCDN\1?r=$JAWS_REVISION\"/g" {} \; \
	-exec sed -ri '' "s/\"\/([^\/][^\"]+\.(png|jpg|jpeg|gif))\"/\"$IMAGECDN\1?r=$JAWS_REVISION\"/g" {} \; \
	-exec sed -ri '' "s/'\/([^\/][^']+\.(css|js))'/'$STATICCDN\1?r=$JAWS_REVISION'/g" {} \; \
	-exec sed -ri '' "s/'\/([^\/][^']+\.(png|jpg|jpeg|gif))'/'$IMAGECDN\1?r=$JAWS_REVISION'/g" {} \;

# TODO - this should really be replaced by a proper parser to be safe

# Dissection of horrible regex:
# "/([^/]         - Quoted, absolute paths. Make sure to exclude no-protocol links e.g., //ajax.googleapis.com/
#   [^"]*+        - Any non-quote character. It's ok that this is greedy unless you do something like not closing your quotes
#   \.(css|js)    - Different file extensions for which to replace
# )"              - End

#
# Minify JS, CSS, and HTML files
#

say "Minifying JS"

{'fraction_non_alphanumeric': 0.23756564720420142, 'fraction_numerical': 0.011121408711770158, 'mean_word_length': 2.570011025358324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '712034', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1272, 'n_words': 320}