1
0
Fork 0

2024-12-29

This commit is contained in:
Gennadiy 2024-12-29 10:39:46 +03:00
parent 2dc300f8f2
commit ef52324aa4
2 changed files with 33 additions and 39 deletions

View file

@ -39,7 +39,7 @@ sudo gem install --local older-tomato-theme-1.0.1.gem
The site can be built using the `jekyll build` command. After that, we get the `_site` folder with the The site can be built using the `jekyll build` command. After that, we get the `_site` folder with the
generated pages and the `assets` subfolder from the theme. We move the contents of this subfolder back generated pages and the `assets` subfolder from the theme. We move the contents of this subfolder back
to the `_site` folder — we get shorter links, that are used in the theme. After that we bypass HTML pages to the `_site` folder — we get shorter links, that are used in the theme. After that we bypass HTML pages
and optimize a number of tags also for shortness and for correctness. Additionally, we copy from theme the and optimize a set of tags also for shortness and for correctness. Additionally, we copy from theme the
redirection file to the root of the site for all subdirectories, if they don't contain the `index.html` redirection file to the root of the site for all subdirectories, if they don't contain the `index.html`
file. The script is intended for this purpose. file. The script is intended for this purpose.
@ -48,25 +48,22 @@ file. The script is intended for this purpose.
cd _site || exit cd _site || exit
cp -r assets/* . cp -r assets/* .
rm -r assets rm -r assets
# optimizing a number of tags # patterns for optimizing a set of tags
function optimize_html { expr+=('s| class="language-plaintext highlighter-rouge"||g')
echo "Optimize: $1" expr+=('s| class="language-java highlighter-rouge"||g')
sed -i 's| class="language-plaintext highlighter-rouge"||g' "$1" expr+=('s| class="language-html highlighter-rouge"||g')
sed -i 's| class="language-java highlighter-rouge"||g' "$1" expr+=('s| class="language-js highlighter-rouge"||g')
sed -i 's| class="language-html 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" # launching parallel processing of gathered pages and optimizing a set of tags
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 'Optimize: {}' && sed -i -E $(printf " -e '%s'" "${expr[@]}") '{}'"
export -f optimize_html # transition to the site root for directories without a main page
# launching parallel processing of gathered pages and optimizing a number of tags 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 "{}"'
# transition page to the root of the site for directories without a main page
find . -type d -print0 | xargs -I{} -n1 -0 -P0 cp -n return.html {}/index.html
rm -r return.html rm -r return.html
``` ```

View file

@ -47,25 +47,22 @@ sudo gem install --local older-tomato-theme-1.0.1.gem
cd _site || exit cd _site || exit
cp -r assets/* . cp -r assets/* .
rm -r assets rm -r assets
# оптимизация ряда тегов # шаблоны для оптимизации ряда тегов
function optimize_html { expr+=('s| class="language-plaintext highlighter-rouge"||g')
echo "Оптимизация: $1" expr+=('s| class="language-java highlighter-rouge"||g')
sed -i 's| class="language-plaintext highlighter-rouge"||g' "$1" expr+=('s| class="language-html highlighter-rouge"||g')
sed -i 's| class="language-java highlighter-rouge"||g' "$1" expr+=('s| class="language-js highlighter-rouge"||g')
sed -i 's| class="language-html 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
``` ```