Skip to content

Development #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 16, 2025
Merged

Development #77

merged 12 commits into from
Apr 16, 2025

Conversation

rubixvi
Copy link
Owner

@rubixvi rubixvi commented Apr 16, 2025

This pull request includes various updates across multiple files to improve code style consistency, enhance documentation, and fix minor layout issues. The most important changes include updates to the README.md, removal of the .prettierrc configuration, and several class name adjustments for better readability and consistency.

Documentation Updates:

  • README.md: Added several badges for license, top language, commit activity, last commit, issues, pull requests, stars, forks, and repo size. Removed the documentation link that was in development. [1] [2]

Configuration Removal:

  • .prettierrc: Removed the Prettier configuration file entirely.

Code Style Improvements:

Component Updates:

Summary by Sourcery

Refactor and improve code style, documentation, and search functionality across the project

Enhancements:

  • Improved search algorithm with more sophisticated relevance scoring
  • Optimized content processing for search indexing
  • Refined Tailwind CSS class ordering and consistency

Build:

  • Updated package.json scripts
  • Upgraded Next.js and related dependencies

Documentation:

  • Added GitHub repository badges to README.md
  • Simplified and refined documentation content

Chores:

  • Updated dependencies
  • Cleaned up project configuration files
  • Improved code formatting and linting

rubixvi added 11 commits April 16, 2025 15:30
- Bump versions for several Radix UI components and Tailwind CSS packages.
- Update Next.js to version 15.3.0.
- Upgrade TypeScript and ESLint packages.
- Update rehype and remark packages for improved functionality.

refactor: enhance MDX file processing in content.ts

- Optimize content processing by removing code blocks and formatting links.
- Introduce search optimization by cleaning up content and extracting headings.
- Add _searchMeta to return structured search data including clean content and keywords.
- Introduced a new function `cleanContentForSearch` to sanitize and format content for better searchability.
- Removed inline code blocks, markdown formatting, and unnecessary whitespace from the content.
- Extracted headings and keywords from the document for improved search metadata.
- Updated the `_searchMeta` object to include cleaned content, headings, and unique keywords.
…unction

- Added new custom components to be removed: Card, CardGrid, Step, StepItem, Note, FileTree, Folder, and File.
- Improved regex replacements for code blocks, inline code, and headings.
- Enhanced handling of tables by trimming whitespace from cells.
- Consolidated removal of custom components into a single regex pattern.
- Cleaned up whitespace and punctuation handling for better content normalization.
- Adjusted class order in various components for consistency and readability.
- Updated layout and spacing in error, not found, and home pages for better alignment.
- Enhanced card component styles for improved hover effects and layout.
- Refined navigation components for better accessibility and visual hierarchy.
- Improved search component layout and responsiveness.
- Cleaned up utility functions and markdown processing for better performance and readability.
- Updated ESLint and Prettier configurations for improved code quality and consistency.
@rubixvi rubixvi added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Apr 16, 2025
@rubixvi rubixvi requested a review from Copilot April 16, 2025 06:57
@rubixvi rubixvi self-assigned this Apr 16, 2025
Copy link

vercel bot commented Apr 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rubix-documents ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 16, 2025 7:03am

Copy link

sourcery-ai bot commented Apr 16, 2025

Reviewer's Guide by Sourcery

This pull request includes updates to documentation, configuration, code style, and search functionality. It adds badges to the README, removes the Prettier configuration, improves search relevance and snippet extraction, updates content processing, and adjusts class names for better readability and consistency across multiple components and pages.

Updated Class Diagram for SearchDocument

classDiagram
    class SearchDocument {
        slug: string
        title: string
        content: string
        description: string
        _searchMeta: SearchMeta
    }

    class SearchMeta {
        cleanContent: string
        headings: string[]
        keywords: string[]
    }

    SearchDocument -- SearchMeta : has a
Loading

File-Level Changes

Change Details Files
Updated documentation in README.md to include various badges and removed an in-development documentation link.
  • Added badges for license, top language, commit activity, last commit, issues, pull requests, stars, forks, and repo size.
  • Removed the in-development documentation link.
README.md
Removed the .prettierrc configuration file.
  • Deleted the .prettierrc file.
.prettierrc
Refactored the search functionality in lib/utils.ts to improve relevance calculation and snippet extraction.
  • Modified the relevance calculation to consider headings and keywords.
  • Improved snippet extraction to provide more context.
  • Removed the memoizedCleanMdxContent function.
  • Added interfaces for SearchMeta and SearchDocument.
  • Adjusted scoring for title and content matches.
  • Implemented keyword and heading matching for relevance scoring.
  • Modified proximity score calculation.
  • Updated snippet extraction logic.
  • Limited search results to the top 10.
lib/utils.ts
Enhanced content processing in scripts/content.ts to improve search indexing.
  • Added a function to clean content for search by removing code blocks, HTML tags, and special characters.
  • Extracted headings and keywords from the content for better search relevance.
  • Modified the content processing pipeline to include the cleaning and extraction steps.
