fix: migrate all hardcoded eyebrow labels and text to CMS to fix locale bleeding

This commit is contained in:
MichalC
2026-09-02 22:46:27 +02:00
parent a24c239ae1
commit 6c87816d13
22 changed files with 427 additions and 44 deletions
+121
View File
@@ -0,0 +1,121 @@
import os
import glob
blocks_dir = "src/blocks"
blocks_with_eyebrow = [
"Affiliation",
"Eligibility",
"FAQTeaser",
"FinalCTA",
"Process",
"ServicesDetailed",
"ServicesList",
"Stats",
"UniqueValue"
]
for block in blocks_with_eyebrow:
config_path = os.path.join(blocks_dir, block, "config.ts")
component_path = os.path.join(blocks_dir, block, "Component.tsx")
if os.path.exists(config_path):
with open(config_path, "r") as f:
content = f.read()
if "'eyebrow'" not in content:
content = content.replace(
"{ name: 'title', type: 'text', required: true, localized: true },",
"{ name: 'eyebrow', type: 'text', localized: true },\n { name: 'title', type: 'text', required: true, localized: true },"
)
# Handle some variations
content = content.replace(
"{ name: 'title', type: 'text', localized: true },",
"{ name: 'eyebrow', type: 'text', localized: true },\n { name: 'title', type: 'text', localized: true },"
)
with open(config_path, "w") as f:
f.write(content)
if os.path.exists(component_path):
with open(component_path, "r") as f:
content = f.read()
# Add eyebrow to Props destructuring
if "eyebrow" not in content:
# Add to destructuring, find where title is destructured
# E.g. const FAQTeaserBlock: React.FC<Props> = ({ title, questions, linkText }) => {
# Find the string `({ ` and see if `title` is inside.
# Just do a simple regex or string replace.
import re
content = re.sub(r'({[\s\S]*?title(.*?)\}) =>', r'{ eyebrow, title\2} =>', content, count=1)
# Replace the hardcoded string with {eyebrow}
# The hardcoded strings are inside <div className="font-mono text-sm md:text-base font-bold text-accent tracking-widest uppercase mb-4">
# // Hardcoded
# </div>
content = re.sub(
r'<div className="font-mono text-sm md:text-base font-bold text-accent tracking-widest uppercase mb-4">\s*//.*?\s*</div>',
r'{eyebrow && (\n <div className="font-mono text-sm md:text-base font-bold text-accent tracking-widest uppercase mb-4">\n // {eyebrow}\n </div>\n )}',
content
)
with open(component_path, "w") as f:
f.write(content)
# Specific fixes for Process and UniqueValue
process_config = os.path.join(blocks_dir, "Process", "config.ts")
with open(process_config, "r") as f:
content = f.read()
if "'subtitle'" not in content:
content = content.replace(
"{ name: 'title', type: 'text', required: true, localized: true },",
"{ name: 'title', type: 'text', required: true, localized: true },\n { name: 'subtitle', type: 'textarea', localized: true },"
)
with open(process_config, "w") as f:
f.write(content)
process_component = os.path.join(blocks_dir, "Process", "Component.tsx")
with open(process_component, "r") as f:
content = f.read()
if "subtitle" not in content.split("}) =>")[0] and "ProcessBlock" in content:
content = re.sub(r'({.*?eyebrow,\s*title(.*?)\}) =>', r'{ eyebrow, title, subtitle\2} =>', content, count=1)
content = re.sub(
r'<p className="text-foreground/75 text-lg md:text-xl font-light leading-relaxed">\s*Prosty.*?\s*</p>',
r'{subtitle && (\n <p className="text-foreground/75 text-lg md:text-xl font-light leading-relaxed">\n {subtitle}\n </p>\n )}',
content
)
with open(process_component, "w") as f:
f.write(content)
uv_config = os.path.join(blocks_dir, "UniqueValue", "config.ts")
with open(uv_config, "r") as f:
content = f.read()
if "'features'" not in content:
content = content.replace(
" ],\n}",
" {\n name: 'features',\n type: 'array',\n localized: true,\n fields: [\n { name: 'text', type: 'text', required: true },\n ],\n },\n ],\n}"
)
with open(uv_config, "w") as f:
f.write(content)
uv_component = os.path.join(blocks_dir, "UniqueValue", "Component.tsx")
with open(uv_component, "r") as f:
content = f.read()
if "features" not in content.split("}) =>")[0] and "UniqueValueBlock" in content:
content = re.sub(r'({.*?eyebrow,\s*title(.*?)\}) =>', r'{ eyebrow, title, features\2} =>', content, count=1)
content = re.sub(
r'<div className="grid grid-cols-1 sm:grid-cols-2 gap-6 w-full pt-6 border-t border-border/60 text-base">\s*<div className="flex items-center gap-2.5 text-foreground/80 font-medium">\s*<span className="w-2 h-2 rounded-full bg-accent" />\s*<span>Bez barier.*?\s*</div>\s*<div className="flex items-center gap-2.5 text-foreground/80 font-medium">\s*<span className="w-2 h-2 rounded-full bg-accent" />\s*<span>Indywidualne.*?\s*</div>\s*</div>',
r'''{features && features.length > 0 && (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-6 w-full pt-6 border-t border-border/60 text-base">
{features.map((feature: any, index: number) => (
<div key={feature.id || index} className="flex items-center gap-2.5 text-foreground/80 font-medium">
<span className="w-2 h-2 rounded-full bg-accent" />
<span>{feature.text}</span>
</div>
))}
</div>
)}''',
content,
flags=re.DOTALL
)
with open(uv_component, "w") as f:
f.write(content)