diff --git a/build.sh b/build.sh index c404931..e5ec690 100755 --- a/build.sh +++ b/build.sh @@ -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|
|
|g' "$1" - sed -i 's|
|
|g' "$1" - sed -i 's|
|
|g' "$1" - sed -i -r 's|||g' "$1" - sed -i -r 's|||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|
|
|g') +expr+=('s|
|
|g') +expr+=('s|
|
|g') +expr+=('s|||g') +expr+=('s|||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)) мс." diff --git a/jekyll_site/en/2023/08/04/directory-tree.md b/jekyll_site/en/2023/08/04/directory-tree.md index 1f7ae80..9264475 100644 --- a/jekyll_site/en/2023/08/04/directory-tree.md +++ b/jekyll_site/en/2023/08/04/directory-tree.md @@ -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 ``, collapse folders with one nested element into one line, place -the constructed tree in a container `
` and add the title — as a result, we get a short and
+the constructed tree in a container `
` 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 "${path##*/}"
+  printf '%s' "${path##*/}"
   # 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
"
-  directory_tree .
-  echo -e "\n
" -} >DIRECTORY_TREE.md +# place the tree in a container, add a header and output to a file +printf '%s\n' "## Directory tree" "" "
" \
+  "$(directory_tree . | grep '\S')" "
" >DIRECTORY_TREE.md ``` Run the script in the root of the repository and save the obtained file. diff --git a/jekyll_site/ru/2023/08/03/directory-tree.md b/jekyll_site/ru/2023/08/03/directory-tree.md index 47809c2..2d09901 100644 --- a/jekyll_site/ru/2023/08/03/directory-tree.md +++ b/jekyll_site/ru/2023/08/03/directory-tree.md @@ -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 "${path##*/}" + printf '%s' "${path##*/}" # рекурсивные вызовы для подкаталогов 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
"
-  directory_tree .
-  echo -e "\n
" -} >DIRECTORY_TREE.md +printf '%s\n' "## Дерево каталогов" "" "
" \
+  "$(directory_tree . | grep '\S')" "
" >DIRECTORY_TREE.md ``` Запускаем скрипт в корне репозитория и сохраняем полученный файл. diff --git a/package.sh b/package.sh index e1420ed..0239b0b 100755 --- a/package.sh +++ b/package.sh @@ -2,4 +2,4 @@ echo "Создание архива для последующего развёртывания." cd _site || exit rm -rf ../pomodoro5.zip -7z a ../pomodoro5.zip . +7z a ../pomodoro5.zip . | grep -E '\S'