<commit_before>#!/bin/bash

html_file_name=mysql-notes.html
style_file_name=styles.css

# 解决 Mac 与 Linux 中 sed 处理不统一的问题
gsed=`which sed`
if [[ `uname` == Darwin* ]]
then
  gsed=`which gsed`
fi

# 确保 cssnano 命令被安装
cssnano=`which cssnano`
if [ ! -n `which cssnano` ]; then
  npm install cssnano-cli --g --registry=https://registry.npm.taobao.org
  cssnano=`which cssnano`
fi

# 确保 html-minifier 命令被安装
html-minifier=`which html-minifier`
if [ ! -n `which html-minifier` ]; then
  npm install html-minifier -g --registry=https://registry.npm.taobao.org
  html-minifier=`which html-minifier`
fi

git push origin master

asciidoctor mysql-notes.adoc -o $html_file_name

temp_folder="/tmp/mysql-notes-`date  "+%Y%m%d%H%M%S"`"

mkdir $temp_folder

mv $html_file_name $temp_folder
cp -R ./images $temp_folder

git checkout deploy

rm -rf *

mv $temp_folder/* .

rm -rf $style_file_name
touch  $style_file_name

## 声明一个数字变量，可以带引号
declare -a start_lines=(`awk '/<style>/{print NR}' $html_file_name`)
declare -a end_lines=(`awk '/<\/style>/{print NR}' $html_file_name`)

# 获取数组长度
arraylength=${#start_lines[@]}

# 遍历数组，获取下标以及各个元素
for (( i=0; i<${arraylength}; i++ ));
do
  $gsed -n "${start_lines[$i]}, ${end_lines[$i]}p" $html_file_name | grep -v "style>" | grep -v "/\*" 1>> $style_file_name
  # cat $html_file_name | head -n ${end_lines[$i]} | tail -n +${start_lines[$i]} | grep -v "style>" | grep -v "/\*" 1>> $style_file_name
done

# 遍历数组，删除样式
for (( i=${arraylength}-1; i>=0; i-- ));
do
  $gsed -i "${start_lines[$i]}, ${end_lines[$i]}d" $html_file_name
done

# 压缩 CSS
$cssnano $style_file_name $style_file_name

# 将样式文件添加到 HTML 中
$gsed -i "s/\(<\/head>\)/<link rel=\"stylesheet\" href=\".\/${style_file_name}\">\n\1/" $html_file_name

# 替换 Font Awesome
$gsed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs/http:\/\/cdn.bootcss.com/" $html_file_name

# 替换 Google Fonts
$gsed -i "s/https:\/\/fonts.googleapis.com/http:\/\/fonts.proxy.ustclug.org/" $html_file_name

$html-minifier -c html-minifier.config.json $html_file_name -o index.html

git add .

git commit -am "ready to deploy"

git push origin deploy

rsync -avz . deployer@192.168.3.11:/home/deployer/diguage.com/notes/mysql

rm -rf $temp_folder

git checkout master<commit_msg>修正变量命名<commit_after>#!/bin/bash

html_file_name=mysql-notes.html
style_file_name=styles.css

# 解决 Mac 与 Linux 中 sed 处理不统一的问题
gsed=`which sed`
if [[ `uname` == Darwin* ]]
then
  gsed=`which gsed`
fi

# 确保 cssnano 命令被安装
cssnano=`which cssnano`
if [ ! -n `which cssnano` ]; then
  npm install cssnano-cli --g --registry=https://registry.npm.taobao.org
  cssnano=`which cssnano`
fi

# 确保 html-minifier 命令被安装
htmlminifier=`which html-minifier`
if [ ! -n `which html-minifier` ]; then
  npm install html-minifier -g --registry=https://registry.npm.taobao.org
  htmlminifier=`which html-minifier`
fi

git push origin master

asciidoctor mysql-notes.adoc -o $html_file_name

temp_folder="/tmp/mysql-notes-`date  "+%Y%m%d%H%M%S"`"

mkdir $temp_folder

mv $html_file_name $temp_folder
cp -R ./images $temp_folder

git checkout deploy

rm -rf *

mv $temp_folder/* .

rm -rf $style_file_name
touch  $style_file_name

## 声明一个数字变量，可以带引号
declare -a start_lines=(`awk '/<style>/{print NR}' $html_file_name`)
declare -a end_lines=(`awk '/<\/style>/{print NR}' $html_file_name`)

# 获取数组长度
arraylength=${#start_lines[@]}

# 遍历数组，获取下标以及各个元素
for (( i=0; i<${arraylength}; i++ ));
do
  $gsed -n "${start_lines[$i]}, ${end_lines[$i]}p" $html_file_name | grep -v "style>" | grep -v "/\*" 1>> $style_file_name
  # cat $html_file_name | head -n ${end_lines[$i]} | tail -n +${start_lines[$i]} | grep -v "style>" | grep -v "/\*" 1>> $style_file_name
done

# 遍历数组，删除样式
for (( i=${arraylength}-1; i>=0; i-- ));
do
  $gsed -i "${start_lines[$i]}, ${end_lines[$i]}d" $html_file_name
done

# 压缩 CSS
$cssnano $style_file_name $style_file_name

# 将样式文件添加到 HTML 中
$gsed -i "s/\(<\/head>\)/<link rel=\"stylesheet\" href=\".\/${style_file_name}\">\n\1/" $html_file_name

# 替换 Font Awesome
$gsed -i "s/https:\/\/cdnjs.cloudflare.com\/ajax\/libs/http:\/\/cdn.bootcss.com/" $html_file_name

# 替换 Google Fonts
$gsed -i "s/https:\/\/fonts.googleapis.com/http:\/\/fonts.proxy.ustclug.org/" $html_file_name

$htmlminifier -c html-minifier.config.json $html_file_name -o index.html

git add .

git commit -am "ready to deploy"

git push origin deploy

rsync -avz . deployer@192.168.3.11:/home/deployer/diguage.com/notes/mysql

rm -rf $temp_folder

git checkout master
{'fraction_non_alphanumeric': 0.1817160826594789, 'fraction_numerical': 0.006738544474393531, 'mean_word_length': 4.214285714285714, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '268149', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1964, 'n_words': 403}