Home

Awesome

<h1 align="center">IndexNow Action</h1> <p align="center"> <a href="https://github.com/bojieyang/indexnow-action/actions/workflows/basic-validation.yml"> <img alt="Basic validation" src="https://github.com/bojieyang/indexnow-action/actions/workflows/basic-validation.yml/badge.svg"> </a> <img alt="GitHub Workflow Status (with branch)" src="https://img.shields.io/github/actions/workflow/status/bojieyang/indexnow-action/test.yml?branch=main"> <img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/bojieyang/indexnow-action"> <img alt="GitHub" src="https://img.shields.io/github/license/bojieyang/indexnow-action"> </p> <p align="center"> A GitHub Action that automatically submits URLs to participating search engines through the IndexNow protocol. </p> <p align="center"> <a href="README.zh.md">中文版本</a> </p>

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

Supported sitemap formats

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