bestdadjokes/seo_patch.py

47 lines
2.7 KiB
Python

import re
with open('build.py', 'r') as f:
content = f.read()
# 1. Update title and desc mapping
new_title_desc = """ title = '[ %d+ ] %s That Will Actually Make You Laugh (Clean)' % (len(js), t['name'])
desc = '%s All %d jokes are 100%% clean, painfully funny, and guaranteed to get a groan!' % (t['intro'], len(js))
if len(desc) > 155:
desc = desc[:152] + '...'"""
old_title_desc = """ title = '%d+ Hilarious %s - Perfect for Groans & Laughs' % (len(js), t['name'])
desc = 'Looking for %s? %s Guaranteed to make anyone roll their eyes. Read %d completely clean jokes now.' % (t['name'].lower(), t['intro'], len(js))
suffix = ''
if len(desc + suffix) <= 155:
desc = desc + suffix
elif len(desc) > 155:
desc = desc[:152] + '...'"""
content = content.replace(old_title_desc, new_title_desc)
# 2. Add long-tail topics
new_topics = """ {"slug": "eyes", "name": "Dad Jokes About Eyes", "emoji": "\\uD83D\\uDC40",
"intro": "Eye see what you did there! These dad jokes about eyes are a sight for sore... well, you know.",
"keywords": r"\\\\b(eyes?|see|sight|glasses|vision)\\\\b"},
{"slug": "funny-dad-jokes-for-middle-schoolers", "name": "Dad Jokes for Middle Schoolers", "emoji": "\\uD83C\\uDFEB",
"intro": "Middle school is tough, but these jokes are tougher to ignore. 100% clean dad jokes to embarrass any middle schooler.",
"keywords": r"\\\\b(school|middle|teen|tween|student|class|homework|math|teacher|principal|locker|backpack)\\\\b"},
{"slug": "dad-jokes-about-nurses", "name": "Dad Jokes About Nurses", "emoji": "\\uD83D\\uDC69\\u200D\\u265E\\uFE0F",
"intro": "Nurse your sense of humor back to health with these clinical dad jokes. Side effects may include eye-rolling and spontaneous groans.",
"keywords": r"\\\\b(nurse|nurses|nursing|doctor|hospital|medical|medicine|patient|sick|health)\\\\b"}
]"""
old_topics = """ {"slug": "eyes", "name": "Dad Jokes About Eyes", "emoji": "\\uD83D\\uDC40",
"intro": "Eye see what you did there! These dad jokes about eyes are a sight for sore... well, you know.",
"keywords": r"\\\\b(eyes?|see|sight|glasses|vision)\\\\b"}
]"""
content = content.replace(old_topics, new_topics)
# 3. Add link trap loop on joke page
new_joke_links = """ <p class="center-link"><a class="btn" style="background-color: var(--brand2); color: #000;" href="/joke/{j['id'] + 1}/">Next Joke &rarr</a></p>
<p class="center-link"><a class="btn btn-ghost" href="/category/{j['cat']}/">More {esc(cat['name'])} &rarr;</a></p>"""
old_joke_links = """ <p class="center-link"><a class="btn" href="/category/{j['cat']}/">More {esc(cat['name'])} &rarr;</a></p>"""
content = content.replace(old_joke_links, new_joke_links)
with open('build.py', 'w') as f:
f.write(content)