46 lines
2.4 KiB
Python
46 lines
2.4 KiB
Python
import sys
|
|
import re
|
|
|
|
with open('tmp_home_current.html', 'r', encoding='utf-8') as f:
|
|
html = f.read()
|
|
|
|
# 1. Find and extract the image block
|
|
img_regex = r'(<!-- wp:group {"layout":{"type":"constrained","contentSize":"1100px"},"style":{"spacing":{"padding":{"top":"40px","bottom":"20px","left":"24px","right":"24px"}}} -->\s*<div class="wp-block-group" style="padding-top:40px;padding-right:24px;padding-bottom:20px;padding-left:24px">{"align":"center"} -->\s*<figure class="wp-block-image aligncenter"><img src="/wp-content/uploads/2026/03/pasted-20260312-192203-5bf6a392\.png".*?</figure>\s*<!-- /wp:image -->\s*</div>\s*<!-- /wp:group -->)'
|
|
|
|
m = re.search(img_regex, html, re.DOTALL)
|
|
if not m:
|
|
print("Error: Could not find image block string.")
|
|
sys.exit(1)
|
|
|
|
img_block_str = m.group(1)
|
|
|
|
# Remove the original image block
|
|
html = html.replace(img_block_str + '\n\n', '')
|
|
html = html.replace(img_block_str + '\n', '')
|
|
html = html.replace(img_block_str, '')
|
|
|
|
# Modify the image block
|
|
new_img_block_str = img_block_str.replace('<!-- wp:image {"align":"center"} -->', '<!-- wp:image {"align":"center","width":"275px","className":"is-resized"} -->')
|
|
new_img_block_str = new_img_block_str.replace('<figure class="wp-block-image aligncenter">', '<figure class="wp-block-image aligncenter is-resized">')
|
|
new_img_block_str = new_img_block_str.replace('max-width:100%', 'width:275px;max-width:100%')
|
|
|
|
# Add the modified image block at the very top of the html
|
|
html = new_img_block_str + '\n\n' + html
|
|
|
|
# 2. Modify "What they're Saying" block padding
|
|
old_saying_regex = r'(<!-- wp:group {"style":{"spacing":{"padding":{"top":"60px","bottom":"60px","left":"24px","right":"24px"},"blockGap":"24px"}},"layout":{"type":"constrained","contentSize":"1400px"}}} -->\s*<div class="wp-block-group" style="padding-top:60px;padding-right:24px;padding-bottom:)60px(;padding-left:24px"><!-- wp:heading {"level":2} -->\s*<h2>What they\'re Saying</h2>)'
|
|
|
|
m2 = re.search(old_saying_regex, html, re.DOTALL)
|
|
if not m2:
|
|
print("Error: Could not find exact saying block string.")
|
|
sys.exit(1)
|
|
|
|
# Replace the "bottom":"60px" and padding-bottom:60px with 0px
|
|
new_saying = m2.group(0).replace('"bottom":"60px"', '"bottom":"0px"').replace('padding-bottom:60px', 'padding-bottom:0px')
|
|
|
|
html = html.replace(m2.group(0), new_saying)
|
|
|
|
with open('tmp_home_current.html', 'w', encoding='utf-8') as f:
|
|
f.write(html)
|
|
print("Success.")
|