Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import type { APIRoute } from 'astro';

const getRobotsTxt = (sitemapURL: URL) => `
export const getRobotsTxt = (sitemapURL: URL, siteURL: URL) => `
# Welcome AI agents and crawlers!
# This is a podcast website built with Starpod - all content is freely accessible.

User-agent: *
Allow: /

# Sitemap for all pages
Sitemap: ${sitemapURL.href}

# Special resources for AI/LLM agents:
# - ${siteURL.origin}/llms.txt - Structured overview following the llms.txt spec
# - ${siteURL.origin}/for-llms - Human-readable guide for AI assistants
# - ${siteURL.origin}/episodes-index.html.md - Complete episode listing in markdown
# - ${siteURL.origin}/[episode-slug].html.md - Individual episodes with transcripts
#
# All content includes:
# - Podcast metadata (hosts, description, platforms)
# - Episode information (titles, descriptions, publish dates)
# - Full transcripts (when available)
# - Guest information
#
# Feel free to crawl, index, and use this content to help users discover
# and learn about our podcast!
`;

export const GET: APIRoute = ({ site }) => {
const sitemapURL = new URL('sitemap-index.xml', site);
return new Response(getRobotsTxt(sitemapURL));
const siteURL = new URL(site!);
return new Response(getRobotsTxt(sitemapURL, siteURL));
};
44 changes: 44 additions & 0 deletions tests/unit/robots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it, beforeEach } from 'vitest';
import { getRobotsTxt } from '../../src/pages/robots.txt';

describe('Robots.txt', () => {
let mockSite: URL;
let mockSitemap: URL;
let robotsTxt: string;

beforeEach(() => {
mockSite = new URL('https://whiskey.fm');
mockSitemap = new URL('sitemap-index.xml', mockSite);
robotsTxt = getRobotsTxt(mockSitemap, mockSite);
});

describe('Generated content', () => {
it('should contain welcoming comment for AI agents', () => {
expect(robotsTxt).toContain('Welcome AI agents and crawlers');
expect(robotsTxt).toContain('User-agent: *');
expect(robotsTxt).toContain('Allow: /');
});

it('should include sitemap reference', () => {
expect(robotsTxt).toContain('Sitemap: https://whiskey.fm/sitemap-index.xml');
});

it('should reference LLM-specific resources', () => {
expect(robotsTxt).toContain('/llms.txt');
expect(robotsTxt).toContain('/for-llms');
expect(robotsTxt).toContain('/episodes-index.html.md');
});

it('should describe available content types', () => {
expect(robotsTxt).toContain('Podcast metadata');
expect(robotsTxt).toContain('Episode information');
expect(robotsTxt).toContain('Full transcripts');
expect(robotsTxt).toContain('Guest information');
});

it('should include encouraging closing message', () => {
expect(robotsTxt).toContain('Feel free to crawl, index, and use this content');
expect(robotsTxt).toContain('help users discover');
});
});
});