nuepress icon indicating copy to clipboard operation
nuepress copied to clipboard

Feature - Static site - Cannot update content from API

Open bovas85 opened this issue 8 years ago • 17 comments

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

bovas85 avatar Jan 08 '18 12:01 bovas85

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?

krestaino avatar Jan 08 '18 17:01 krestaino

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

bovas85 avatar Jan 08 '18 19:01 bovas85

PR's are more than welcome!

krestaino avatar Jan 16 '18 03:01 krestaino

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?

krestaino avatar Jan 17 '18 00:01 krestaino

Here's a proof of concept:

https://github.com/krestaino/nuepress/commit/8fb4ac960202929886738f4d769f5b046dcf2ea2

krestaino avatar Jan 17 '18 00:01 krestaino

Interesting, although that's limited to the pages api. I wonder if it would be too spammy in terms of requests every 5 seconds

bovas85 avatar Jan 17 '18 21:01 bovas85

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?

krestaino avatar Jan 19 '18 20:01 krestaino

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

bovas85 avatar Jan 19 '18 20:01 bovas85

Ohhh, do you mean when building the app using nuxt generate?

krestaino avatar Jan 19 '18 21:01 krestaino

I don't mind the spamming, but maybe you should have to add an ?refresh to the url to trigger it?

yashha avatar Jan 19 '18 21:01 yashha

Yes, when running nuxt generate (static site) this will come in handy.

bovas85 avatar Jan 20 '18 10:01 bovas85

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)

bovas85 avatar Feb 13 '18 16:02 bovas85

Have you tried reloading a page? It won't show up in a static site as it's missing the dynamic route.

bovas85 avatar Mar 08 '18 11:03 bovas85

@bovas85 did you solve the problem?

jakubm95 avatar Jan 30 '19 10:01 jakubm95

I'm using my nuxt-headless boilerplate which works fine on created https://github.com/bovas85/nuxt-headless

bovas85 avatar Jan 30 '19 10:01 bovas85

@bovas85 Thanks I will test it today

jakubm95 avatar Jan 30 '19 10:01 jakubm95

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

dejangeorgiev avatar Apr 11 '20 13:04 dejangeorgiev