Skip to content
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

redirect search to browspage #178

Merged
merged 6 commits into from
Nov 4, 2024

Conversation

koilebeit
Copy link

@koilebeit koilebeit commented Nov 1, 2024

Pull request

Proposed changes

solves #175

Types of changes

  • New feature (non-breaking change which adds functionality).
  • Enhancement (non-breaking change which enhances functionality)
  • Bug Fix (non-breaking change which fixes an issue).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • New Features

    • Updated navigation to include a new search component, enhancing the search functionality.
    • Introduced a new search form with an input field and submit button, allowing users to perform searches directly from the navigation bar.
    • Implemented a seamless search experience that redirects users to the results page with their query.
    • Added translations for search-related terms in English, Spanish, and German to improve accessibility.
  • Bug Fixes

    • Replaced outdated search component to improve functionality and user experience.

Copy link

changeset-bot bot commented Nov 1, 2024

⚠️ No Changeset found

Latest commit: cf0f14d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Nov 1, 2024

Walkthrough

The changes involve modifications to the navigation component of a web page, specifically in four files. The _includes/collection-nav-sgb.html file has replaced the previous search component with a new search component, while the _includes/nav-search.html and _includes/nav-search-browse.html files introduce new search functionalities, including JavaScript functions for handling search queries and new forms for user input. Additionally, the _data/translations.yml file has been updated to include translations for the new search component.

Changes

File(s) Change Summary
_includes/collection-nav-sgb.html Updated search component from nav-search-lunr.html to nav-search-browse.html.
_includes/nav-search.html Added a new JavaScript function site_search, a search form with an input field and submit button, styled with Bootstrap.
_includes/nav-search-browse.html Added a new JavaScript function site_search, a search form with an input field and submit button, styled with Bootstrap.
_data/translations.yml Added translations for "Search" and "Submit search" in English, Spanish, and German for the nav-search-browse.html component.

Poem

In the garden where we play,
A new search path leads the way.
With forms and buttons, oh so bright,
Finding treasures, pure delight!
Hop along, let queries flow,
Navigation’s charm, now on show! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 797b952 and bfc2763.

📒 Files selected for processing (2)
  • _includes/collection-nav-sgb.html (1 hunks)
  • _includes/nav-search.html (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • _includes/collection-nav-sgb.html

_includes/nav-search.html Outdated Show resolved Hide resolved
_includes/nav-search.html Outdated Show resolved Hide resolved
_includes/nav-search.html Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bfc2763 and b578934.

📒 Files selected for processing (2)
  • _data/translations.yml (1 hunks)
  • _includes/nav-search.html (1 hunks)
🔇 Additional comments (2)
_includes/nav-search.html (2)

12-20: Add input constraints for better security.

The search input field should have length constraints to prevent excessive long queries:
[security]

     <input
       id="site-search"
       class="form-control"
       type="text"
       autocomplete="off"
       spellcheck="false"
+      minlength="2"
+      maxlength="100"
       placeholder="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}"
       aria-label="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}"
     >

10-32: Consider adding CSRF protection.

The form submission should include CSRF protection to prevent cross-site request forgery attacks:
[security]

 <form class="form-inline my-2 my-lg-0" role="search" id="search" onsubmit="site_search(); return false;" aria-label="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}">
+  {% csrf_token %}
   <div class="input-group">

Note: The exact CSRF implementation might vary depending on your web framework. Please adjust accordingly.

_includes/nav-search.html Outdated Show resolved Hide resolved
_data/translations.yml Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b578934 and 2888052.

📒 Files selected for processing (2)
  • _data/translations.yml (1 hunks)
  • _includes/nav-search.html (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • _data/translations.yml
🔇 Additional comments (1)
_includes/nav-search.html (1)

10-42: 🛠️ Refactor suggestion

Enhance form validation and user feedback.

The form implementation could benefit from additional validation attributes and visual feedback during search.

 <form
   class="form-inline my-2 my-lg-0"
   role="search"
   id="search"
-  onsubmit="site_search(); return false;"
+  onsubmit="debouncedSearch(); return false;"
   aria-label="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}"
 >
   <div class="input-group">
     <input
       id="site-search"
       class="form-control"
       type="text"
       autocomplete="off"
       spellcheck="false"
+      maxlength="100"
+      minlength="2"
+      pattern="[^<>]*"
+      title="{{ site.data.translations['_includes']['nav-search.html']['validation'][site.lang] | default: 'Please enter a valid search term' }}"
       placeholder="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}"
       aria-label="{{ site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' }}"
     >
     <button
       class="btn btn-dark"
       type="submit"
+      id="search-submit"
       aria-label="{{ site.data.translations['_includes']['nav-search.html']['submit'][site.lang] | default: 'Submit search' }}"
     >
-      <span id="search-icon">
+      <span id="search-icon" class="d-flex align-items-center">
         <svg viewBox="0 0 1024 974" fill="white" height="16px" width="20px" aria-hidden="true" focusable="false">
           <path d="M960 832L710.875 582.875C746.438 524.812 768 457.156 768 384 768 171.96900000000005 596 0 384 0 171.969 0 0 171.96900000000005 0 384c0 212 171.969 384 384 384 73.156 0 140.812-21.562 198.875-57L832 960c17.5 17.5 46.5 17.375 64 0l64-64C977.5 878.5 977.5 849.5 960 832zM384 640c-141.375 0-256-114.625-256-256s114.625-256 256-256 256 114.625 256 256S525.375 640 384 640z"/>
         </svg>
+        <span class="spinner-border spinner-border-sm ms-1 d-none" role="status" id="search-spinner">
+          <span class="visually-hidden">Searching...</span>
+        </span>
       </span>
       <span class="visually-hidden">
         {{-  site.data.translations['_includes']['nav-search.html']['search'][site.lang] | default: 'Search' -}}
       </span>
     </button>
   </div>
 </form>

+<style>
+.form-control:invalid {
+  border-color: var(--bs-danger);
+}
+</style>

+<script>
+// Add loading indicator during search
+document.getElementById('search').addEventListener('submit', function() {
+  document.getElementById('search-spinner').classList.remove('d-none');
+  document.getElementById('search-submit').disabled = true;
+  setTimeout(() => {
+    document.getElementById('search-spinner').classList.add('d-none');
+    document.getElementById('search-submit').disabled = false;
+  }, 2000);
+});
+</script>

Changes include:

  • Input validation with maxlength, minlength, and pattern attributes
  • Loading spinner during search
  • Visual feedback for invalid input
  • Debounced search submission

_includes/nav-search.html Show resolved Hide resolved
Copy link
Member

@maehr maehr left a comment

Choose a reason for hiding this comment

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

@koilebeit Thank you very much for this PR. It's a nice fix. My suggestions in regards to the naming are not critical.

_includes/collection-nav-sgb.html Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
_includes/nav-search-browse.html (2)

10-16: Enhance form security and accessibility.

The form implementation should include additional security measures and accessibility improvements:

 <form
   class="form-inline my-2 my-lg-0"
   role="search"
   id="search"
   onsubmit="site_search(); return false;"
+  method="get"
+  action="{{ '/browse.html' | relative_url }}"
+  aria-live="polite"
+  aria-atomic="true"
   aria-label="{{ site.data.translations['_includes']['nav-search-browse.html']['search'][site.lang] | default: 'Search' }}"
 >

17-26: Add input constraints and search hints.

Consider adding input constraints and search functionality hints:

     <input
       id="site-search"
       class="form-control"
       type="text"
       autocomplete="off"
       spellcheck="false"
+      minlength="2"
+      maxlength="100"
+      pattern="[^<>]*"
+      title="{{ site.data.translations['_includes']['nav-search-browse.html']['search_hint'][site.lang] | default: 'Enter at least 2 characters' }}"
       placeholder="{{ site.data.translations['_includes']['nav-search-browse.html']['search'][site.lang] | default: 'Search' }}"
       aria-label="{{ site.data.translations['_includes']['nav-search-browse.html']['search'][site.lang] | default: 'Search' }}"
     >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2888052 and 1909716.

📒 Files selected for processing (3)
  • _data/translations.yml (1 hunks)
  • _includes/collection-nav-sgb.html (1 hunks)
  • _includes/nav-search-browse.html (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • _data/translations.yml
  • _includes/collection-nav-sgb.html
🔇 Additional comments (2)
_includes/nav-search-browse.html (2)

27-42: LGTM! Well-implemented accessible search button.

The button implementation follows accessibility best practices with proper ARIA labels, screen reader text, and decorative SVG handling.


1-42: Verify browse page implementation and translations.

Please ensure:

  1. The browse page exists and can handle hash parameters for search
  2. All required translations are defined in _data/translations.yml
✅ Verification successful

Let me gather more information about the browse page implementation since it wasn't found in the root or includes directory.


Let me search for the browse page implementation and its JavaScript handling since we found the layout file but need to verify the functionality.


Let me check for the browse page JavaScript implementation since we found the layout file.


Based on the verification results, I can now provide a final response since we have confirmed:

  1. The browse page exists at _layouts/browse.html
  2. The JavaScript implementation in _includes/js/browse-js.html properly handles hash parameters for search
  3. The translations are defined in _data/translations.yml

Implementation verified successfully

The search functionality is properly implemented with:

  • Hash-based URL parameters for search terms
  • Proper handling of URL hash changes for filtering
  • Translation support for UI elements
  • Client-side filtering and display of results
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if browse page exists and verify translations

echo "Checking for browse page..."
if [ -f "_includes/browse.html" ] || [ -f "browse.html" ]; then
    echo "Browse page found"
else
    echo "Warning: browse page not found"
fi

echo "Checking for required translations..."
rg -A 2 "nav-search-browse.html" "_data/translations.yml"

Length of output: 393


Script:

#!/bin/bash
# Search for browse page and its implementation
echo "Searching for browse page in all directories..."
fd browse.html

echo -e "\nSearching for browse-related JavaScript implementations..."
rg -g "*.{html,js}" "browse" -A 5

echo -e "\nChecking for Jekyll page configurations..."
fd "_config.yml|*.md" --exec grep -l "browse"

Length of output: 128124


Script:

#!/bin/bash
# Check for browse page implementation and related JavaScript
echo "Checking for browse page JavaScript implementation..."
fd -e js browse
fd -e html browse

echo -e "\nChecking for browse page content handling..."
rg -g "*.{js,html}" "function.*browse" -A 5

Length of output: 90070


Script:

#!/bin/bash
# Check for browse page JavaScript implementation
echo "Checking for browse.js content..."
cat _includes/js/browse-js.html

echo -e "\nChecking for browse page hash handling..."
rg -g "*.{js,html}" "window.location.hash" -A 3

Length of output: 10523

_includes/nav-search-browse.html Show resolved Hide resolved
@koilebeit koilebeit merged commit c26c40e into Stadt-Geschichte-Basel:main Nov 4, 2024
3 checks passed
@koilebeit koilebeit deleted the search_slot branch November 4, 2024 08:23
@coderabbitai coderabbitai bot mentioned this pull request Nov 6, 2024
7 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 18, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants