Feature - Static site - Cannot update content from API
As you know, asyncData only runs on node SSR, while it generates routes once on nuxt generate.
I feel this repo is fantastic as starting point, but it should contain an approach with mounted redoing the api call to the api to refresh the content if it's updated.
Any idea on how to handle this?
In my app I use mounted on each page to get new data in and updated the current datasets
Hey @bovas85,
If I'm understanding correctly, you're suggesting when content changes on the WordPress side, that content should automatically update the view within NuePress? Is that correct?
Yes indeed. If you have custom fields (also needed on this in my opinion, there's a nice wordpress API plugin that enables it in the json response, I'll pull request if you are up for it) it would pull new content straight into the site.
One of the sites I've done (https://cambridge-epigenetix.com/) currently does this, but your approach with Vuex is much cleaner so I'd like to contribute and expand this
PR's are more than welcome!
I've been messing around with this, what do you think?
https://gfycat.com/CommonPoisedAfricanrockpython
I have a setting the user can define to call the API every x seconds after it has been mounted. In the demo above, it's set to 5 seconds. Is this what you were looking for?
Here's a proof of concept:
https://github.com/krestaino/nuepress/commit/8fb4ac960202929886738f4d769f5b046dcf2ea2
Interesting, although that's limited to the pages api. I wonder if it would be too spammy in terms of requests every 5 seconds
Yeah I agree, 5 seconds is way too aggressive. Was just for demo purposes.
Is this what you meant by "redoing the api call to the api to refresh the content if it's updated"?
I think I'm just having a little difficulty understanding your request. Do you have a repo I could look at to further understand your request?
asyncData runs on nuxt generate only once while building the content. If you have let's say a title, that title will stay what it was during the build process.
Ideally we want to get the new title every time the content changes on WordPress. Ideally, also, we would need to retrieve advanced custom fields that are likely to be set in this kind of stack
Ohhh, do you mean when building the app using nuxt generate?
I don't mind the spamming, but maybe you should have to add an ?refresh to the url to trigger it?
Yes, when running nuxt generate (static site) this will come in handy.
Hmm I tried that code but it doesn't auto refresh for me. How odd.
Did you include anything else in the video to make it refresh? It's doing the network request but the page content remains the same (although I'm using advanced custom fields for that)
Have you tried reloading a page? It won't show up in a static site as it's missing the dynamic route.
@bovas85 did you solve the problem?
I'm using my nuxt-headless boilerplate which works fine on created https://github.com/bovas85/nuxt-headless
@bovas85 Thanks I will test it today
Hi @krestaino,
I just tested your script and works fine. Thank you very much. Are you considering to fix the generate in a near future?
Best, Dejan