Most people get this kind of logic from their CMS or publishing platform. Jekyll, hugo, wordpress, 11ty, etc. all have various external state stores (yaml files, JSON, CSV, calling a graphql API, etc.) that you can query and interpolate or insert data into your document using a bevy of different template languages. Check out Gatsby or even Next.js for something that's really pushing the boundaries of static + data-driven content.