2024-12-29

This commit is contained in:
Gennadiy 2024-12-29 10:39:46 +03:00
parent 928f0beebe
commit 991fcdda6d
4 changed files with 36 additions and 57 deletions

View file

@ -1,10 +1,8 @@
#!/bin/bash #!/bin/bash
echo "Сборка сайта в двух помидорных темах и оптимизация результатов." echo "Сборка сайта в двух помидорных темах и оптимизация результатов."
time_ms="$(date '+%s%3N')" time_ms="$(date '+%s%3N')"
# удаление каталогов предыдущей сборки # удаление каталогов предыдущей сборки, если таковые имеются
rm -rf _site find . -maxdepth 1 -type d -name "_site*" -exec rm -rf {} \;
rm -rf _site_older
rm -rf _site_color
# сборка сайта в двух помидорных темах # сборка сайта в двух помидорных темах
function jekyll_build { function jekyll_build {
case "$1" in case "$1" in
@ -22,8 +20,8 @@ function jekyll_build {
jekyll build --disable-disk-cache --quiet jekyll build --disable-disk-cache --quiet
} }
export -f jekyll_build export -f jekyll_build
# запуск параллельной сборки сайта в двух помидорных темах # запуск параллельной сборки сайта в двух помидорных темах оформления
printf '%s\0' {older,color} | xargs -I{} -n1 -0 -P0 bash -c 'jekyll_build "{}"' printf 'jekyll_build "%s"\0' {older,color} | xargs -n1 -0 -P0 bash -c
# объединение двух сборок # объединение двух сборок
cp -r _site_older/_site . cp -r _site_older/_site .
cp -r _site_color/_site ./_site/color cp -r _site_color/_site ./_site/color
@ -41,24 +39,21 @@ cp -r color/assets/* .
rm -r color/assets rm -r color/assets
rm -r color/404.html rm -r color/404.html
rm -r color/return.html rm -r color/return.html
# оптимизация ряда тегов # шаблоны для оптимизации ряда тегов
function optimize_html { expr+=('s|layout-padding=""|layout-padding|g')
echo "Оптимизация: $1" expr+=('s| class="language-plaintext highlighter-rouge"||g')
sed -i 's|layout-padding=""|layout-padding|g' "$1" expr+=('s| class="language-java highlighter-rouge"||g')
sed -i 's| class="language-plaintext highlighter-rouge"||g' "$1" expr+=('s| class="language-js highlighter-rouge"||g')
sed -i 's| class="language-java highlighter-rouge"||g' "$1" expr+=('s| class="language-bash highlighter-rouge"||g')
sed -i 's| class="language-js highlighter-rouge"||g' "$1" expr+=('s|<div><div class="highlight">|<div class="highlight">|g')
sed -i 's| class="language-bash highlighter-rouge"||g' "$1" expr+=('s|</pre></div></div>|</pre></div>|g')
sed -i 's|<div><div class="highlight">|<div class="highlight">|g' "$1" expr+=('s|<hr />|<hr>|g')
sed -i 's|</pre></div></div>|</pre></div>|g' "$1" expr+=('s|<input(.+) />|<input\1>|g')
sed -i 's|<hr />|<hr>|g' "$1" expr+=('s|<img(.+) />|<img\1>|g')
sed -i -r 's|<input(.+) />|<input\1>|g' "$1" # запуск параллельной обработки собранных страниц и оптимизация ряда тегов
sed -i -r 's|<img(.+) />|<img\1>|g' "$1" find . -type f -name "*.html" -printf '%p\0' | xargs -I{} -n1 -0 -P0 bash -c \
} "echo 'Оптимизация: {}' && sed -i -E $(printf " -e '%s'" "${expr[@]}") '{}'"
export -f optimize_html # переход в корень сайта для каталогов без заглавной страницы
# запуск параллельной обработки собранных страниц и оптимизации ряда тегов find . -type d -exec cp -n return.html {}/index.html \;
find . -type f -name "*.html" -print0 | xargs -I{} -n1 -0 -P0 bash -c 'optimize_html "{}"'
# страница перехода в корень сайта для каталогов без заглавной страницы
find . -type d -print0 | xargs -I{} -n1 -0 -P0 cp -n return.html {}/index.html
rm -r return.html rm -r return.html
echo "Общее время выполнения: $(("$(date '+%s%3N')" - "$time_ms")) мс." echo "Общее время выполнения: $(($(date '+%s%3N') - time_ms)) мс."

View file

@ -19,7 +19,7 @@ will be used in the web interface to navigate through the objects of the reposit
We create a recursive function and use it to bypass all files and directories of the repository, We create a recursive function and use it to bypass all files and directories of the repository,
excluding the list from `.gitignore` — we build a directory structure in the form of a tree. We excluding the list from `.gitignore` — we build a directory structure in the form of a tree. We
output the elements as links `<a>`, collapse folders with one nested element into one line, place output the elements as links `<a>`, collapse folders with one nested element into one line, place
the constructed tree in a container `<pre>` and add the title — as a result, we get a short and the constructed tree in a container `<pre>` and add the header — as a result, we get a short and
concise Markdown file with links. concise Markdown file with links.
```bash ```bash
@ -36,17 +36,13 @@ function directory_tree {
local head="$2" local head="$2"
local tail="$3" local tail="$3"
# prefix for current element # prefix for current element
if [ "one" == "$4" ]; then [ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head"
echo -n "/"
else
echo -ne "\n$head"
fi
# current element of the tree # current element of the tree
echo -n "<a href='${path#*/}'>${path##*/}</a>" printf '%s' "<a href='${path#*/}'>${path##*/}</a>"
# recursive calls for subdirectories # recursive calls for subdirectories
if [ -d "$path" ]; then if [ -d "$path" ]; then
local list # array of files and directories local list # array of files and directories
readarray -t list <<<"$(list_directory_contents "$path")" readarray -t list < <(list_directory_contents "$path")
local size=${#list[@]} # length of array local size=${#list[@]} # length of array
local i # counter local i # counter
for ((i = 0; i < size; i++)); do for ((i = 0; i < size; i++)); do
@ -62,15 +58,11 @@ function directory_tree {
done done
fi fi
} }
# line of exclusions for "ls" from ".gitignore" list — the untracked files # line of exclusions for "ls" from the list of untracked files ".gitignore"
exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')" exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')"
# put the tree in a container, add a title and output to a file # place the tree in a container, add a header and output to a file
{ printf '%s\n' "## Directory tree" "" "<pre>" \
echo "## Directory tree" "$(directory_tree . | grep '\S')" "</pre>" >DIRECTORY_TREE.md
echo -ne "\n<pre>"
directory_tree .
echo -e "\n</pre>"
} >DIRECTORY_TREE.md
``` ```
Run the script in the root of the repository and save the obtained file. Run the script in the root of the repository and save the obtained file.

View file

@ -35,17 +35,13 @@ function directory_tree {
local head="$2" local head="$2"
local tail="$3" local tail="$3"
# префикс для текущего элемента # префикс для текущего элемента
if [ "one" == "$4" ]; then [ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head"
echo -n "/"
else
echo -ne "\n$head"
fi
# текущий элемент дерева # текущий элемент дерева
echo -n "<a href='${path#*/}'>${path##*/}</a>" printf '%s' "<a href='${path#*/}'>${path##*/}</a>"
# рекурсивные вызовы для подкаталогов # рекурсивные вызовы для подкаталогов
if [ -d "$path" ]; then if [ -d "$path" ]; then
local list # массив файлов и каталогов local list # массив файлов и каталогов
readarray -t list <<<"$(list_directory_contents "$path")" readarray -t list < <(list_directory_contents "$path")
local size=${#list[@]} # длина массива local size=${#list[@]} # длина массива
local i # счётчик local i # счётчик
for ((i = 0; i < size; i++)); do for ((i = 0; i < size; i++)); do
@ -61,15 +57,11 @@ function directory_tree {
done done
fi fi
} }
# строка исключений для "ls" из списка ".gitignore" — неотслеживаемые файлы # строка исключений для "ls" из списка неотслеживаемых файлов ".gitignore"
exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')" exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')"
# помещаем дерево в контейнер, добавляем заголовок и выводим в файл # помещаем дерево в контейнер, добавляем заголовок и выводим в файл
{ printf '%s\n' "## Дерево каталогов" "" "<pre>" \
echo "## Дерево каталогов" "$(directory_tree . | grep '\S')" "</pre>" >DIRECTORY_TREE.md
echo -ne "\n<pre>"
directory_tree .
echo -e "\n</pre>"
} >DIRECTORY_TREE.md
``` ```
Запускаем скрипт в корне репозитория и сохраняем полученный файл. Запускаем скрипт в корне репозитория и сохраняем полученный файл.

View file

@ -2,4 +2,4 @@
echo "Создание архива для последующего развёртывания." echo "Создание архива для последующего развёртывания."
cd _site || exit cd _site || exit
rm -rf ../pomodoro5.zip rm -rf ../pomodoro5.zip
7z a ../pomodoro5.zip . 7z a ../pomodoro5.zip . | grep -E '\S'