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
echo "Сборка сайта в двух помидорных темах и оптимизация результатов."
time_ms="$(date '+%s%3N')"
# удаление каталогов предыдущей сборки
rm -rf _site
rm -rf _site_older
rm -rf _site_color
# удаление каталогов предыдущей сборки, если таковые имеются
find . -maxdepth 1 -type d -name "_site*" -exec rm -rf {} \;
# сборка сайта в двух помидорных темах
function jekyll_build {
case "$1" in
@ -22,8 +20,8 @@ function jekyll_build {
jekyll build --disable-disk-cache --quiet
}
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_color/_site ./_site/color
@ -41,24 +39,21 @@ cp -r color/assets/* .
rm -r color/assets
rm -r color/404.html
rm -r color/return.html
# оптимизация ряда тегов
function optimize_html {
echo "Оптимизация: $1"
sed -i 's|layout-padding=""|layout-padding|g' "$1"
sed -i 's| class="language-plaintext highlighter-rouge"||g' "$1"
sed -i 's| class="language-java highlighter-rouge"||g' "$1"
sed -i 's| class="language-js highlighter-rouge"||g' "$1"
sed -i 's| class="language-bash highlighter-rouge"||g' "$1"
sed -i 's|<div><div class="highlight">|<div class="highlight">|g' "$1"
sed -i 's|</pre></div></div>|</pre></div>|g' "$1"
sed -i 's|<hr />|<hr>|g' "$1"
sed -i -r 's|<input(.+) />|<input\1>|g' "$1"
sed -i -r 's|<img(.+) />|<img\1>|g' "$1"
}
export -f optimize_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
# шаблоны для оптимизации ряда тегов
expr+=('s|layout-padding=""|layout-padding|g')
expr+=('s| class="language-plaintext highlighter-rouge"||g')
expr+=('s| class="language-java highlighter-rouge"||g')
expr+=('s| class="language-js highlighter-rouge"||g')
expr+=('s| class="language-bash highlighter-rouge"||g')
expr+=('s|<div><div class="highlight">|<div class="highlight">|g')
expr+=('s|</pre></div></div>|</pre></div>|g')
expr+=('s|<hr />|<hr>|g')
expr+=('s|<input(.+) />|<input\1>|g')
expr+=('s|<img(.+) />|<img\1>|g')
# запуск параллельной обработки собранных страниц и оптимизация ряда тегов
find . -type f -name "*.html" -printf '%p\0' | xargs -I{} -n1 -0 -P0 bash -c \
"echo 'Оптимизация: {}' && sed -i -E $(printf " -e '%s'" "${expr[@]}") '{}'"
# переход в корень сайта для каталогов без заглавной страницы
find . -type d -exec cp -n return.html {}/index.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,
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
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.
```bash
@ -36,17 +36,13 @@ function directory_tree {
local head="$2"
local tail="$3"
# prefix for current element
if [ "one" == "$4" ]; then
echo -n "/"
else
echo -ne "\n$head"
fi
[ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head"
# current element of the tree
echo -n "<a href='${path#*/}'>${path##*/}</a>"
printf '%s' "<a href='${path#*/}'>${path##*/}</a>"
# recursive calls for subdirectories
if [ -d "$path" ]; then
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 i # counter
for ((i = 0; i < size; i++)); do
@ -62,15 +58,11 @@ function directory_tree {
done
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' ' ')"
# put the tree in a container, add a title and output to a file
{
echo "## Directory tree"
echo -ne "\n<pre>"
directory_tree .
echo -e "\n</pre>"
} >DIRECTORY_TREE.md
# place the tree in a container, add a header and output to a file
printf '%s\n' "## Directory tree" "" "<pre>" \
"$(directory_tree . | grep '\S')" "</pre>" >DIRECTORY_TREE.md
```
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 tail="$3"
# префикс для текущего элемента
if [ "one" == "$4" ]; then
echo -n "/"
else
echo -ne "\n$head"
fi
[ "one" == "$4" ] && printf '%s' "/" || printf '\n%s' "$head"
# текущий элемент дерева
echo -n "<a href='${path#*/}'>${path##*/}</a>"
printf '%s' "<a href='${path#*/}'>${path##*/}</a>"
# рекурсивные вызовы для подкаталогов
if [ -d "$path" ]; then
local list # массив файлов и каталогов
readarray -t list <<<"$(list_directory_contents "$path")"
readarray -t list < <(list_directory_contents "$path")
local size=${#list[@]} # длина массива
local i # счётчик
for ((i = 0; i < size; i++)); do
@ -61,15 +57,11 @@ function directory_tree {
done
fi
}
# строка исключений для "ls" из списка ".gitignore" — неотслеживаемые файлы
# строка исключений для "ls" из списка неотслеживаемых файлов ".gitignore"
exclusions="-I'.git' $(sed -E "s|^(.*)$|-I'\1'|" .gitignore | tr '\n' ' ')"
# помещаем дерево в контейнер, добавляем заголовок и выводим в файл
{
echo "## Дерево каталогов"
echo -ne "\n<pre>"
directory_tree .
echo -e "\n</pre>"
} >DIRECTORY_TREE.md
printf '%s\n' "## Дерево каталогов" "" "<pre>" \
"$(directory_tree . | grep '\S')" "</pre>" >DIRECTORY_TREE.md
```
Запускаем скрипт в корне репозитория и сохраняем полученный файл.

View file

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