#!/bin/bash
# Скрипт для обновления конфигурации Hugo для работы с S3
# Обновляет shortcodes и настройки для работы с внешними изображениями
set -e # Остановка при ошибке
# Загрузка конфигурации
source "$(dirname "$0")/config.sh"
log "Начало обновления конфигурации Hugo..."
# Обновление shortcode figure.html
log "Обновление shortcode figure.html..."
figure_shortcode="./layouts/shortcodes/figure.html"
if [ -f "$figure_shortcode" ]; then
# Создание backup
cp "$figure_shortcode" "$BACKUP_DIR/figure.html.backup"
# Создание обновленного shortcode
cat > "$figure_shortcode" << 'EOF'
{{- if not ($.Page.Scratch.Get "figurecount") }}{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 -}}
{{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
{{- $thumbURL := "" }}
{{- if or (hasPrefix $thumb "http://") (hasPrefix $thumb "https://") }}
{{- $thumbURL = $thumb }}
{{- else }}
{{- $thumbURL = $thumb | relURL }}
{{- end }}
{{- $linkURL := "" }}
{{- $link := .Get "link" | default (.Get "src") }}
{{- if or (hasPrefix $link "http://") (hasPrefix $link "https://") }}
{{- $linkURL = $link }}
{{- else }}
{{- $linkURL = $link | relURL }}
{{- end }}
{{ with $linkURL }}{{ end }}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
{{- with .Get "title" }}
{{.}}
{{ end }}
{{- if or (.Get "caption") (.Get "attr")}}
{{- .Get "caption" -}}
{{- with .Get "attrlink"}}{{ .Get "attr" }}{{ else }}{{ .Get "attr"}}{{ end -}}
{{- end }}
{{- end }}
EOF
log "Обновлен figure.html shortcode"
else
log "figure.html shortcode не найден, создаем новый..."
mkdir -p "./layouts/shortcodes"
# Создать тот же код что выше
fi
# Обновление shortcode gallery.html
log "Обновление shortcode gallery.html..."
gallery_shortcode="./layouts/shortcodes/gallery.html"
if [ -f "$gallery_shortcode" ]; then
# Создание backup
cp "$gallery_shortcode" "$BACKUP_DIR/gallery.html.backup"
# Создание обновленного shortcode
cat > "$gallery_shortcode" << 'EOF'
{{- if not ($.Page.Scratch.Get "figurecount") }}{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 }}