svelte-wikipedia Svelte Themes

Svelte Wikipedia

Search pages on Wikipedia

svelte-wikipedia-app

Search pages on Wikipedia and discover trending articles from any date.

Visit Site

Quick Start

npm install
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

Features

  • šŸ” Full-text Wikipedia Search - Search across Wikipedia in your language
  • šŸŒ Multi-language Support - English, Spanish, Portuguese, French, Italian, German
  • šŸ”„ Trending Articles - Browse Wikipedia's most-viewed articles by date
  • šŸ“… Historical Data - Check trending articles from any date in the past
  • šŸŽØ Dark Mode - Beautiful dark/light theme support
  • ⚔ Lightning Fast - Optimized API interactions and caching

Architecture

šŸ†• Modular Stores + API Factories

The project uses a clean, layered architecture:

  • stores.js - Unified Svelte stores (searchStore, featuredStore)
  • apiConfig.js - Centralized configuration and constants
  • apiUtils.js - Reusable utility functions for data processing
  • searchApi.js - Wikipedia search functionality
  • featuredApi.js - Trending/featured articles functionality

Benefits:

  • āœ… Pure, testable API factories
  • āœ… Automatic language switching
  • āœ… Intelligent retry logic for API delays
  • āœ… Separated concerns
  • āœ… Better error handling

See docs/MIGRATION_TO_STORES.md for architecture details.

Documentation

Recent Improvements

āœ… Bug Fixes

  • Fixed: "can't access property 'toLowerCase', pageDetails.title is undefined" error
  • Added defensive checks for all API responses
  • Improved error handling with proper HTTP status validation

šŸ—ļø Code Quality

  • Comprehensive JSDoc documentation on all functions
  • Modular API design with separated concerns
  • Pure utility functions for better testability
  • Better error messages and logging

šŸ“š Documentation

  • Complete API architecture guide
  • Bug fix documentation with prevention strategies
  • Testing guide with examples
  • Inline code comments and JSDoc

Development

Running Tests

# When test infrastructure is added
npm run test
npm run test:ui
npm run test:coverage

See docs/TESTING_GUIDE.md for setup instructions and examples.

Code Standards

  • Documentation: All functions have JSDoc comments
  • Modularity: Separated concerns - config, utils, search, featured
  • Error Handling: Defensive programming with validation
  • Pure Functions: Utilities are side-effect free and testable

Making Changes

When working with the API:

  1. Add configuration to apiConfig.js
  2. Create utilities in apiUtils.js
  3. Implement logic in feature-specific modules (searchApi.js, featuredApi.js)
  4. Document with JSDoc
  5. Create tests in __tests__ directory

Project Structure

src/
ā”œā”€ā”€ lib/
│   ā”œā”€ā”€ api/                    # šŸ†• Modular API modules
│   │   ā”œā”€ā”€ apiConfig.js       # Configuration & constants
│   │   ā”œā”€ā”€ apiUtils.js        # Reusable utilities
│   │   ā”œā”€ā”€ searchApi.js       # Wikipedia search
│   │   └── featuredApi.js     # Trending articles
│   ā”œā”€ā”€ stores.js              # šŸ†• Unified Svelte stores
│   ā”œā”€ā”€ theme.js
│   └── utils.js
ā”œā”€ā”€ components/
│   ā”œā”€ā”€ Header.svelte
│   ā”œā”€ā”€ Searchbar.svelte
│   ā”œā”€ā”€ WikiArticle.svelte
│   └── toast/
ā”œā”€ā”€ routes/
│   ā”œā”€ā”€ __layout.svelte
│   ā”œā”€ā”€ index.svelte
│   └── about.svelte
└── i18n/                      # Internationalization
    ā”œā”€ā”€ en.json
    ā”œā”€ā”€ es.json
    └── ...

docs/
ā”œā”€ā”€ API_ARCHITECTURE.md        # API design guide
ā”œā”€ā”€ MIGRATION_TO_STORES.md     # šŸ†• Stores migration guide
ā”œā”€ā”€ HOTFIX_RETRY_LOGIC.md      # šŸ†• Retry logic details
ā”œā”€ā”€ PHASE1_FINAL_SUMMARY.md    # šŸ†• Phase 1 completion
ā”œā”€ā”€ BUG_FIXES.md              # Bug fixes & prevention
└── TESTING_GUIDE.md          # Testing setup & examples

API Usage Examples

Search Wikipedia

import { createSearchApi } from 'src/lib/api/searchApi';

const search = createSearchApi('en');
const results = await search.search('javascript');
search.setLanguage('es');  // Switch language
import { createFeaturedApi } from 'src/lib/api/featuredApi';

const featured = createFeaturedApi('en');
const articles = await featured.fetchFeatured(new Date('2024-10-24'));

API Utilities

import { normalizeImageUrl, formatViewCount } from 'src/lib/api/apiUtils';

const image = normalizeImageUrl(imageUrl, 400);
const viewsText = formatViewCount(1000000);  // "1,000,000"

See docs/API_ARCHITECTURE.md for complete examples.

Performance

  • Uses Wikimedia APIs for fast responses
  • Image optimization and URL normalization
  • Efficient error handling and retries
  • Support for historical date queries

Browser Support

  • Modern browsers (ES6+)
  • Chrome, Firefox, Safari, Edge

License

MIT

Contributing

Contributions are welcome! Please:

  1. Follow the code standards (JSDoc documentation, modular design)
  2. Update documentation when making changes
  3. Test your changes thoroughly
  4. Create descriptive commit messages

Status

  • āœ… Search functionality - Stable
  • āœ… Featured articles - Stable
  • āœ… Multi-language support - Stable
  • āœ… Bug fixes - Complete
  • āœ… Documentation - Complete
  • āœ… Stores migration - Complete (Phase 1)
  • 🚧 Unit tests - In progress (Phase 2)
  • šŸ“… Caching layer - Planned (Phase 3)
  • šŸ“… Performance optimizations - Planned

Top categories

Loading Svelte Themes