Sri Lanka suffered an early collapse on day one of their second Test against Australia but steadied the ship late as Kusal Mendis kept the hosts on track.