scripts/content.ts
Updated the content and structure of the basic setup documentation page (contents/docs/basic-setup/index.mdx).
  • Revised the introduction to be more concise and highlight key features.
  • Updated the 'Why Documents?' section to focus on benefits and use cases.
  • Refreshed the 'Key Features' table with more descriptive and user-focused information.
  • Adjusted the language and structure for better readability and clarity.
contents/docs/basic-setup/index.mdx
Updated class names across multiple components and pages for improved readability and consistency.
  • Adjusted class names in app/docs/[[...slug]]/page.tsx for h1, p, and section elements.
  • Updated class names in app/error.tsx, app/layout.tsx, app/not-found.tsx, and app/page.tsx.
  • Modified class names in components/markdown/card.tsx for Card and CardGrid components.
  • Updated class names in components/navigation/footer.tsx and components/navigation/navbar.tsx.
app/docs/[[...slug]]/page.tsx
app/error.tsx
app/layout.tsx
app/not-found.tsx
app/page.tsx
components/markdown/card.tsx
components/navigation/footer.tsx
components/navigation/navbar.tsx
Improved the search component's UI and functionality.
  • Enhanced the styling of search results and input fields.
  • Improved the layout and responsiveness of the search dialog.
  • Added transition effects for a smoother user experience.
components/navigation/search.tsx

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

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 37 out of 38 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • .prettierrc: Language not supported

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 @rubixvi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a changeset to track the removal of the .prettierrc file.
  • The changes to lib/utils.ts significantly alter the search algorithm; ensure these changes are thoroughly tested.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -139,54 +153,68 @@ function searchMatch(a: string, b: string): number {
function calculateRelevance(
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extracting helper functions and precomputing lowercased versions of content to reduce repeated looping and lowercasing in the calculateRelevance function, improving efficiency and readability without changing functionality

Consider extracting helper functions to remove repeated looping and repeated lowercasing. For example, you can precompute a lowercased version of content and factor out the scoring of list matches into a helper. One approach might be:

```typescript
function scoreListMatches(
  items: string[],
  target: string,
  exactScore: number,
  includeScore: number
): number {
  let score = 0;
  if (items.some((item) => item === target)) score += exactScore;
  items.forEach((item) => {
    if (item.includes(target)) score += includeScore;
  });
  return score;
}

function calculateRelevance(
  query: string,
  title: string,
  content: string,
  headings: string[],
  keywords: string[]
): number {
  const lowerQuery = query.toLowerCase().trim();
  const lowerTitle = title.toLowerCase();
  const lowerContent = content.toLowerCase();
  const queryWords = lowerQuery.split(/\s+/);

  let score = 0;
  if (lowerTitle === lowerQuery) {
    score += 50;
  } else if (lowerTitle.includes(lowerQuery)) {
    score += 30;
  }
  queryWords.forEach((word) => {
    if (lowerTitle.includes(word)) score += 15;
  });

  // Pre-lower headings and keywords
  const lowerHeadings = headings.map((h) => h.toLowerCase());
  const lowerKeywords = keywords.map((k) => k.toLowerCase());

  score += scoreListMatches(lowerHeadings, lowerQuery, 40, 25);
  score += scoreListMatches(lowerKeywords, lowerQuery, 35, 20);

  const exactMatches = lowerContent.match(new RegExp(`\\b${lowerQuery}\\b`, "gi"));
  if (exactMatches) score += exactMatches.length * 10;

  queryWords.forEach((word) => {
    if (lowerContent.includes(word)) score += 5;
  });

  const proximityScore = calculateProximityScore(lowerQuery, lowerContent);
  score += proximityScore * 2;

  return score / Math.log(content.length + 1);
}

This refactoring consolidates similar logic, reduces redundant operations, and makes future modifications easier to manage without changing functionality.

@@ -95,18 +104,74 @@ function removeCustomComponents() {
}
}

function cleanContentForSearch(content: string): string {
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the regex chain in cleanContentForSearch into a sequence of smaller, well-named transformation functions for improved readability and maintainability.

Consider refactoring the inline regex chain into a sequence of small, well-named transformation functions. This makes each step self-contained and easier to debug. For example:

function removeCodeBlocks(text: string): string {
  return text.replace(/```[\s\S]*?```/g, " ");
}

function inlineCode(text: string): string {
  return text.replace(/`([^`]+)`/g, "$1");
}

function removeHeadings(text: string): string {
  return text.replace(/#{1,6}\s+(.+)/g, "$1");
}

function unwrapMarkdownLinks(text: string): string {
  return text.replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1");
}

// Define other transformations as needed...

function cleanContentForSearch(content: string): string {
  const transformations = [
    removeCodeBlocks,
    inlineCode,
    removeHeadings,
    unwrapMarkdownLinks,
    // ...other helper functions
  ];

  return transformations.reduce((text, fn) => fn(text), content)
    // example final adjustments:
    .replace(/[^\w\s-:]/g, " ")
    .replace(/\s+/g, " ")
    .toLowerCase()
    .trim();
}

This refactoring maintains functionality while making the logic clearer and easier to extend or modify in the future.

@rubixvi rubixvi merged commit ec4931d into main Apr 16, 2025
5 checks passed
rubixvi added a commit that referenced this pull request Apr 16, 2025
Merge pull request #77 from rubixvi/development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant