Skip to content

Conversation

roderik
Copy link
Member

@roderik roderik commented Feb 2, 2025

Summary by Sourcery

Add a sitemap and an llms.txt file for improved SEO and LLM indexing.

New Features:

  • Added a sitemap.xml file to improve SEO.

Tests:

  • Added a plugin to generate an llms.txt file containing all documentation and blog post links, which is helpful for LLM indexing.

Copy link

sourcery-ai bot commented Feb 2, 2025

Reviewer's Guide by Sourcery

This pull request introduces a sitemap.xml and llms.txt file to improve SEO and LLM indexing. It also adds a docusaurus plugin to generate the llms.txt file.

Sequence diagram for llms.txt generation process

sequenceDiagram
    participant P as Plugin
    participant FS as FileSystem
    participant B as Build Process

    P->>FS: Read markdown files
    FS-->>P: Return file contents
    P->>P: Parse frontmatter
    P->>P: Extract titles and permalinks
    P->>P: Sort content
    P->>P: Generate markdown content
    P->>FS: Write llms.txt
    P->>B: Complete build process
Loading

Class diagram for the LLMs Plugin

classDiagram
    class Plugin {
        +name: string
        +loadContent()
        +contentLoaded()
        +postBuild()
    }

    class ContentItem {
        +title: string
        +description: string
        +permalink: string
        +sectionNesting: number
    }

    class DocusaurusPlugin {
        +loadVersions()
        +loadDocs(version)
        +loadBlog()
    }

    Plugin ..> ContentItem : creates
    Plugin ..|> DocusaurusPlugin : implements
Loading

File-Level Changes

Change Details Files
Added sitemap configuration to docusaurus.
  • Configured sitemap to generate a sitemap.xml file.
  • Set lastmod to 'date'.
  • Set changefreq to 'weekly'.
  • Set priority to 0.5.
  • Ignored /tags/** patterns.
  • Filtered out pagination URLs from the sitemap.
docusaurus.config.ts
Added a docusaurus plugin to generate llms.txt.
  • Created a new docusaurus plugin.
  • The plugin generates a llms.txt file containing links to all documentation pages and blog posts.
  • The plugin reads all markdown files from the docs and blog directories.
  • The plugin extracts the title and permalink from each markdown file.
  • The plugin writes the llms.txt file to the output directory.
src/plugins/docusaurus-llms-plugin/index.ts
src/plugins/docusaurus-llms-plugin/package.json
Added llms.txt to the navbar.
  • Added a new navbar item for llms.txt.
docusaurus.config.ts
Added ideal image plugin.
  • Added the ideal image plugin to the docusaurus config.
  • Added the ideal image plugin to the package.json.
docusaurus.config.ts
package.json
Added dependencies for sitemap and ideal image plugins.
  • Added @docusaurus/plugin-sitemap as a dependency.
  • Added @docusaurus/plugin-ideal-image as a dependency.
  • Added @docusaurus/faster as a dependency.
package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the feat New feature label Feb 2, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @roderik - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing or replacing the console.log debug statements with proper logging before merging to production
  • The error handling in the llms plugin could be improved to provide more context when issues occur rather than catching and continuing silently
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 2 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const fileName = fileNameMatch ? fileNameMatch[1] : '';

// Basic frontmatter parsing
const titleMatch = content.match(/title:\s*(.+)/);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use a proper frontmatter parser instead of regex

The current regex-based approach is fragile and might break with complex frontmatter. Consider using a library like 'gray-matter' for robust frontmatter parsing.

Suggested implementation:

            const fileNameMatch = file.match(/([^/]+)\.mdx?$/);
            const fileName = fileNameMatch ? fileNameMatch[1] : '';

            // Parse frontmatter using gray-matter
            const matter = require('gray-matter');
            const { data: frontmatter } = matter(content);
            const title = frontmatter.title || fileName;

You'll need to:

  1. Install the gray-matter package: npm install gray-matter
  2. Add gray-matter to your project's dependencies in package.json

@@ -0,0 +1,164 @@
import type { LoadContext, Plugin } from '@docusaurus/types';
import fs from 'fs';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider using asynchronous fs methods for non-blocking I/O.

Using synchronous file system methods can block the event loop, potentially leading to performance issues. Consider using asynchronous methods like fs.promises for better performance.

Review instructions:

Path patterns: **/*.ts

Instructions:
Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.

name: 'docusaurus-llms-plugin',

async loadContent(): Promise<ContentItem[]> {
console.log('Loading content...');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Consider removing or using a logger for console.log statements.

Console.log statements can clutter the output and are not recommended for production code. Consider using a logging library that can be configured for different environments.

Review instructions:

Path patterns: **/*.ts

Instructions:
Focus on readability over being performant, but performance is important.

@roderik roderik merged commit eab69c2 into main Feb 2, 2025
2 checks passed
@roderik roderik deleted the feat/sitemap-and-llms.txt branch February 2, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant