Website Development Guide
This document provides comprehensive guidance for developing and maintaining the Swit project's GitHub Pages website built with VitePress.
Overview
The Swit project website is built using:
- VitePress - Static site generator
- Vue 3 - Component framework
- TypeScript - Type safety
- Tailwind CSS - Styling framework
- GitHub Actions - CI/CD pipeline
Project Structure
docs/pages/
├── .vitepress/ # VitePress configuration
│ ├── config/ # Multi-language configurations
│ └── theme/ # Custom theme components
├── en/ # English content
├── zh/ # Chinese content
├── public/ # Static assets
├── scripts/ # Build and automation scripts
└── tests/ # Testing suite
Development Setup
Prerequisites
- Node.js 18+
- npm or yarn
- Git
Installation
bash
cd docs/pages
npm install
Development Commands
bash
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Run tests
npm test
# Run linting
npm run lint
# Type checking
npm run type-check
Website Architecture
VitePress Configuration
The website uses a multi-language setup with shared configurations:
config/index.mjs
- Main configuration entryconfig/shared.mjs
- Shared settingsconfig/en.mjs
- English-specific configurationconfig/zh.mjs
- Chinese-specific configuration
Theme Customization
Custom theme components are located in .vitepress/theme/
:
index.js
- Theme entry pointcomponents/
- Vue componentsstyles/
- CSS styles and variables
Content Structure
Content is organized by language and category:
├── en/zh/
│ ├── index.md # Homepage
│ ├── guide/ # User guides
│ ├── api/ # API documentation
│ ├── examples/ # Code examples
│ └── community/ # Community resources
Component Development
Creating New Components
- Create Vue component in
.vitepress/theme/components/
- Import and register in theme
index.js
- Use in Markdown files with proper props
Example component structure:
vue
<template>
<div class="my-component">
<!-- Component content -->
</div>
</template>
<script setup lang="ts">
// TypeScript setup
</script>
<style scoped>
/* Component styles */
</style>
Key Components
- HomePage.vue - Landing page hero and features
- FeatureCard.vue - Feature showcase cards
- CodeExample.vue - Syntax-highlighted code examples
- ApiDocViewer.vue - API documentation display
- SearchBox.vue - Enhanced search functionality
Styling Guidelines
- Use Tailwind CSS classes for consistency
- Follow responsive design principles
- Support both light and dark themes
- Maintain accessibility standards
Content Management
Writing Documentation
- Use Markdown with VitePress extensions
- Include frontmatter with title and description
- Follow established content structure
- Add appropriate navigation links
Multi-language Support
- Keep content structure consistent between languages
- Use the same file names and paths
- Update both language versions simultaneously
- Test language switching functionality
Content Automation
The website includes scripts for automated content management:
sync-docs.js
- Synchronizes content from main projectapi-docs-generator.js
- Generates API documentationcontent-validator.js
- Validates content consistency
API Documentation Integration
Automatic Generation
API documentation is automatically generated from:
- OpenAPI/Swagger specifications
- Protocol Buffer definitions
- Code comments and annotations
Manual Updates
For manual API documentation updates:
- Edit source files in the main project
- Run
npm run sync:api
to regenerate - Review and commit changes
Performance Optimization
Build Optimization
- Code splitting is configured automatically
- Static assets are optimized during build
- CSS is purged and minimized
Runtime Performance
- Images use lazy loading
- Critical resources are preloaded
- Service Worker provides offline caching
Monitoring
Performance is monitored using:
- Lighthouse CI in GitHub Actions
- Core Web Vitals tracking
- Bundle size analysis
Testing Strategy
Unit Tests
bash
# Run component tests
npm run test:unit
# Watch mode
npm run test:unit:watch
# Coverage report
npm run test:coverage
E2E Tests
bash
# Run end-to-end tests
npm run test:e2e
# Run in headless mode
npm run test:e2e:headless
Accessibility Tests
bash
# Run accessibility audits
npm run test:a11y
Performance Tests
bash
# Run performance audits
npm run test:performance
Deployment
GitHub Actions
The website deploys automatically via GitHub Actions:
- Build Stage - Compiles VitePress site
- Test Stage - Runs all test suites
- Deploy Stage - Publishes to GitHub Pages
Manual Deployment
For manual deployment:
bash
# Build production site
npm run build
# Deploy to GitHub Pages
npm run deploy
Maintenance Tasks
Regular Updates
- Update dependencies monthly
- Review and update content quarterly
- Monitor performance metrics weekly
- Check broken links monthly
Content Synchronization
bash
# Sync with main project documentation
npm run sync:docs
# Update API documentation
npm run sync:api
# Validate content consistency
npm run validate:content
Security Updates
- Monitor security advisories
- Update dependencies promptly
- Run security audits regularly
Troubleshooting
Common Issues
Build Failures
- Check Node.js version compatibility
- Clear node_modules and reinstall
- Verify configuration files syntax
Development Server Issues
- Check port availability (default 5173)
- Clear VitePress cache
- Verify file permissions
Content Display Issues
- Check Markdown syntax
- Verify frontmatter format
- Test component imports
Performance Issues
- Analyze bundle size
- Check image optimization
- Review lazy loading implementation
Debug Mode
Enable debug mode for detailed logging:
bash
DEBUG=vitepress:* npm run dev
Contributing Guidelines
Code Style
- Follow TypeScript best practices
- Use ESLint and Prettier configurations
- Write meaningful commit messages
- Include tests for new features
Pull Request Process
- Create feature branch
- Make changes with tests
- Run full test suite
- Submit PR with description
- Address review feedback
Documentation Standards
- Write clear, concise documentation
- Include code examples
- Keep both language versions updated
- Follow established patterns
Version Control
Branch Strategy
master
- Main branchdocs/development
- Active developmentdocs/gh-pages
- Deployment branch- Feature branches for specific changes
Release Process
- Update version numbers
- Run full test suite
- Build production site
- Tag release
- Deploy to production
Support and Resources
Getting Help
- Check existing documentation
- Search GitHub issues
- Create detailed bug reports
- Join community discussions
Useful Resources
Contact
- Create GitHub issues for bugs
- Use discussions for questions
- Follow contribution guidelines
- Respect community standards