How to Write Funnier Jokes Without Sounding Like Everyone Else

Back to Blog
Joke Writing
March 22, 2026
lalo morales
How to Write Funnier Jokes Without Sounding Like Everyone Else

How to Write Funnier Jokes Without Sounding Like Everyone Else

A lot of jokes do not bomb because the comic is untalented. They bomb because the joke could have been written by almost anybody.

That is the real trap of beginner and intermediate comedy writing. You find a topic that feels promising, you write a setup and a punchline, and technically it works. But it does not stick. It does not sound like you. It sounds like comedy-flavored filler.

If you want to write funnier jokes without sounding like everyone else, the goal is not to become weird for the sake of weird. The goal is to become specific.

The biggest reason jokes sound generic

Most weak jokes are built from shared observations with no personal angle.

Examples:

  • dating apps are weird
  • airports are stressful
  • parenting is hard
  • people drive crazy
  • customer service is awful

None of those topics are unusable. The problem is that millions of comics have touched them already. If you write from the topic alone, you usually land on the same obvious joke roads everybody else lands on.

The fix is to stop asking:

What is funny about this topic?

And start asking:

What is weird about my relationship to this topic?

That is where voice starts.

Specificity beats volume

A generic joke often uses broad labels. A sharper joke uses details that make the audience feel like they are looking at a real moment.

Compare these:

  • generic: “dating apps are depressing”
  • better: “dating apps make me feel like I am applying for a job where the recruiter wants beach photos and emotional availability”

The second one works better because it creates a clearer picture. It also hints at a point of view.

When you revise a joke, ask yourself:

  • what exact image can I use?
  • what exact phrase would I say in real life?
  • what specific behavior makes this funny?
  • what detail makes this mine instead of interchangeable?

Stop writing from the headline

A lot of weak jokes stay trapped at headline level.

For example:

  • “going to the gym is hard”
  • “family group chats are chaotic”
  • “everyone lies on social media”

Those are topics, not jokes.

To move from headline to material, dig into one of these:

1. Your emotional reaction

How did it make you feel?

Not “bad.” Be more exact.

  • embarrassed
  • suspicious
  • competitive
  • petty
  • weirdly proud
  • irrationally angry

2. The social truth

What are people pretending about this situation?

Comedy loves fake politeness, fake confidence, fake expertise, fake intimacy.

3. The hidden comparison

What else does this feel like?

Good comparisons create instant punch-up paths.

  • dating app = job interview
  • open mic sign-up = public self-harm spreadsheet
  • writing a new joke = trying to build furniture with one screw and self-hatred

Your voice is mostly your taste under pressure

A lot of comics talk about “finding your voice” like it is buried in a cave somewhere. In practice, voice is built from repeated choices.

Your voice shows up in:

  • what you notice
  • what annoys you
  • what you are willing to admit
  • how mean or gentle your punchlines are
  • whether you go absurd, dark, analytical, dumb, playful, or personal

You do not find voice by trying to sound special. You find it by writing enough truth that your patterns become obvious.

That means you should pay attention to your natural tendencies.

If every joke you write turns into:

  • overthinking social interactions
  • shame with confidence
  • fake authority
  • family dysfunction
  • self-delusion
  • accidental aggression

That is not a flaw. That is probably part of your lane.

A simple rewrite method for stale jokes

If you have a joke that feels “almost funny,” run this quick rewrite pass.

Pass 1: make it more specific

Replace broad words with real ones.

Pass 2: make it more personal

Add your actual behavior, flaw, reaction, or hypocrisy.

Pass 3: make the punch harder

Look for:

  • stronger contrast
  • a sharper image
  • a better comparison
  • a more embarrassing confession
  • a less safe ending

Pass 4: add one tag

Once the core joke works, write 3 to 5 possible tags. Most comics stop too early and leave extra laughs on the table.

Original does not mean impossible to understand

One mistake comics make after hearing “be original” is trying to become so random that the audience cannot follow them.

That is not voice. That is fog.

A joke can be clear and still feel original. The best jokes are usually easy to follow but hard to predict.

That is the sweet spot.

Use AI carefully without flattening your style

AI can help you write more, but it can also sand off your edges if you use it lazily.

The best use is not “write my joke for me.”

The best use is:

  • give me 10 sharper punchline directions
  • show me 5 comparisons for this premise
  • make this setup more specific
  • help me push this one step darker, dumber, or more absurd

That way, you stay in control of taste and voice.

