|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Chevron position (right: -.8rem) + remove arrow.png from Share your stories submenu. |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +THEME="${THEME:-/var/www/html/blog/wp-content/themes/eucodewe-1389}" |
| 6 | +WP_ROOT="${WP_ROOT:-/var/www/html/blog}" |
| 7 | +SHARE_TEXT="Share your stories" |
| 8 | + |
| 9 | +[[ -d "$THEME" ]] || { echo "Theme not found: $THEME"; exit 1; } |
| 10 | +[[ -d "$WP_ROOT" ]] || { echo "WP_ROOT not found: $WP_ROOT"; exit 1; } |
| 11 | + |
| 12 | +cd "$THEME" |
| 13 | +chmod u+w new.css 2>/dev/null || true |
| 14 | + |
| 15 | +python3 <<'PY' |
| 16 | +from pathlib import Path |
| 17 | +import re |
| 18 | +
|
| 19 | +css = Path("new.css") |
| 20 | +text = css.read_text() |
| 21 | +
|
| 22 | +# Don't hide chevron on last top-level item when it has children (Blog) |
| 23 | +text = text.replace( |
| 24 | + ".header__menu nav > ul > li:last-child a:after {\n display: none;\n}", |
| 25 | + ".header__menu nav > ul > li:last-child:not(.menu-item-has-children) a:after {\n display: none;\n}", |
| 26 | +) |
| 27 | +
|
| 28 | +chevron_sel = ( |
| 29 | + "li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-has-children a:after" |
| 30 | +) |
| 31 | +chevron_block = """li.menu-item.menu-item-type-custom.menu-item-object-custom.menu-item-has-children a:after { |
| 32 | + content: ""; |
| 33 | + width: 10px; |
| 34 | + height: 10px; |
| 35 | + background: url(https://codeweek.eu/blog/wp-content/uploads/2025/01/Vector-6.svg); |
| 36 | + display: block; |
| 37 | + background-size: contain; |
| 38 | + background-repeat: no-repeat; |
| 39 | + background-position: center; |
| 40 | + transition: 0.3s; |
| 41 | + right: -.8rem; |
| 42 | +}""" |
| 43 | +
|
| 44 | +pattern = re.compile( |
| 45 | + r"li\.menu-item\.menu-item-type-custom\.menu-item-object-custom\.menu-item-has-children a:after\s*\{[^}]+\}", |
| 46 | + re.S, |
| 47 | +) |
| 48 | +if pattern.search(text): |
| 49 | + text = pattern.sub(chevron_block, text, count=1) |
| 50 | + print("Updated chevron rule with right: -.8rem") |
| 51 | +else: |
| 52 | + print("WARNING: chevron rule not found — append manually if needed") |
| 53 | +
|
| 54 | +# Remove submenu arrow layout overrides (no longer needed) |
| 55 | +for pat in [ |
| 56 | + r"\n/\* Blog dropdown: Share your stories.*?(?=\n/\* |\Z)", |
| 57 | + r"\n/\* Blog nav: restore dropdown chevron.*?(?=\n/\* |\Z)", |
| 58 | + r"\n/\* Blog nav: chevron on Blog.*?(?=\n/\* |\Z)", |
| 59 | +]: |
| 60 | + text = re.sub(pat, "\n", text, flags=re.S) |
| 61 | +
|
| 62 | +css.write_text(text) |
| 63 | +print("Patched new.css") |
| 64 | +PY |
| 65 | + |
| 66 | +echo "--- chevron rule ---" |
| 67 | +grep -n -A12 "menu-item-has-children a:after" new.css | head -15 |
| 68 | + |
| 69 | +cd "$WP_ROOT" |
| 70 | +command -v wp >/dev/null 2>&1 || { echo "wp-cli required for menu arrow removal"; exit 1; } |
| 71 | + |
| 72 | +SHARE_ID="" |
| 73 | +for menu in primary header main "Menu 1" 2; do |
| 74 | + SHARE_ID=$(wp menu item list "$menu" --fields=db_id,title --format=csv --allow-root 2>/dev/null \ |
| 75 | + | awk -F, -v t="$SHARE_TEXT" '$2 ~ t {print $1; exit}') || true |
| 76 | + [[ -n "${SHARE_ID:-}" ]] && break |
| 77 | +done |
| 78 | +SHARE_ID="${SHARE_ID:-8142}" |
| 79 | + |
| 80 | +wp eval --allow-root " |
| 81 | +\$id = (int) ${SHARE_ID}; |
| 82 | +delete_post_meta(\$id, 'rt-wp-menu-custom-fields'); |
| 83 | +delete_transient('rt-wp-menu-custom-fields-' . \$id); |
| 84 | +echo \"Removed arrow custom HTML from menu item \$id\n\"; |
| 85 | +" |
| 86 | + |
| 87 | +wp cache flush --allow-root 2>/dev/null | tail -1 || true |
| 88 | +for svc in php8.3-fpm php8.2-fpm php8.1-fpm php8.0-fpm; do |
| 89 | + systemctl is-active --quiet "$svc" 2>/dev/null && systemctl reload "$svc" && echo "Reloaded $svc" && break |
| 90 | +done |
| 91 | +echo "Done. Hard-refresh https://codeweek.eu/blog/" |
0 commit comments