astro-robots
Advanced tools
Comparing version 0.8.21 to 1.0.1
@@ -1,22 +0,27 @@ | ||
import d from"node:fs";var u="astro-robots";function w(r,e){let o=/^(?=.{1,253}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$/;typeof e!="string"&&l(r,"Host must be a string","error"),o.test(e)||l(r,"Host is invalid","error")}function g(r,e){let o="";return e.host===!0||e.host===!1||(typeof e.host=="number"?w(r,e.host):typeof e.host=="string"&&e.host!=="localhost"&&(w(r,e.host),o+=`Host: ${e.host} | ||
`)),o}function p(r,e){/^https?:\/\/[^\s/$.?#].[^\s]*\.(xml|txt|html|xml.gz|txt.gz|json|xhtml)$/i.test(e)||l(r,"sitemap [URL is invalid or not a valid sitemap file.]",!0)}function c(r,e,o){let s="";if(e.sitemap===!0)s+=`Sitemap: ${o}sitemap-index.xml | ||
`;else if(typeof e.sitemap=="number")l(r,"sitemap [URL is invalid or not a valid sitemap file.]",!0);else if(typeof e.sitemap=="string")p(r,e.sitemap),s+=`Sitemap: ${e.sitemap} | ||
`;else if(Array.isArray(e.sitemap))for(let i of e.sitemap)p(r,i),s+=`Sitemap: ${i} | ||
`;return s}function l(r,e,o){let s="\x1B[1mRefer:\x1B[22m",i=t=>{r.info("\x1B[31mFailured!\x1B[39m")},n=t=>{r.warn(`Skiped! [${t}].`)};switch(o){case"warn":n(e);break;case"error":throw i(e),new Error(`${e}`);case!0:throw i(e),new Error(`${e} | ||
${s} | ||
Visit \x1B[4mhttps://developers.google.com/search/docs/crawling-indexing/robots/create-robots-txt#useful-robots.txt-rules\x1B[24m for instructions.`);default:throw i(e),new Error(`${e} | ||
${s} | ||
Visit \x1B[4mhttps://yandex.com/support/webmaster/controlling-robot/robots-txt.html#recommend\x1B[24m for instructions.`)}}function b(r,e,o){var i;let s="";for(let n of r.policy??[]){if((i=r==null?void 0:r.policy)==null||i.forEach((t,a)=>{var f,m;t.userAgent||l(o,`policy[${a}].userAgent [Required, one or more per group]. | ||
${JSON.stringify(t,null,2)}`,!!t.userAgent),(!t.allow&&!t.disallow||((f=t.allow)==null?void 0:f.length)===0&&((m=t.disallow)==null?void 0:m.length)===0)&&l(o,`policy[${a}] [At least one or more 'disallow' or 'allow' entries per rule]. | ||
${JSON.stringify(t,null,2)}`,!t.allow&&!t.disallow),t.crawlDelay&&typeof t.crawlDelay!="number"?l(o,`policy[${a}].crawlDelay [Must be number]. | ||
${JSON.stringify(t,null,2)}`,!1):t.crawlDelay!==void 0&&(t==null?void 0:t.crawlDelay)<0?l(o,`policy[${a}].crawlDelay [Must be a positive number]. | ||
${JSON.stringify(t,null,2)}`,!1):t.crawlDelay!==void 0&&((t==null?void 0:t.crawlDelay)<.1||t.crawlDelay>60)&&l(o,`policy[${a}].crawlDelay [Must be between 0.1 and 60 seconds]. | ||
${JSON.stringify(t,null,2)}`,!1)}),n.userAgent){let t=Array.isArray(n.userAgent)?n.userAgent:[n.userAgent||"*"];for(let a of t)a&&(s+=`User-agent: ${a} | ||
`)}if(n.allow){let t=Array.isArray(n.allow)?n.allow:[n.allow];for(let a of t)s+=`Allow: ${a} | ||
`}if(n.disallow){let t=Array.isArray(n.disallow)?n.disallow:[n.disallow];for(let a of t)s+=`Disallow: ${a} | ||
`}if(n.crawlDelay&&(s+=`Crawl-delay: ${n.crawlDelay} | ||
`),n.cleanParam){let t=Array.isArray(n.cleanParam)?n.cleanParam:[n.cleanParam];for(let a of t)s+=`Clean-param: ${a} | ||
`}r.policy&&n!==r.policy[r.policy.length-1]?s+=` | ||
`:r.sitemap!==!1&&(s+=` | ||
import x from"node:fs";var g="astro-robots";var c=class{colors={reset:"\x1B[0m",fg:{red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",cyanBold:"\x1B[1m\x1B[36m"}};packageName;constructor(r){this.packageName=r}log(r,o=""){let a=r.join(` | ||
`),s=new Date,e=s.getHours().toString().padStart(2,"0"),n=s.getMinutes().toString().padStart(2,"0"),m=s.getSeconds().toString().padStart(2,"0"),f=`\x1B[2m${e}:${n}:${m}\x1B[22m`;console.log(`${f} %s[${this.packageName}]%s ${a}`,o,o?this.colors.reset:"")}info(...r){this.log(r,this.colors.fg.cyanBold)}success(...r){this.log(r,this.colors.fg.cyanBold)}warn(...r){this.log([`${this.colors.fg.yellow}(!)${this.colors.reset} ${r}`],this.colors.fg.cyanBold)}error(...r){this.log([`${this.colors.fg.red}failed!${this.colors.reset}`,...r],this.colors.fg.cyanBold)}};function u(t){let r=performance.now();t();let o=performance.now();return Math.floor(o-r)}var l=new c(g);function p(t){let r=/^(?=.{1,253}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$/;typeof t!="string"&&i("Host must be a string","error"),r.test(t)||i("Host is invalid","error")}function h(t){let r="";return t.host===!0||t.host===!1||(typeof t.host=="number"?p(t.host):typeof t.host=="string"&&t.host!=="localhost"&&(p(t.host),r+=`Host: ${t.host} | ||
`)),r}function b(t){/^https?:\/\/[^\s/$.?#].[^\s]*\.(xml|txt|html|xml.gz|txt.gz|json|xhtml)$/i.test(t)||i("sitemap [URL is invalid or not a valid sitemap file.]",!0)}function y(t,r){let o="";if(t.sitemap===!0)o+=`Sitemap: ${r}sitemap-index.xml | ||
`;else if(typeof t.sitemap=="number")i("sitemap [URL is invalid or not a valid sitemap file.]",!0);else if(typeof t.sitemap=="string")b(t.sitemap),o+=`Sitemap: ${t.sitemap} | ||
`;else if(Array.isArray(t.sitemap))for(let a of t.sitemap)b(a),o+=`Sitemap: ${a} | ||
`;return o}function i(t,r){let o="\x1B[1mRefer:\x1B[22m",a=e=>{l.info("\x1B[31mFailured!\x1B[39m")},s=e=>{l.warn(`Skiped! [${e}].`)};switch(r){case"warn":s(t);break;case"error":throw a(t),new Error(`${t}`);case!0:throw a(t),new Error(`${t} | ||
${o} | ||
Visit \x1B[4mhttps://developers.google.com/search/docs/crawling-indexing/robots/create-robots-txt#useful-robots.txt-rules\x1B[24m for instructions.`);default:throw a(t),new Error(`${t} | ||
${o} | ||
Visit \x1B[4mhttps://yandex.com/support/webmaster/controlling-robot/robots-txt.html#recommend\x1B[24m for instructions.`)}}function w(t,r){var a;let o="";for(let s of t.policy??[]){if((a=t==null?void 0:t.policy)==null||a.forEach((e,n)=>{var m,f;e.userAgent||i(`policy[${n}].userAgent [Required, one or more per group]. | ||
${JSON.stringify(e,null,2)}`,!!e.userAgent),(!e.allow&&!e.disallow||((m=e.allow)==null?void 0:m.length)===0&&((f=e.disallow)==null?void 0:f.length)===0)&&i(`policy[${n}] [At least one or more 'disallow' or 'allow' entries per rule]. | ||
${JSON.stringify(e,null,2)}`,!e.allow&&!e.disallow),e.crawlDelay&&typeof e.crawlDelay!="number"?i(`policy[${n}].crawlDelay [Must be number]. | ||
${JSON.stringify(e,null,2)}`,!1):e.crawlDelay!==void 0&&(e==null?void 0:e.crawlDelay)<0?i(`policy[${n}].crawlDelay [Must be a positive number]. | ||
${JSON.stringify(e,null,2)}`,!1):e.crawlDelay!==void 0&&((e==null?void 0:e.crawlDelay)<.1||e.crawlDelay>60)&&i(`policy[${n}].crawlDelay [Must be between 0.1 and 60 seconds]. | ||
${JSON.stringify(e,null,2)}`,!1)}),s.userAgent){let e=Array.isArray(s.userAgent)?s.userAgent:[s.userAgent||"*"];for(let n of e)n&&(o+=`User-agent: ${n} | ||
`)}if(s.allow){let e=Array.isArray(s.allow)?s.allow:[s.allow];for(let n of e)o+=`Allow: ${n} | ||
`}if(s.disallow){let e=Array.isArray(s.disallow)?s.disallow:[s.disallow];for(let n of e)o+=`Disallow: ${n} | ||
`}if(s.crawlDelay&&(o+=`Crawl-delay: ${s.crawlDelay} | ||
`),s.cleanParam){let e=Array.isArray(s.cleanParam)?s.cleanParam:[s.cleanParam];for(let n of e)o+=`Clean-param: ${n} | ||
`}t.policy&&s!==t.policy[t.policy.length-1]?o+=` | ||
`:t.sitemap!==!1&&(o+=` | ||
# crawling rule(s) for above bots | ||
`)}return s+=c(o,r,e),s+=g(o,r),s}var A={sitemap:!0,host:!1,policy:[{userAgent:"*",allow:"/"}]};function h(r){let e,o,s,i={...A,...r};return{name:u,hooks:{"astro:config:setup":({config:n})=>{e=n},"astro:build:start":({logger:n})=>{let t=new URL(e.base,e.site).href;o=b(i,t,n)},"astro:build:done":async({dir:n,logger:t})=>{s=process.hrtime(),d.writeFileSync(new URL("robots.txt",n),o);let a=process.hrtime(s),f=Math.floor((a[0]*1e9+a[1])/1e6);t.info(`'robots.txt' \x1B[32mgenerated\x1B[0m in ${f}ms`)}}}}export{h as default}; | ||
`)}return o+=y(t,r),o+=h(t),o}function d(t){t>10&&(console.log(` | ||
\x1B[42m generating 'robots.txt' file \x1B[0m`),console.log(`${[` | ||
\x1B[33m(!) Keep your 'robots.txt' file size under 10 KB for best crawling results.`,"- To keep it low, only include directives that are necessary for your site.",`- Remove rules for pages that no longer exist to avoid bloat.\x1B[0m | ||
`].join(` | ||
`)}`))}function $(t){return x.statSync(t).size/1024}var A={sitemap:!0,host:!1,policy:[{userAgent:"*",allow:"/"}]};function S(t){let r,o,a,s={...A,...t};return{name:g,hooks:{"astro:config:setup":({config:e})=>{r=e},"astro:build:start":()=>{o=new URL(r.base,r.site).href},"astro:build:done":async({dir:e})=>{a=u(()=>{x.writeFileSync(new URL("robots.txt",e),w(s,o),"utf-8")});let n=$(`${r.outDir.pathname}/robots.txt`);l.info(`\x1B[2mCompleted in ${a}ms\x1B[22m`),d(n),l.success(`\x1B[32mgenerated\x1B[0m 'robots.txt' ${n} KB`)}}}}export{S as default}; |
@@ -5,3 +5,3 @@ { | ||
"description": "The lightweight robots.txt generator makes it simple to create compliant robots.txt files specifically for Astro integrations, with zero-config support, an intuitive JSDoc API, and always up-to-date verified bots user-agents.", | ||
"version": "0.8.21", | ||
"version": "1.0.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "exports": { |
155
README.md
@@ -1,105 +0,45 @@ | ||
# What is Astro Robots | ||
<div align="center"> | ||
The lightweight `robots.txt` generator package makes it simple to create compliant robots.txt files specifically for [Astro Integrations](https://astro.build/integrations/), with zero-config support, an intuitive JSDoc API, and always up-to-date [Verified Bots](https://radar.cloudflare.com/traffic/verified-bots) support. | ||
**Latest Updates! 🎉 See the [change log](./CHANGELOG.md) for details.** | ||
[Features](#features) · [Installation](#installation) · [Usage](#usage) · [Configuration](#configuration) · [Changelog](/CHANGELOG.md) | ||
<img height="128" alt="" src="./assets/logo.svg"> | ||
## Overview | ||
# astro-robots | ||
Robots.txt is one of the simplest files on a website, but it’s also one of the easiest to mess up. Just one character out of place can wreak havoc on your SEO and prevent search engines from accessing important content on your site. | ||
A lightweight `robots.txt` generator designed specifically for [Astro Integration](http://www.npmjs.com/package/astro) . With zero-config support, an intuitive JSDoc API, and up-to-date [Verified Bots](https://radar.cloudflare.com/traffic/verified-bots) support | ||
This is why robots.txt misconfigurations are extremely common — even amongst experienced SEO professionals (the `astro-robots` may help you do better). | ||
[Features](#features) · [Installation](#installation) · [Usage](#usage) · [Configuration](#configuration) · [Change Log](/CHANGELOG.md) | ||
### Key Features | ||
</div> | ||
<details> | ||
<summary><b>Speeds Creation:</b> Effortlessly genertate customized <i>robots.txt<sup>[<a href="https://www.rfc-editor.org/rfc/rfc9309.html" target="_blank">1</a>]</sup></i> files.</summary> | ||
<br> | ||
## Overview | ||
Just a few steps, our robot.txt generator allows you to easily create optimized and customized robots.txt files for your website. | ||
Robots.txt file are simple yet crucial for your website's SEO. A single misstep can prevent search engines from accessing important content. With `astro-robots` help, you can avoid common misconfigurations and ensure optimal SEO performance. | ||
- Conveniently manage bot access rules without coding. | ||
- Supports setting crawling delay, allowing/blocking specified bots, etc. | ||
- Smart automation to get optimized robots.txt without the hassle and guesswork. | ||
<br> | ||
</details> | ||
<details> | ||
<summary><b>Validated Bots:</b> Uses the most recent <i>Validated Bots<sup>[<a href="https://radar.cloudflare.com/traffic/verified-bots" target="_blank">2</a>]</sup></i> from leading search engines.</summary> | ||
<br> | ||
Stay ahead of the curve with the most up-to-date verified bot user-agents from search leaders like Google, Bing, Yahoo, Yandex, and Baidu. | ||
- Uses latest verified bot user-agents from major search engines. | ||
- Integrates real-world bot data to optimize for emerging bots. | ||
- Saves time from manually tracking user-agent changes. | ||
<br> | ||
</details> | ||
<details> | ||
<summary><b>Flexible Configuration:</b> Streamline bot crawling with universal rules or customized settings per bot.</summary> | ||
<br> | ||
- Allows unified rule application OR customization per bot for flexibility | ||
- Time-saving standardization is available but customization is also supported | ||
- Full control whether through common or customized crawling rules. | ||
<br> | ||
</details> | ||
<details> | ||
<summary><b>UI-Friendly:</b> With the blessing of <i>VSCode<sup>[<a href="https://code.visualstudio.com/" target="_blank">3</a>]</sup></i>, there is no need to pay too much attention to configuration.</summary> | ||
<br> | ||
- VSCode integration means complex configs aren't required | ||
- Streamlines process so users can concentrate on building | ||
> For localization support, it is recommended that you install _Commment Translate<sup>[[3.1](https://marketplace.visualstudio.com/items?itemName=intellsmi.comment-translate)]</sup>_ for a better experience. | ||
<br> | ||
</details> | ||
## Installation | ||
<details> | ||
<summary><b>Quick Install</b> (Astro Official Support)</summary><br> | ||
> This package is compatible with Astro 2.0 and above, which support the Integrations API. | ||
Install the `astro-robots` package into any Astro project using your preferred package manager: | ||
To automate the installation, use the `astro add` command-line tool. You can initialize it via `npx`, `yarn`, or `pnpm` based on your preference. | ||
```sh | ||
# Using NPM | ||
$ npx astro add astro-robots | ||
# Using Yarn | ||
$ yarn astro add astro-robots | ||
# Using PNPM | ||
$ pnpx astro add astro-robots | ||
npx astro add astro-robots | ||
``` | ||
Alternatively, you can manually install it by running the following command in your terminal: | ||
<br> | ||
</details> | ||
### Manual Install | ||
First, install the `astro-robots` package using your package manager. If you're using npm or aren't sure, run this in the terminal: | ||
```sh | ||
$ npm install --save-dev astro-robots | ||
npm install astro-robots | ||
``` | ||
Then, apply this integration to your `astro.config.*` file using the integrations property: | ||
## Usage | ||
To use this integration, add it to your `astro.config.*` file using the integrations property: | ||
```ts | ||
// astro.config.mjs | ||
import { defineConfig } from "astro/config"; | ||
import robots from "astro-robots"; // Add code manually | ||
const siteUrl = "https://example.com"; | ||
export default defineConfig({ | ||
site: siteUrl, | ||
site: "https://example.com"; | ||
integrations: [robots()], // Add code manually | ||
@@ -109,13 +49,11 @@ }); | ||
### Usage | ||
After installing, run `npm run build` or `yarn build` in terminal: | ||
If you have completed added code manually or installed automatically (`zero-configuration`), the `robots.txt` file will be generated when you run the `npm run build` or `yarn build` command. | ||
```sh | ||
$ npm run build | ||
npm run build | ||
``` | ||
✨ dist > robots.txt | ||
This will output `robots.txt` to the `dist` folder with default rules: | ||
```txt | ||
```yaml | ||
User-agent: * | ||
@@ -132,8 +70,9 @@ Allow: / | ||
<summary><b>Getting Started</b> (A hands-on crash course with example walkthroughs).</summary><br> | ||
<summary><b>Getting Started</b> - A hands-on crash course with example walkthroughs.</summary><br> | ||
To configure this integration, pass an object to the `robots()` function call in `astro.config.*` file. | ||
To configure the integration, pass an object to the `robots()` function in your `astro.config.*` file: | ||
```ts | ||
const siteUrl = "https://example.com"; | ||
//.... | ||
import robots from "astro-robots"; | ||
@@ -144,3 +83,3 @@ export default defineConfig({ | ||
robots({ | ||
host: siteUrl.replace(/^https?:\/\/|:\d+/g, ""), | ||
host: "https://example.com";, | ||
sitemap: [ | ||
@@ -174,12 +113,8 @@ "https://example.com/sitemap.xml", | ||
], | ||
//... | ||
}); | ||
``` | ||
With the above configuration you will get a `robots.txt` file as shown below. | ||
With the above configuration, the generated `robots.txt` file will look like this: | ||
✨ dist > robots.txt | ||
```txt | ||
```yaml | ||
User-agent: Applebot | ||
@@ -193,3 +128,2 @@ User-agent: Googlebot | ||
User-agent: * | ||
User-agent: | ||
Allow: / | ||
@@ -212,3 +146,3 @@ Disallow: /admin | ||
> **Note:** Some directives (`Host` `Clean-param` `Crawl-delay`) are only supported by a few crawlers. For example from February 22, 2018, Yandex ignores the Crawl-delay directive. To set the speed at which robots downloads the site pages, use the [Site crawl rate](https://yandex.com/support/webmaster/service/crawl-rate.html#crawl-rate) in Yandex.Webmaster. | ||
> **Note:** Some directives like `Host`, `Clean-param`, and `Crawl-delay` may not be supported by all crawlers. For example, Yandex has ignored `Crawl-delay` since February 2018. To control Yandex's crawl rate, use the [Site crawl rate setting](https://yandex.com/support/webmaster/service/crawl-rate.html#crawl-rate) in Yandex Webmaster. | ||
@@ -219,6 +153,8 @@ <br> | ||
<details> | ||
<summary> | ||
<b>Integration API</b> - Customize your robots.txt directives and behaviors. | ||
<summary><b>Integration API</b> (Add new directives and behaviors for your <i>robots.txt</i> file with only a few lines of config).</summary><br> | ||
</summary><br> | ||
Through the above examples, you must have understood how `astro-robots` works. Next, let us learn more about its interface. | ||
Through the above examples, you must have understood how `astro-robots` works. Now, let's learn more about its interface. | ||
@@ -246,22 +182,19 @@ | Name | Type | Required | Default value | Directive | | ||
```ts | ||
export type UsertAgentType = | ||
| "*" | ||
| SearchEngines[keyof SearchEngines] | ||
| SocialNetwork[keyof SocialNetwork] | ||
| SearchEngineOptimization[keyof SearchEngineOptimization]; | ||
``` | ||
If you still have questions, don't worry! We have powerful [JSDoc](./dist/index.d.ts) support, which makes it easy for both SEO experts and novices to manage. | ||
Still clueless, don't worry! We have powerful [JSDoc support](./dist/index.d.ts), whether you are an SEO expert or a novice, you can easily manage it. | ||
</details> | ||
<details> | ||
<summary><b>Practical Examples</b> - Visit the <a href="https://yandex.com/support/webmaster/controlling-robot/robots-txt.html#recommend">Yandex Support</a> to learn more about directives.</summary> | ||
> I'm planning to release more practical examples to cater to the mainstream search engine market. | ||
</details> | ||
### Examples | ||
## Need Help or Feedback? | ||
Visit the [Yandex Support](https://yandex.com/support/webmaster/controlling-robot/robots-txt.html#recommend) to learn more about directives. | ||
Submit your issues or feedback on our [GitHub](https://github.com/ACP-CODE/astro-robots/issues) channel. | ||
We're planning to release more practical examples to cater to the mainstream search engine market. | ||
## Changelog | ||
See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this integration. | ||
Check out the [CHANGELOG.md](CHANGELOG.md) file for a history of changes to this integration. | ||
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
222
0
18749
193
1