|
| 1 | +import os |
| 2 | +import re |
| 3 | + |
| 4 | +files_to_update = [ |
| 5 | + "posts/best-remote-work-setup-2026.html", |
| 6 | + "posts/budget-laptops-under-1000.html", |
| 7 | + "posts/best-laptops-for-students-2026.html", |
| 8 | + "posts/best-premium-laptop-for-work-2026.html", |
| 9 | + "posts/do-you-need-thunderbolt-dock.html", |
| 10 | + "posts/is-a-4k-monitor-worth-it.html", |
| 11 | + "posts/is-samsung-990-pro-worth-it.html", |
| 12 | +] |
| 13 | + |
| 14 | +cluster_signal = '\n<p class="cluster-signal" style="font-style: italic; font-size: 0.92rem; color: #a1a1aa; margin-top: -0.5rem; margin-bottom: 1.5rem;">This guide is part of our <a href="/posts/best-remote-work-setup-2026.html" style="color: var(--accent); text-decoration: underline;">Remote Work Hardware Series</a>.</p>' |
| 15 | + |
| 16 | +for file_path in files_to_update: |
| 17 | + if not os.path.exists(file_path): |
| 18 | + print(f"Missing: {file_path}") |
| 19 | + continue |
| 20 | + |
| 21 | + with open(file_path, "r", encoding="utf-8") as f: |
| 22 | + content = f.read() |
| 23 | + |
| 24 | + if "cluster-signal" in content: |
| 25 | + print(f"Already injected in: {file_path}") |
| 26 | + continue |
| 27 | + |
| 28 | + # Regex to find <p class="post-meta">...</p> and insert right after it. |
| 29 | + # We account for the fact that some pages might not have it exactly matching. |
| 30 | + # We can also look for <span class="badge">...</span> and <h1 class="post-title">...</h1> |
| 31 | + |
| 32 | + # We will look for <p class="post-meta">....</p> |
| 33 | + pattern = r'(<p class="post-meta">.*?</p>)' |
| 34 | + |
| 35 | + # In budget-laptops-under-1000.html, there's no post-meta! |
| 36 | + # Let's check where to inject if post-meta is missing. |
| 37 | + if re.search(pattern, content): |
| 38 | + new_content = re.sub(pattern, r'\1' + cluster_signal, content, count=1) |
| 39 | + else: |
| 40 | + # If no post-meta, insert after post-title |
| 41 | + pattern_title = r'(<h1 class="post-title">.*?</h1>)' |
| 42 | + new_content = re.sub(pattern_title, r'\1' + cluster_signal, content, count=1) |
| 43 | + |
| 44 | + if new_content != content: |
| 45 | + with open(file_path, "w", encoding="utf-8") as f: |
| 46 | + f.write(new_content) |
| 47 | + print(f"Injected in: {file_path}") |
| 48 | + else: |
| 49 | + print(f"Failed to inject in: {file_path}") |
0 commit comments