Efficient variational contraction of two-dimensional tensor networks with a non-trivial unit cell