Skip to content

Automatically submits URLs to participating search engines through the IndexNow protocol.

License

Notifications You must be signed in to change notification settings

bojieyang/indexnow-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

IndexNow Action

Basic validation GitHub Workflow Status (with branch) GitHub release (latest SemVer) GitHub

A GitHub Action that automatically submits URLs to participating search engines through the IndexNow protocol.

中文版本

Usage

Prerequisites

The key file has been obtained from IndexNow and added to your website.

If you don't know how to get the key file, see IndexNow Document.

Tip

If your website is stored in a public repository (such as GitHub Pages), saving the Key file directly in the repository will reveal the content and location of this file, which may be a potential security risk. If you want to avoid this, use a solution that dynamically generates key files at deployment time. Please refer to Generate IndexNow Key file during deployment section.

Basic

steps:
  - uses: bojieyang/indexnow-action@v2 # v2 is the latest major version following the action-versioning.
    with:
    # The location of your sitemap must start with http(s). 
    # Currently, XML Sitemap, Sitemap index, RSS and Atom formats are supported.
      sitemap-location: 'https://example.com/sitemap.xml' 
      key: ${{ secrets.INDEXNOW_KEY }} # The key you get from IndexNow.

Examples

A complete example used in my blog shows below:

name: 'IndexNow'
on:
  schedule:
    # Set the schedule time
    - cron: '0 2 * * *'

jobs:
  check-and-submit:
    runs-on: ubuntu-latest
    steps:
      - name: indexnow-action
        uses: bojieyang/indexnow-action@v2
        with:
          sitemap-location: 'https://bojieyang.github.io/sitemap.xml'
          key: ${{ secrets.INDEXNOW_KEY }}

View code from here.

Inputs

  • sitemap-location required. The location of sitemap file in your website. Must start with https or http(e.g., https://example.com/sitemap.xml).

  • key required. The IndexNow key that you get from search engines.

    Note DO NOT stored as plaintext in the workflow file. Use GitHub Secrets instead. More about GitHub Secrets, see Encrypted Secrets.

  • key-location optional. Location of the IndexNow key file that you customed. If not set, it will assume that there is a file named {your-indexnow-key}.txt in the root directory of the website(e.g., https://example.com/{your-indexnow-key}.txt).

    Note DO NOT stored as plaintext in the workflow file. Use GitHub Secrets instead. More about GitHub Secrets, see Encrypted Secrets.

  • since optional. URLs with lastmod fields in sitemap files within the last {since} {since-unit} will be submitted. The default value is 1.

  • since-unit optional. The unit of since. Available units are minute, hour, day, week, month and year. The default value is day.

  • endpoint optional. The endpoint of a special search engine. Available values are api.indexnow.org, www.bing.com, search.seznam.cz and yandex.com. For more details, see: IndexNow FAQ. The default value is www.bing.com.

  • limit optional. The upper limit for submitting URLs. The default value is 100.

  • timeout optional. The timeout both fetch sitemap and submit to the search engine in milliseconds. The default value is 10000 (10 seconds).

  • failure-strategy optional. Define the strategy when submit failed. Available strategies are ignore and error. For ignore, will outputting an notice only. For error, outputting an error message also sets the status of action to fail. The default value is ignore.

Supported sitemap formats

  • XML Sitemap
  • Sitemap Index
  • RSS 2.0
  • Atom 1.0

Generate IndexNow Key file during deployment

Dynamically generating the key file during deployment can avoid the problem of leakage caused by storing the key file in a public repository. Different platforms have their own solutions for dynamically generating files during the deployment process. Here we take GitHub Pages as an example to introduce the corresponding solution.

The specific steps of deploying the plan are as follows:

  1. Store the contents of IndexNow’s key through GitHub Secrets.
  2. Deploy the website through GitHub Action.
  3. Add the following content to the deployment configuration corresponding to Action:
 jobs:
   build:
     steps: 
      ### ... omit other steps
      - name: Setup IndexNow 
      # Generate files dynamically to prevent them from being leaked in public repositories.
      # This example will put the file in the root directory of the site.You may change the location by yourself.
        run: echo ${{ secrets.INDEXNOW_KEY }} > ${{ secrets.INDEXNOW_KEY }}.txt
      ### ... omit other steps

For complete deployment files, see here

About Versions

The v2 is the current maintenance version and is based on Node.js v20. It is recommended to use the V2 version whenever possible.

The v1 version is a legacy version and is based on Node.js v16. This version can be used when the Node.js v20 version is not available.

Maintainers

@bojieyang

Acknowledgements

Use lquixada/cross-fetch to polyfill the WHATWG Fetch API.

Use @NaturalIntelligence/fast-xml-parser to parse XML.

Use @iamkun/dayjs to simplify date-related calculations.

Contributing

Contributions are welcome! Please create an issue and if applicable, a design before proceeding with code.

License

The scripts and documentation in this project are released under the MIT License