Referencing a subpage's page and section titles in a table

I’m trying to accomplish a fairly simple task here. I have a few pages and nested subpages within them. There are 3 levels in total. Like Section > Page > Subpage as shown in the image below.


I want to create a table which has them as columns, and whenever I reference a Subpage using the “@” option, I would like a formula to be added to the Page and Section columns which fetches them automatically based on the hierarchy of the doc.

I’m not sure if there’s a formula for this already, I tried finding it but couldn’t.

I think you might have realized, what I’m trying to do is create a Master Table of Contents for my doc. Creating the columns this way and then grouping them according to Section and Page columns would be a great way to visualize the doc and also filter the table, vote on subpages using buttons etc. which is not possible in the left sidebar.