8000 Create sitemaps.yml by glenn-jocher Β· Pull Request #17 Β· ultralytics/docs Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create sitemaps.yml #17

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

Merged
merged 13 commits into from
Nov 17, 2023
52 changes: 52 additions & 0 deletions .github/workflows/sitemaps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Ultralytics YOLO πŸš€, AGPL-3.0 license
# Submit Sitemaps to Google Search Console after Pages Deployment

name: Submit Sitemaps

on:
workflow_dispatch:
workflow_run:
workflows: ["pages-build-deployment"]
types:
- completed

jobs:
submit-sitemaps:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}

steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install google-api-python-client oauth2client

- name: Run Submit Sitemap Script
env:
CREDENTIALS_JSON: ${{ secrets.GOOGLE_SEARCH_CONSOLE_API_JSON }}
shell: python
run: |
import os
import json
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
def submit_sitemap(site_url, sitemap_url, credentials_json):
credentials = ServiceAccountCredentials.from_json_keyfile_dict(json.loads(credentials_json), ['https://www.googleapis.com/auth/webmasters'])
webmasters_service = build('webmasters', 'v3', credentials=credentials)
webmasters_service.sitemaps().submit(siteUrl=site_url, feedpath=sitemap_url).execute()
print(f'Submitted {sitemap_url}')
credentials_json = os.environ['CREDENTIALS_JSON']
# Submit sitemap for the main site
submit_sitemap('https://docs.ultralytics.com', 'https://docs.ultralytics.com/sitemap.xml', credentials_json)
# Submit sitemaps for each language
languages = ['zh', 'ko', 'ja', 'ru', 'de', 'fr', 'es', 'pt']
for lang in languages:
submit_sitemap(f'https://docs.ultralytics.com/', f'https://docs.ultralytics.com/{lang}/sitemap.xml', credentials_json)
0