This document describes the implementation of Structured Data (JSON-LD) for Filter Controls in the TeachLink application. This implementation improves SEO and accessibility by providing machine-readable metadata about filter options.
-
src/utils/structuredDataUtils.ts- Utility functions for generating JSON-LD structured data
- Functions:
generateFilterStructuredData(): Generates complete filter control structured datagenerateBreadcrumbStructuredData(): Generates breadcrumb navigation structured datagenerateFilterGroupStructuredData(): Generates individual filter group structured datavalidateStructuredData(): Validates JSON-LD structure and schema.org compliance
-
src/components/seo/StructuredDataScript.tsx- React component to render JSON-LD script tags
- Validates JSON before rendering
- Uses
type="application/ld+json"for proper schema.org recognition
-
src/utils/__tests__/structuredDataUtils.test.ts- Comprehensive unit tests for structured data utilities
- Tests for generation, validation, and edge cases
-
src/components/search/FilterSidebar.tsx- Added structured data generation for search filters
- Includes: difficulty, duration, price, topics, instructor, node affinity
- Integrated
StructuredDataScriptcomponent
-
src/components/dashboard/DashboardFilters.tsx- Added structured data for dashboard analytics filters
- Includes: time range, aggregation, metric, categories
- Integrated
StructuredDataScriptcomponent
-
src/components/search/FacetedFilterSystem.tsx- Added structured data for faceted search filters
- Includes: content type, topics, difficulty, price, rating
- Integrated
StructuredDataScriptcomponent
The implementation follows schema.org specifications:
- Uses
@context: https://schema.org - Implements
FilterControlstype for main filter groups - Uses
ItemListfor filter options - Uses
PropertyValueSpecificationfor individual filter groups - Uses
BreadcrumbListfor navigation breadcrumbs
- All existing ARIA labels are preserved
- Structured data provides additional semantic information
- Screen readers can access filter metadata through JSON-LD
- No changes to keyboard navigation
- Existing keyboard shortcuts and focus management remain intact
- JSON-LD provides machine-readable descriptions
- Filter options include descriptive text in structured data
- Helps assistive technologies understand filter semantics
StructuredDataScriptcomponent usesdangerouslySetInnerHTMLonly after validation- JSON parsing validates structure before rendering
- No user input is directly injected without sanitization
validateStructuredData()function ensures:- Valid JSON format
- Required fields present (@context, @type)
- Schema.org context compliance
- Invalid structured data is not rendered to prevent console errors
- Structured data generation uses
useMemoto avoid unnecessary recalculations - Minimal performance overhead (JSON serialization)
- Only renders when filter values change
- Comprehensive test coverage for all utility functions
- Tests for:
- JSON-LD generation
- Schema.org compliance
- Validation logic
- Edge cases (invalid JSON, missing fields)
- Structured data is integrated into all three filter components
- Each component generates appropriate metadata for its filters
- No regression in existing functionality
- JSON-LD is supported by all modern browsers
- Graceful degradation for older browsers (script tag simply not rendered)
- No impact on core functionality if structured data fails to load
- Search engines can understand filter structure
- Rich snippets potential for filter pages
- Improved indexing of filterable content
- Better semantic understanding of UI controls
Potential improvements:
- Dynamic structured data based on actual filter results
- Integration with Google Rich Results testing
- Add more schema.org types as needed
- Server-side rendering for initial structured data
- Internationalization support for structured data descriptions
- When adding new filters, update the corresponding structured data generation
- Keep structured data in sync with UI changes
- Run tests after modifying filter components
- Validate JSON-LD using Google's Structured Data Testing Tool