Notify Google to Update Sitemap Using Netlify Functions
Currently, this site is hosted on Netlify. I am pretty satisfied and don’t plan to move anytime soon. I also submitted my sitemap to Google for it to index. But the update frequency seems not very high.
Fortunately, Google provides an endpoint for you to notify it. Send a GET
request to http://www.google.com/ping?sitemap=${siteMapUrl}
and you are done.
But do we have to use curl
every time we deploy to tell Google it’s time to fetch our sitemap? Well, life is short, don’t waste time on things like that.
Let functions work for you
Netlify Functions, which leverages Amazon API Gateway
and AWS Lambda
underneath, can be triggered at different stages of deployment.
Pricing
Free tier provides 125,000 times invocations or 100 hours of execution time. That’s way more than we need for this purpose.
Settings
First, we need to specify the location of functions in our repository.
netlify.toml
|
|
The function
For available triggers, check the document here. In this post, we only need deploy-succeeded
.
First, create a functions
folder under repository root to match the functions
settings in netlify.toml
above.
Then, create a deploy-succeeded.js
under functions
folder:
|
|
Check deployment
At deploy log, you will notice a few lines like:
|
|
Finally, you can go to Functions
page to see the functions you deployed and their logs.
|
|
In the meantime, you will likely receive an email to notify you that you’ve started using Netlify Functions.
You can also go to Functions
under Site settings
to see your usage.