Support IndexNox
This commit is contained in:
parent
6bd0df1f34
commit
9b4bb6c9f1
5 changed files with 53 additions and 4 deletions
25
base/wagtail_hooks.py
Normal file
25
base/wagtail_hooks.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from django.conf import settings
|
||||
from wagtail import hooks
|
||||
from wagtail.models import Page
|
||||
from urllib.parse import urlparse
|
||||
from base.indexnow import get_key
|
||||
import requests
|
||||
|
||||
|
||||
@hooks.register('after_publish_page')
|
||||
def after_publish_page(request, page):
|
||||
page_url = page.full_url
|
||||
# avoid if the host is localhost (development)
|
||||
print("preparing to notify")
|
||||
if urlparse(page_url).hostname == "localhost":
|
||||
print("not notifying indexnow for localhost" + get_key() + ", page url: " + page_url)
|
||||
return
|
||||
session = requests.Session()
|
||||
session.post(
|
||||
"https://api.indexnow.org/indexnow",
|
||||
json={
|
||||
"host": urlparse(page_url).hostname,
|
||||
"urlList": [page_url],
|
||||
"key": get_key(),
|
||||
},
|
||||
).raise_for_status()
|
Loading…
Add table
Add a link
Reference in a new issue