If you want help doing exactly that, Comedeez can help you generate alternate punchlines, punch-ups, and new angles without starting from a blank page.

Final thought

If your jokes sound like everyone else, that does not mean you lack talent. It usually means you are still writing from topics instead of perspective.

The more specific you get, the funnier you can get.

The more honest you get, the more original you sound.

And the more you rewrite with intention, the less your material feels like borrowed comedy furniture.

Write the version only you would say. That is where the laughs start getting real. }, { slug: 'how-to-find-better-punchlines-when-your-joke-feels-almost-funny', title: 'How to Find Better Punchlines When Your Joke Feels Almost Funny', excerpt: 'A joke that feels almost funny is usually closer than you think. Here is how to diagnose weak punchlines and turn decent setups into stronger laughs.', category: 'Punchlines', coverTitle: 'Better Punchlines', coverSubtitle: 'for jokes that are almost funny', accent: '#38bdf8', content:# How to Find Better Punchlines When Your Joke Feels Almost Funny

There is a specific kind of frustration every comic knows.

You have a premise that feels good. The setup makes sense. The audience even leans in a little. Then the punchline lands and gets a reaction somewhere between polite air movement and emotional tax fraud.

That is the “almost funny” zone.

The good news is that an almost-funny joke is not dead. It is usually a clue. It means the setup is carrying some tension, but the payoff is not surprising, sharp, or committed enough.

Why punchlines miss

Most weak punchlines fail for one of five reasons:

1. They are too predictable

If the audience can guess the ending halfway through the setup, the laugh gets smaller.

2. They are too soft

The idea is there, but the wording lands like a suggestion instead of a punch.

3. They stop too early

A lot of comics hit the first decent ending instead of the strongest one.

4. They do not escalate the premise

The setup promises more tension than the punchline delivers.

5. They are true, but not funny enough

This one hurts. Something can be accurate and still need more comedy structure.

First, identify what kind of laugh the setup wants

Not every punchline needs the same engine.

Ask: what is the most natural laugh type here?

  • misdirection: the audience expects one thing, gets another
  • exaggeration: you push the truth past realism in a believable way
  • comparison: the situation feels like something else
  • confession: the funniest version is your own bad behavior
  • specific image: the laugh is in what people suddenly see

If you do not know the engine, you often write flat punchlines.

A practical test for weak punchlines

Take your setup and write three bad obvious punchlines on purpose.

Why? Because your current punchline may secretly be one of them.

If your real punchline sounds like the safe answer, that is useful information. It means you need a more interesting turn.

Three ways to strengthen a punchline fast

1. Replace summary with image

Weak punchline:

my doctor was not helpful

Stronger direction:

my doctor looked at my bloodwork like he was reading Yelp reviews about my organs

The second one gives the audience something to picture.

2. Replace mild truth with embarrassing truth

Weak:

I get nervous talking to attractive people

Stronger:

when I talk to attractive people, my personality clocks out and leaves a voicemail

Embarrassment creates stakes. Stakes create laughs.

3. Push one more beat

Sometimes the first punchline is only the doorway.

Example structure:

  • setup
  • first punchline
  • stronger tag
  • even stronger tag based on the same logic

A lot of material becomes stage-ready during the tag phase, not the first line.

Use contrast more aggressively

Punchlines usually improve when the gap gets bigger between expectation and reality.

Try contrast in these forms:

  • high status vs low status
  • serious tone vs dumb outcome
  • confidence vs incompetence
  • normal setting vs insane emotional reaction

That contrast creates impact.

Ask the useful revision questions

When a punchline is not quite there, ask:

  • what is the more brutal version of this?
  • what is the more specific version?
  • what is the version that makes me look worse?
  • what is the visual version instead of the explanatory version?
  • what word in this line is too weak?

Sometimes changing one noun or one verb is enough to wake up the joke.

Write punchline ladders

A punchline ladder is simple.

Take one setup and write:

  • 5 realistic endings
  • 5 absurd endings
  • 5 self-own endings
  • 5 comparison endings

You are not trying to nail it immediately. You are trying to force range.

Usually one category produces a version with more energy than the others.

Watch out for “writer funny” vs “audience funny”

A line can feel clever on paper and still die on stage.

If a punchline is too abstract, too wordy, or too pleased with itself, it may impress your notebook more than your audience.

A good punchline usually gets to the laugh quickly, clearly, and with confidence.

Let AI help widen the search, not finish the joke for you

This is where AI can actually be useful.

If your joke feels almost funny, you can use AI to ask for:

  • 10 sharper punchline options
  • 5 more visual comparisons
  • 5 more self-own versions
  • 5 tags that escalate the existing punchline

That does not replace your voice. It just helps you search faster.

Comedeez is especially useful here because you can use it to generate alternate punchline directions, compare tones, and test different joke endings without rewriting from scratch every time.

Final thought

An almost-funny joke is not a failure. It is a strong setup asking for a more committed ending.

Usually the answer is not “throw it away.”

Usually the answer is:

  • get more specific
  • get less safe
  • push one more beat
  • choose a stronger laugh engine

The setup already did part of the job. Now give it a punchline that deserves it. }, { slug: 'how-comedians-can-use-ai-without-losing-their-voice', title: 'How Comedians Can Use AI Without Losing Their Voice', excerpt: 'AI can speed up comedy writing, but it can also flatten your material if you use it lazily. Here is how comics can use AI as a writing partner instead of a replacement.', category: 'AI Comedy Tools', coverTitle: 'AI Without Losing Voice', coverSubtitle: 'how comedians can use ai the smart way', accent: '#a78bfa', content:# How Comedians Can Use AI Without Losing Their Voice

A lot of comedians have the same reaction to AI.

Part of them is curious.

Part of them is disgusted.

And part of them is thinking, “If this thing starts writing better tags than me, I am moving into landscaping.”

The truth is simpler than both the hype and the panic.

AI is not automatically good for comics. It is not automatically bad either. It is just a tool. And like most tools, it becomes helpful or harmful depending on how you use it.

If you use AI to replace your point of view, your material gets flatter.

If you use AI to expand your options while keeping your taste in charge, it can become a genuinely useful comedy-writing assistant.

The biggest mistake comics make with AI

The worst prompt in comedy is basically:

write me a funny joke about dating apps

That is how you get bland, generic, fake-comedy sludge.

Why? Because the model is pulling toward the average shape of a joke instead of your voice, your rhythm, and your angle.

Average comedy is usually dead on arrival.

What AI is actually good at for comics

AI is best when it helps with range, iteration, and speed.

Good uses:

  • alternate punchline directions
  • premise expansion
  • tag generation
  • comparison mining
  • reframing weak setups
  • organizing scattered joke notes
  • helping you find stronger wording faster

Bad uses:

  • replacing your point of view
  • writing your final act for you
  • copying a voice you did not earn
  • generating generic jokes and pretending they are stage-ready

Use AI like a writers room intern, not a headliner

That is the cleanest mental model.

AI should be the intern that throws out options. You are still the comic, editor, and judge.

That means your workflow should look more like this:

  1. bring in your actual premise
  2. include your voice or angle
  3. ask for variations, not finished truth
  4. keep only what actually sounds like you
  5. rewrite heavily before stage use

Start with your material, not blank prompts

If you want to protect your voice, start with something real.

For example:

Here is my premise: I panic on dating apps because they feel like job interviews for people who hate my resume. Give me 12 punchline directions in a sharper, more self-own tone.

That works much better than asking for “a funny joke about dating apps.”

The more of you that is in the input, the better the output gets.

Give AI a role, not vague freedom

Vague prompts create vague comedy.

Instead, assign jobs like:

  • make this setup more specific
  • write 10 tags that escalate the same logic
  • give me darker, dumber, and more absurd versions
  • show me 5 stronger comparisons
  • help me find a cleaner punchline wording

That keeps you directing instead of passively accepting whatever it spits out.

Keep your final filter ruthless

A line is not yours just because you pasted it into a document.

Before keeping anything AI-generated, ask:

  • would I actually say this on stage?
  • does this match my rhythm?
  • does this sound like my perspective or generic comedy?
  • is this sharper than what I already had?
  • does this create a real laugh or just a polite nod?

If the answer is no, cut it.

Do not let AI erase your rough edges

A lot of comedy voice lives in imperfection.

Your weird phrasing, your emotional bias, your overreaction, your pet obsessions, your level of pettiness, your personal blind spots — that is often the funny part.

AI naturally pulls toward cleaner, safer, more balanced language unless you guide it away from that.

But comedy is not always balanced. Comedy is often stronger when it is biased, heightened, and emotionally committed.

So if the AI output feels too polished, too neutral, or too “helpful,” that is not a sign it is better than you. That is a sign it is drifting away from the useful mess that makes a comic sound human.

One smart AI workflow for comedians

Try this:

Step 1: write the raw joke yourself

Even if it is messy.

Step 2: ask AI for angles, not answers

Have it widen the map.

Step 3: choose only the interesting branches

Not all branches deserve attention.

Step 4: rewrite the survivors in your own words

This is the part that keeps the voice alive.

Step 5: test on stage or out loud

If it does not sound natural in your mouth, it is not done.

AI is especially useful when you are stuck, not when you are lazy

That distinction matters.

If you are stuck between two endings, AI can help.

If you need 15 ways to phrase a comparison, AI can help.

If you need to turn a weak premise into possible directions, AI can help.

But if you are avoiding the real work of honesty, selection, and performance, AI will not save you. It will usually just give you a shinier version of avoiding the work.

A better way to use Comedeez

This is exactly where Comedeez should fit.

Not as a machine that “writes your stand-up for you.”

But as a tool that helps you:

  • punch up a premise
  • test different joke directions
  • generate sharper tags
  • compare versions of the same joke
  • write faster without defaulting to generic comedy

That is the sweet spot.

Final thought

AI should not replace your voice.

It should help you hear your voice faster, test it harder, and sharpen it more often.

If you keep your taste in charge, AI can be useful.

If you let AI become the taste, the jokes start sounding like they were written by a committee trapped in a LinkedIn post.

Use it as a comedy-writing assistant, not a substitute for perspective. That is how you stay funny and still get faster. }, { slug: 'the-best-ai-prompts-for-joke-writing-premises-and-punch-ups', title: 'The Best AI Prompts for Joke Writing, Premises, and Punch Ups', excerpt: 'Most comics get weak results from AI because they prompt too vaguely. These prompt patterns help you get stronger joke ideas, sharper punchlines, and better punch-ups.', category: 'AI Comedy Tools', coverTitle: 'Best AI Prompts', coverSubtitle: 'for joke writing, premises, and punch ups', accent: '#f59e0b', content:# The Best AI Prompts for Joke Writing, Premises, and Punch Ups

If you have ever used AI for comedy writing and gotten back something that sounded like a substitute teacher doing open mic, the problem was probably not just the model.

It was the prompt.

Most weak AI comedy output comes from weak instructions.

If you ask for “a funny joke about family” you usually get broad, bloodless material that sounds like it belongs on a mug nobody asked for.

But if you prompt with structure, tone, and purpose, AI can actually help you generate stronger comedy-writing options.

Here are the prompt types that tend to work best.

1. Premise expansion prompts

Use these when you have a small idea but need more angles.

Prompt pattern

I have this comedy premise: [insert premise]. Give me 12 angles I could explore. Break them into observational, personal, exaggerated, and self-own directions.

Example

I have this comedy premise: open mic sign-up lists feel more stressful than actual work meetings. Give me 12 angles I could explore. Break them into observational, personal, exaggerated, and self-own directions.

Why it works:

  • you provide the seed
  • AI widens the map
  • you do not force it to write a final joke too early

2. Punchline variation prompts

Use these when the setup is solid but the payoff is weak.

Prompt pattern

Here is my setup: [insert setup]. Give me 15 punchline options. Make 5 visual, 5 darker, and 5 more self-deprecating.

Why it works:

  • it forces variety
  • it helps you see tone options quickly
  • it avoids getting stuck on one safe ending

3. Tag generation prompts

A lot of comics stop after the first punchline. That leaves laughs behind.

Prompt pattern

Here is the joke: [insert setup + punchline]. Give me 10 tags that escalate the same logic without changing the original joke structure.

This is one of the best practical uses of AI for comedy.

4. Comparison mining prompts

Comparisons are one of the fastest ways to sharpen comedy writing.

Prompt pattern

My premise is [insert premise]. What are 15 unexpected comparisons this situation feels like? Make them grounded, visual, and stage-friendly.

Example

My premise is dating apps make me feel unemployable. What are 15 unexpected comparisons this situation feels like?

A good comparison can save an average joke.

5. Specificity prompts

If a joke sounds generic, make AI help you sharpen the nouns and details.

Prompt pattern

Rewrite this joke to be more specific without changing the core idea. Replace broad words with real images, clearer details, and stronger verbs.

This is useful because generic comedy often dies from vague language, not weak concepts.

6. Voice-preserving rewrite prompts

This is one of the most important ones.

Prompt pattern

Help me improve this joke without making it sound like generic AI comedy. Keep the tone [insert tone], the point of view [insert viewpoint], and the rhythm short and stage-friendly.

You are telling the model what not to destroy.

7. Character and persona prompts

These help if your joke needs stronger perspective.

Prompt pattern

Rewrite this premise as if it is coming from a comic who is [insert traits]. Do 5 versions, but keep them believable and performable.

Example traits:

  • insecure but overconfident
  • hyper-analytical and petty
  • fake spiritual and judgmental
  • exhausted parent who still thinks they are fun

This helps you explore voice lanes without fully abandoning your own.

8. Escalation prompts

If the joke feels too mild, make the AI push it.

Prompt pattern

Take this joke and escalate it in 8 steps, from realistic to absurd, while keeping the emotional logic intact.

That is an easy way to discover whether your joke wants a grounded ending or a bigger swing.

9. Setlist clustering prompts

This is underrated.

Prompt pattern

Here are 12 joke ideas. Group them into themes and show me which ones sound like they belong in the same chunk of a stand-up set.

That can help turn random notes into actual structure.

10. Brutal editor prompts

Sometimes you do not need more options. You need a better filter.

Prompt pattern

Read these 8 joke drafts and tell me which 3 have the strongest laugh potential, which 3 are generic, and which 2 should probably be cut. Be blunt.

This is useful when you have note fatigue and everything starts sounding equally good or equally terrible.

Prompt tips that make a big difference

Be concrete

Bad:

make it funnier

Better:

give me 10 sharper punchlines that are more visual and more embarrassing

Ask for categories

That forces useful spread.

Tell it what to keep

Tone, perspective, and rhythm matter.

Feed it your actual material

Blank prompts lead to blank-feeling comedy.

Use it to widen options, then decide like a comic

That is the whole game.

A few ready-to-use prompt templates

Here are quick copyable versions:

For premises

I have this premise: [idea]. Give me 12 directions I could take it as a stand-up joke. Make them specific and stage-friendly.

For punch-ups

Here is my joke draft: [joke]. Give me 10 sharper punchline alternatives that keep the same idea but hit harder.

For tags

Here is the joke: [joke]. Give me 8 tags that escalate the same logic.

For voice

Rewrite this joke to sound more like an insecure, overthinking comic who says things a little too honestly.

For specificity

Make this joke more specific and visual without making it longer.

Where Comedeez fits

If you are serious about using AI for joke writing, Comedeez should save you from blank-page prompting and generic outputs.

Instead of starting from scratch every time, use it to:

  • explore premise directions
  • punch up weak endings
  • generate tags
  • compare tones
  • keep your writing moving when you are stuck

That is where AI becomes genuinely useful instead of just technically impressive.

Final thought

The best AI prompt is not “be funny.”

The best AI prompt gives structure, tone, and purpose.

If you tell AI exactly what kind of help you want, it gets much better at being helpful.

And if you keep your taste in charge, you can use it to write faster without sounding more generic. }, { slug: 'how-to-turn-a-weak-premise-into-a-real-bit', title: 'How to Turn a Weak Premise Into a Real Bit', excerpt: 'Not every rough premise deserves to be thrown away. A lot of weak joke ideas can become strong bits if you know how to expand them the right way.', category: 'Bit Development', coverTitle: 'Turn a Weak Premise', coverSubtitle: 'into a real bit that actually works', accent: '#ef4444', content:# How to Turn a Weak Premise Into a Real Bit

Every comic has a graveyard of weak premises.

They usually look like this in a notes app:

  • dentists are creepy
  • self-checkout is annoying
  • my family texts like hostages
  • I hate networking
  • adulthood is just emails

At first glance, these feel too thin to matter. But a weak premise is not always a bad premise. Sometimes it is just an undeveloped premise.

That distinction matters.

A lot of real bits start as mediocre notes. The difference is what you do next.

First, stop expecting the premise to do all the work

A premise is just the seed.

A bit comes from expansion.

If your note is only one sentence and you are judging it like it should already feel stage-ready, you are skipping the actual comedy-writing process.

The job is not to stare at the note until it becomes brilliant.

The job is to interrogate it.

Five ways to turn a weak premise into something usable

1. Find the actual point of view

A weak premise is often missing a point of view.

For example:

self-checkout is annoying

That is not enough.

But these are stronger:

  • self-checkout treats me like I work part-time at a store I do not respect
  • self-checkout is the only job where I get judged by a machine and still bag my own humiliation
  • self-checkout makes me feel like a shoplifter during a software update

Same topic. Better angle.

2. Add stakes

Why does this matter to you?

Comedy gets stronger when the premise creates tension, embarrassment, ego, insecurity, or conflict.

Ask:

  • what do I want in this situation?
  • what am I afraid of?
  • what makes this irrationally personal?

Weak premise:

my family texts too much

Bit potential:

my family group chat acts like every Tuesday is a hostage negotiation and my mom keeps sending blurry evidence

Now there is texture.

3. Build example chains

Many bits become real once you stop explaining and start listing examples.

Example chains work because they create momentum.

If your premise is:

adulthood is just emails

You can build it out with examples:

  • every email sounds urgent but means nothing
  • every email ends with “circling back” like a threat from a polite cult
  • adulthood is opening an inbox and discovering nine people professionally checking if you are still alive

That is where the bit starts to breathe.

4. Add act-outs or imagined behavior

Some premises are too small until you act them out.

If the funny part is how someone says something, walks, lies, freezes, or pretends, write that behavior into the bit.

Act-outs turn explanation into performance.

Even on paper, that gives the material more shape.

5. Explore the hidden metaphor

A lot of strong bits come from one useful comparison.

Ask:

  • what does this situation feel like?
  • what is the hidden version of this?

Examples:

  • networking = adult speed dating for fake confidence
  • email follow-ups = corporate haunting
  • dentist small talk = hostage empathy

A good metaphor can unlock the whole bit.

Use the “bit expansion” checklist

When a premise feels weak, run it through this:

  • what is my actual opinion?
  • what emotion powers it?
  • what examples prove it?
  • what is the most embarrassing version of my role in it?
  • what comparison sharpens it?
  • what act-out makes it more performable?
  • what tag could extend it?

If you can answer most of those, you probably have more than a premise. You have a path.

Not every weak premise should survive

This matters too.

Some ideas are weak because they are just weak.

If a premise stays flat after multiple expansion attempts, it may not be worth your energy right now.

But do not kill it too early.

A lot of material sounds dead until the second or third angle reveals what the joke is really about.

AI can help you widen the premise, not fake the bit

This is another place where AI can be genuinely useful.

You can feed it a weak premise and ask for:

  • 12 possible angles
  • 10 comparisons
  • 8 example-chain directions
  • 5 self-own versions
  • 5 act-out ideas

That does not make the bit finished. But it helps you find the version worth writing.

Comedeez can help here by taking a rough premise and opening up punch-up paths, tags, comparisons, and alternate joke directions much faster than staring at a dead note for 40 minutes.

A real mindset shift

Do not ask:

is this premise good enough?

Ask:

what would make this premise worth performing?

That question leads to action.

Final thought

A weak premise is not the end of the joke.

It is the beginning of a decision.

If you add point of view, stakes, examples, comparison, and a little performance logic, a flimsy note can become a real bit.

That is comedy writing in practice.

Not waiting for perfect ideas. Building better ones.` } ];

async function main() { const conn = await mysql.createConnection(DATABASE_URL); try { await conn.beginTransaction();

for (const post of posts) {
  const imageId = `blog_${crypto.randomBytes(5).toString('hex')}`;
  const imageUri = svgDataUri({ title: post.coverTitle, subtitle: post.coverSubtitle, accent: post.accent });
  const postId = crypto.randomUUID();
  const coverUrl = `/api/image/${imageId}`;

  const [existing] = await conn.execute('SELECT id, cover_image FROM blog_posts WHERE slug = ?', [post.slug]);
  const rows = existing;

  if (rows.length) {
    await conn.execute(
      'UPDATE blog_posts SET title = ?, excerpt = ?, content = ?, category = ?, published = 1, updated_at = NOW() WHERE slug = ?',
      [post.title, post.excerpt, post.content, post.category, post.slug]
    );
  } else {
    await conn.execute(
      'INSERT INTO user_uploads (id, user_id, type, data_uri, created_at) VALUES (?, ?, ?, ?, NOW())',
      [imageId, AUTHOR_ID, 'blog-image', imageUri]
    );
    await conn.execute(
      `INSERT INTO blog_posts (id, title, slug, excerpt, content, cover_image, category, author_id, published, created_at, updated_at)
       VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, NOW(), NOW())`,
      [postId, post.title, post.slug, post.excerpt, post.content, coverUrl, post.category, AUTHOR_ID]
    );
  }

  console.log(`${rows.length ? 'updated' : 'created'} ${post.slug}`);
}

await conn.commit();

} catch (err) { await conn.rollback(); throw err; } finally { await conn.end(); } }

main().catch(err => { console.error(err); process.exit(1); });

Enjoyed this article?

Join Comedeez to start writing your own jokes and get access to our AI tools.

Sign Up Free