Weighted K–stability and coercivity with applications to extremal Kähler and Sasaki metrics