-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can 11ty be instructed to repeatedly poll external API data while running in serve or watch mode? #1358
Comments
I don't know if this is helpful, but I have what amounts to a fake cron job through GitHub actions that sends a webhook to Netlify to rebuild my website every few hours to bring in new webmentions. It's still completely static, but it brings in new information several times a day. I don't know how frequent you could go before hitting the max of the free tier. |
@siakaramalegos I actually worked it out once. You can go much more than a couple times a day, and stay within the free tier.
@kkgthb I don't think Eleventy will help you here. Eleventy is simply a tool to generate static sites. Static sites don't generally change after they are generated. It's completely possible that you can write the website's JavaScript to accomplish what you want, but Eleventy won't help this. Also, |
@b3u I thought that If so, that "watching and responding to triggers" functionality is essentially what I'm asking if I can tap into for other changes, like API endpoint changes. (I do like your point that firing the trigger would potentially have to be done by a client-side API listener, though.) |
@kkgthb Just fyi, I checked the documentation and there is no command To answer your question, I don't know how to do that with 11ty. I imagine it could work, for example, if you customized the browserSync instance. However, I'm sure there are many tools, methods, and workflows which would do the job more easily. Again, that's not what it's built for. I can poke around. |
Thanks @b3u -- that was indeed a typo. I think I found another way to hack it. Just built out a proof-of-concept this morning. https://github.com/joerobot/sanity-11ty gave me some boilerplate for making Then borrowing from https://medium.com/@richyinbeta/eleventy-strapi-headless-cms-with-automatic-page-creating-and-updating-86942f10c19a, I set up an Express server on a different port with an endpoint Now I can force a refresh of Hopefully I will get this written up & put on the web sooner rather than later. |
@kkgthb that's great to hear. If this solution works, would you please close the issue? |
Sure thing, @b3u. One final note to self: if playing with "plugin" building ... https://github.com/sanity-io/gatsby-source-sanity/blob/main/src/util/getDocumentStream.ts & sanity-io/gatsby-source-sanity@ad7a57b#diff-58a996f947cfabb0eb6cd1fcb7e09e62 (its first commit) are examples of how the See also https://github.com/sanity-io/gatsby-source-sanity/blob/main/src/gatsby-node.ts and search in-page for the word "overlay" and "watch." It seems to make use of NPM's Because it does so within the context of a As @b3u mentioned, because 11ty URLs are just HTML files with no inherent "phone home to the server's running NodeJS code" JavaScript in their In theory, something like At some point, without triggering full rebuilds, with the amount of trickery to So we're back to full-rebuild magic links. You might as well just have 11ty templates inject a "refresh me from drafts" button into the corner of every page in development builds. Thankfully, 11ty seems to rebuild fast. This means that perhaps the only reasonable architectural optimization left, as far as I can see it, would be the possibility of using "plugins" as a way of slipping a little more "web server" functionality into Note to self: If running preview servers in One more note to self: since all the thing running in The builder's webhook system replaces the Express server and we're back to the "rebuild from scratch" architecture I took my inspiration from, only with less nonsense to maintain yourself. And if Sanity ever adds a sort of authorial "see my draft work" webhook (rather than just "publish" webhooks), you wouldn't even need a magic button in the preview UI anymore. They did say that better webhooks were on the way. |
I think #3085 and 11ty/eleventy-dev-server#70 should help with this, if anyone is reading and interested. |
I'm working on a proof of concept where I host an Eleventy project running in "--start" mode on Heroku (the only general-purpose long-running NodeJS host I have any familiarity with), intended to function as a "live preview" playground for content authors working in Sanity CMS (or any other API-based CMS).
I can see a few blog posts and starters for Contentful, DatoCMS, Sanity CMS, etc. but before I get too deep into the weeds, a question I can't quite find an answer to myself is:
I see that a server running 11ty in "--serve" mode will watch for changes to files in its local filesystem, but since a host like Heroku will restart the server every time I use Git to make a change to the files in its filesystem, that's not exactly useful.
That's what took me back to the idea of API-based CMSes.
Gatsby has a
gatsby-source-sanity
plugin that can be configured to frequently ping Sanity's "drafts" API options such aswatchMode
andoverlayDrafts
. To me, this implies that Gatsby SSG itself can be told to frequently poll an external site while running in develop mode.Is there a way to tell Eleventy to "frequently poll an external site while running in serve or watch mode?" I'm struggling to find documentation or tutorials.
Or is that just something that Eleventy can't do? (Don't want to waste my time to find this out the hard way!)
Thanks so much.
The text was updated successfully, but these errors were encountered: