Nanomechanics of two-dimensional materials: From tuning phonons to probing excitons