add IndexNow script
This commit is contained in:
parent
19f8de4fab
commit
79f9218c34
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
/indexnow-key.txt
|
||||||
/lock
|
/lock
|
||||||
/nginx-tmp/
|
/nginx-tmp/
|
||||||
/node_modules/
|
/node_modules/
|
||||||
|
35
indexnow
Executable file
35
indexnow
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import validators
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
urls = sys.argv[1:]
|
||||||
|
else:
|
||||||
|
urls = sys.stdin.read().splitlines()
|
||||||
|
|
||||||
|
for url in urls:
|
||||||
|
if not validators.url(url):
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
if not urls:
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
host = "grapheneos.org"
|
||||||
|
api_url = "https://api.indexnow.org/indexnow"
|
||||||
|
|
||||||
|
with open("indexnow-key.txt") as keyfile:
|
||||||
|
key = keyfile.read().strip()
|
||||||
|
|
||||||
|
def submit(urls):
|
||||||
|
data = {
|
||||||
|
"host": host,
|
||||||
|
"key": key,
|
||||||
|
"urlList": urls
|
||||||
|
}
|
||||||
|
r = requests.post(api_url, json=data)
|
||||||
|
print(r.status_code)
|
||||||
|
|
||||||
|
submit(urls)
|
@ -92,5 +92,7 @@ for file in static-tmp/**/*.@(atom|xml); do
|
|||||||
xmllint --noblanks "$file" --output "$file"
|
xmllint --noblanks "$file" --output "$file"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[[ -f indexnow-key.txt ]] && index_now_key="$(cat indexnow-key.txt)" && echo "$index_now_key" > "static-tmp/$index_now_key.txt"
|
||||||
|
|
||||||
find static-tmp -regex '.+\.\(atom\|css\|html\|ico\|js\|json\|mjs\|pdf\|svg\|txt\|webmanifest\|xml\)' |
|
find static-tmp -regex '.+\.\(atom\|css\|html\|ico\|js\|json\|mjs\|pdf\|svg\|txt\|webmanifest\|xml\)' |
|
||||||
parallel -q ::: brotli zopfli :::: -
|
parallel -q ::: brotli zopfli :::: -
|
||||||
|
Loading…
x
Reference in New Issue
Block a user