We present accurate optical spectra of semiconductors and insulators within a pure Kohn-Sham time-dependent density-functional approach. In particular, we show that the onset of the absorption is well reproduced when comparing to experiment. No empirical information nor a theory beyond Kohn-Sham density-functional theory, such as $GW$, is invoked to correct the Kohn-Sham gap. Our approach relies on the link between the exchange-correlation kernel of time-dependent density functional theory and the derivative discontinuity of ground-state density-functional theory. We show explicitly how to relate these two quantities. We illustrate the accuracy and simplicity of our approach by applying it to various semiconductors (Si, GaP, GaAs) and wide-gap insulators (C, LiF, Ar).