← back to Dw Marketing Viewer

site-deploy/_remote-edit.py

105 lines

#!/usr/bin/env python3
# Runs ON the Kamatera server. Rebrands wallpapersback.com to the new Optima
# logo: hero image + header/footer wordmark text → "Wallpaper's Back".
# Also fixes the stale wallco-ai .deploy.conf. Backup-safe, abort-safe, idempotent.
import sys, re, time
BASE = "/root/public-projects/wallpapersback"
PUB  = BASE + "/public"
ts   = int(time.time())
BR   = "Wallpaper's Back"

idx = PUB + "/index.html"
s0 = open(idx).read()
s = s0
notes = []

# ---- 1. hero <h1> text -> logo image ----
hero_old = '  <h1 class="hero-wordmark">wallpapersback</h1>'
hero_new = ('  <h1 class="hero-wordmark"><img class="hero-wordmark-img" '
            'src="/wpb-hero-wordmark.png" alt="%s"></h1>' % BR)
css = '.hero-wordmark-img{width:min(820px,86vw);height:auto;display:block;margin:18px auto 0}'
anchor = '@media (max-width:760px) { .hero-wordmark { font-size:clamp(32px, 12vw, 64px) } }'
if 'hero-wordmark-img' in s:
    notes.append("hero already rebranded")
elif hero_old in s:
    s = s.replace(hero_old, hero_new, 1)
    if css.split('{')[0] not in s and anchor in s:
        s = s.replace(anchor, anchor + "\n" + css, 1)
    notes.append("hero -> logo image")
else:
    print("  ! ERROR: hero <h1> not found — aborting, NO changes made")
    sys.exit(1)

# ---- 2. small brand-text spots ----
swaps = [
    ('<span class="ns-name">Wallpapersback</span>',
     '<span class="ns-name">%s</span>' % BR),
    ('<a class="cinema-logo" href="/" aria-label="wallpapersback home">wallpapersback</a>',
     '<a class="cinema-logo" href="/" aria-label="%s home">%s</a>' % (BR, BR)),
    ('<div class="footer-brand">wallpapersback</div>',
     '<div class="footer-brand">%s</div>' % BR),
    # sticky DW header brand (read by dw-header.js) — literal apostrophe; dw-header esc()s it
    ('siteName:"Wallpapersback"', 'siteName:"Wallpaper\'s Back"'),
]
for old, new in swaps:
    if old in s:
        s = s.replace(old, new, 1)
        notes.append("brand text swap")

# ---- B: wordmark overlay centered on the cinema hero (ivory, with scrim) ----
cwm_anchor = '  <div class="cinema-bg" id="heroBg"></div>'
cwm_markup = (cwm_anchor + '\n  <div class="cinema-wm" aria-hidden="true">'
              '<img src="/wpb-hero-wordmark-ivory.png" alt="%s"></div>' % BR)
if 'cinema-wm' not in s and cwm_anchor in s:
    s = s.replace(cwm_anchor, cwm_markup, 1)
    notes.append("cinema hero overlay")
cwm_css = ('.cinema-wm{position:absolute;inset:0;display:flex;align-items:center;'
           'justify-content:center;z-index:4;pointer-events:none}'
           '.cinema-wm::before{content:"";position:absolute;width:64%;height:46%;'
           'background:radial-gradient(ellipse at center,rgba(12,16,12,.5),transparent 70%)}'
           '.cinema-wm img{position:relative;width:min(680px,72vw);height:auto;'
           'filter:drop-shadow(0 3px 16px rgba(0,0,0,.6))}'
           '.hero-wordmark-block{display:none}')
css_anchor = '.hero-wordmark-img{width:min(820px,86vw);height:auto;display:block;margin:18px auto 0}'
if '.cinema-wm{' not in s and css_anchor in s:
    s = s.replace(css_anchor, css_anchor + '\n' + cwm_css, 1)
    notes.append("cinema overlay CSS")

# ---- C: remove dead 404 <script> tags (zd-loader.js, sku-redact.js) ----
# Both 404 on the live host and throw console errors. Idempotent: skip if gone.
dead_scripts = [
    '<script src="/zd-loader.js" defer></script>\n',
    '<script src="/sku-redact.js" defer></script>\n',
]
for tag in dead_scripts:
    if tag in s:
        s = s.replace(tag, '', 1)
        notes.append("removed dead script " + tag.split('"')[1])
    else:
        notes.append("dead script " + tag.split('"')[1] + " already absent")

# ---- write index.html once, with a single backup ----
if s != s0:
    open(idx + ".bak-rebrand-%d" % ts, "w").write(s0)
    open(idx, "w").write(s)
    print("  ✓ index.html: " + "; ".join(notes) + "  (backup .bak-rebrand-%d)" % ts)
else:
    print("  · index.html already fully rebranded")

# ---- 3. fix stale wallco-ai .deploy.conf ----
cf = BASE + "/.deploy.conf"
try:
    c = open(cf).read()
    c2 = re.sub(r'PROJECT_NAME=.*', 'PROJECT_NAME="wallpapersback"', c)
    c2 = re.sub(r'DEPLOY_PATH=.*',  'DEPLOY_PATH="/root/public-projects/wallpapersback"', c2)
    c2 = re.sub(r'HEALTH_URL=.*',   'HEALTH_URL="https://wallpapersback.com/"', c2)
    if c2 != c:
        open(cf + ".bak-%d" % ts, "w").write(c)
        open(cf, "w").write(c2)
        print("  ✓ .deploy.conf corrected (no more wallco-ai; backup written)")
    else:
        print("  · .deploy.conf already clean")
except FileNotFoundError:
    print("  · no .deploy.conf found — skipped")
print("DONE")