Grothendieck–Lefschetz theorem with base locus