The simplest approach is to use a hosts file: https://someonewhocares.org/hosts/
(1) Install "1Blocker X" -- not free but it's cheap. (2) It has a huge number of rules and protects your Safari pretty damn good. (3) You can disable the existing rules if you so choose. (4) You can add new ones based on URL regexes or CSS rules.
I am still using it actively both on my iPhone and iPad, one of the best investment in apps I ever did.
It seems to only impact during NIC changes, but I VPN and was moving my computer enough that it was causing me issue.
I'd rather have a separate service to run it.