npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eleventy-plugin-robotstxt

v0.0.4

Published

An Eleventy plugin to generate a robots.txt file for your static site

Downloads

40

Readme

eleventy-plugin-robotstxt

[!NOTE] This plugin is experimental and is only compatible with Eleventy versions >= 3.0.0-alpha.6.

Automatically generate a robots.txt file for your Eleventy site using front matter.

Getting Started

Install the plugin in your project using your preferred package manager:

npm install --save-dev eleventy-plugin-robotstxt

And update your Eleventy config to import and use the plugin:

const EleventyPluginRobotsTxt = require("eleventy-plugin-robotstxt");

module.exports = (eleventyConfig) => {
  /** @type {import("eleventy-plugin-robotstxt/typedefs.js").EleventyPluginRobotsTxtOptions} */
  const eleventyPluginRobotsTxtOptions = {};
  eleventyConfig.addPlugin(
    EleventyPluginRobotsTxt,
    eleventyPluginRobotsTxtOptions,
  );
};

See the examples for how you might configure the plugin for different use cases.

API

The following plugin options are available for use in your .eleventy.js configuration:

| Option | Type | Description | Example | | ---------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------- | | sitemapURL | string \| undefined | (Optional) The absolute location of a sitemap for this site. The sitemap URL must be a fully-qualified URL; Google doesn't assume or check http/https/www.non-www alternates. Sitemaps are a good way to indicate which content Google should crawl, as opposed to which content it can or cannot crawl. See also: Google Search Central - How to write robots.txt rules. | https://www.example.com/sitemap.xml | | rules | Map<string \| string[], ({ allow: string } \| { disallow: string })[]> \| undefined | (Optional) A map of robots.txt rules, grouped by user agent. Each key is an array of user agents in the group; the value is an array of allowed or disallowed paths.| See examples. | | shouldBlockAIRobots | string \| undefined | (Optional) Whether to soft-block a list of known AI robots (see the ai-robots GitHub repository for context). | true | | frontMatterOverrides | Record<string, unknown> \| undefined | Front matter overrides to apply to the robots.txt template. By default, the plugin automatically applies eleventyExcludeFromCollections: true and permalink: /robots.txt, so you do not need to set these yourself. | { "frontMatterKey": "value" } |

Examples

The following examples are direct translations of Google's guide on how to write and submit a robots.txt file.

Disallow crawling of the entire site

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([["*", [{ disallow: "/" }]]]),
};

Output:

User-agent: *
Disallow: /

Disallow crawling of a directory and its contents

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([
    [
      "*",
      [
        { disallow: "/calendar/" },
        { disallow: "/junk/" },
        { disallow: "/books/fiction/contemporary/" },
      ],
    ],
  ]),
};

Output:

User-agent: *
Disallow: /calendar/
Disallow: /junk/
Disallow: /books/fiction/contemporary/

Allow access to a single crawler

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([
    ["Googlebot-news", [{ allow: "/" }]],
    ["*", [{ disallow: "/" }]],
  ]),
};

Output:

User-agent: Googlebot-news
Allow: /

User-agent: *
Disallow: /

Allow access to all but a single crawler

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([
    ["Unnecessarybot", [{ disallow: "/" }]],
    ["*", [{ allow: "/" }]],
  ]),
};

Output:

User-agent: Unnecessarybot
Disallow: /

User-agent: *
Allow: /

Disallow crawling of a single web page

For example, disallow the useless_file.html page located at https://example.com/useless_file.html, and other_useless_file.html in the junk directory.

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([
    [
      "*",
      [
        { disallow: "/useless_file.html" },
        { disallow: "/junk/other_useless_file.html" },
      ],
    ],
  ]),
};

Output:

User-agent: *
Disallow: /useless_file.html
Disallow: /junk/other_useless_file.html

Disallow crawling of the whole site except a subdirectory

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([["*", [{ disallow: "/" }, { allow: "/public/" }]]]),
};

Output:

User-agent: *
Disallow: /
Allow: /public/

Block a specific image from Google Images

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([["Googlebot-Image", [{ disallow: "/images/dogs.jpg" }]]]),
};

Output:

User-agent: Googlebot-Image
Disallow: /images/dogs.jpg

Block all images on your site from Google Images

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([["Googlebot-Image", [{ disallow: "/" }]]]),
};

Output:

User-agent: Googlebot-Image
Disallow: /

Disallow crawling of files of a specific file type

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([["Googlebot", [{ disallow: "/*.gif$" }]]]),
};

Output:

User-agent: Googlebot
Disallow: /*.gif$

Disallow crawling of an entire site, but allow Mediapartners-Google

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([
    ["*", [{ disallow: "*" }]],
    ["Mediapartners-Google", [{ allow: "/" }]],
  ]),
};

Output:

User-agent: *
Disallow: /

User-agent: Mediapartners-Google
Allow: /

Disallow crawling for multiple user agents in one go

Input:

const eleventyPluginRobotsTxtOptions = {
  rules: new Map([[["agent1", "agent2", "agent3"], [{ disallow: "/" }]]]),
};

Output:

User-agent: agent1
User-agent: agent2
User-agent: agent3
Disallow: /

Notes

  • This plugin registers Liquid as a recognized template language, as suggested by Zach Leatherman here: https://github.com/11ty/eleventy/issues/1612#issuecomment-2027476340