DocumentationAPI References

Hawk.js API Documentation

The Hawk.js API offers user-friendly methods for sitemap generation, search engine submission, and indexing automation. This page details the public API methods and their usage.


Getting Started

To use the Hawk.js API, import the Hawk class into your project:

import { Hawk } from "hawkjs";
 
const hawk = new Hawk();

Public API Methods

1. hawk(strategy, lookupPatterns, ignorePatterns, prettify)

This is the main method to execute sitemap generation and submission based on a specified strategy.

Parameters

ParameterTypeDefaultDescription
strategystring(Required)The strategy to employ (IndexNow, GWebmaster, GWebmaster2, or GIndex).
lookupPatternsstring[]Configured lookup patternsArray of file patterns to include in the sitemap.
ignorePatternsstring[]Configured ignore patternsArray of file patterns to exclude from the sitemap.
prettifybooleanfalseWhether to prettify the generated sitemap.xml for better readability.

Returns

  • Promise<boolean>: Resolves to true if the strategy completes successfully, otherwise false.

Example Usage

await hawk.hawk("IndexNow", ["src/**/*.html"], ["node_modules/**"], true);

2. utils.makeSitemap(lookupPatterns, ignorePatterns, prettify, upload)

Generates a sitemap.xml based on the provided patterns.

Parameters

ParameterTypeDefaultDescription
lookupPatternsstring[]Configured lookup patternsArray of file patterns to include in the sitemap.
ignorePatternsstring[]Configured ignore patternsArray of file patterns to exclude from the sitemap.
prettifybooleanfalseWhether to prettify the sitemap.xml.
uploadbooleantrueWhether to upload the generated sitemap to the configured FTP server.

Returns

  • Promise<string>: A status message indicating the success or failure of the sitemap generation process.

Example Usage

const sitemapStatus = await hawk.utils.makeSitemap(
  ["src/**/*.html"],
  ["node_modules/**"],
  true,
  true
);
console.log(sitemapStatus);

3. utils.makeRobot()

Creates a robots.txt file to guide search engine crawlers.

Returns

  • string: A status message indicating the success or failure of the robots.txt creation.

Example Usage

const robotTxtStatus = hawk.utils.makeRobot();
console.log(robotTxtStatus);

4. utils.getLastRunTimeStamp()

Retrieves the timestamp of the last successful run of Hawk.js. This is used to determine which files have changed since the last run.

Returns

  • number: The Unix timestamp of the last run.

Example Usage

const lastRunTimeStamp = hawk.utils.getLastRunTimeStamp();
console.log("Last Run Timestamp:", lastRunTimeStamp);

5. utils.getUpdatedRoutesPath(lastRunTimeStamp, lookupPatterns, ignorePatterns)

Finds and returns the list of updated file paths based on the last run timestamp.

Parameters

ParameterTypeDescription
lastRunTimeStampnumberThe Unix timestamp of the last run.
lookupPatternsstring[]Array of file patterns to include when looking for updated routes.
ignorePatternsstring[]Array of file patterns to exclude when looking for updated routes.

Returns

  • string[]: An array of updated file paths.

Example Usage

const updatedRoutes = hawk.utils.getUpdatedRoutesPath(
  lastRunTimeStamp,
  ["src/**/*.html"],
  ["node_modules/**"]
);
console.log("Updated Routes:", updatedRoutes);

Configuration Options

The Hawk instance automatically loads configurations defined in the hawk.config.js file. These configurations are accessed via the configurations property.

Example Configuration (hawk.config.js)

module.exports = {
  lookupPatterns: ["src/**/*.html"],
  ignorePattern: ["node_modules/**"],
  ftpCredentials: {
    hostname: "ftp.example.com",
    username: "yourUsername",
    password: "yourPassword",
  },
  googleServiceAccount: "./service-account.json",
};

Accessing Configuration

You can access the loaded configuration via the configurations property:

console.log(hawk.configurations.lookupPatterns);

Supported Strategies

Refer to the CLI and strategy-specific documentation for details on each supported strategy:


Keywords:

  • Hawk.js API
  • sitemap generation
  • indexing automation
  • search engine submission
  • API methods
  • IndexNow
  • Google Webmaster
  • GWebMaster
  • GIndex
  • API configuration
  • robots.txt
  • FTP upload