Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

output every blog post as json

  • #4173
    Avatar photo[anonymous]

    Hi,

    I’m trying to build a mongodb search engine of every post in a blog (roughly 800 posts). Is there a relatively easy way to do this?  I’ve tried re-using some of the code which generates the feed.json file. I’ve also started down the path to use this templates, https://github.com/GetPublii/Publii/blob/8db728c848a7c2e8c15770d1fd96e7e38304a8dd/app/default-files/theme-files/feed-json.hbs, to pull from the sqlite db to generate the json per post.

    Is there some easier way to accomplish the goal?

    Thanks!

    #4180
    Avatar photo[anonymous]

    Hi,

    My idea, but please remember – it is only idea, which wasn’t tested –

    1) create a custom post template
    2) create a new hidden post and assign this new custom post template

    3) then render the JSON in the template using @website.contentStructure global variable: https://getpublii.com/dev/website-global-variable/ and use feed-json.hbs as an inspiration

    Of course you will get JSON inside HTML file, but as I suppose – you just need raw JSON data.

    #4193
    Avatar photo[anonymous]

    Thanks!

    For now, I just use the JSON extension to sqlite3 and this query gets the core data into a usable format:

    SELECT title, authors.name, text, created_at FROM posts JOIN authors;

    Not quite as cool as running js templates, but gets the job done.