A beautiful, responsive web application to display astronomy pictures with date selection functionality.
- 🌌 Display daily astronomy pictures
- 📅 Date picker to view historical images
- 📱 Fully responsive design
- 🎨 Beautiful dark space-themed UI
- 🖼️ Support for both images and videos
- ⚡ Fast loading with error handling
- 🔍 Click to view high-resolution images
- Open the app: Simply open
index.htmlin any modern web browser - No installation required: This is a pure HTML/CSS/JavaScript application
The app is designed to work with any astronomy picture API. To use your custom API:
Edit the apiConfig object in app.js:
this.apiConfig = {
baseUrl: 'https://your-api.com/endpoint',
apiKey: 'your-api-key',
dateParam: 'date', // Parameter name for date
apiKeyParam: 'api_key' // Parameter name for API key
};If your API has a different response structure, update the displayPicture method to map your API fields:
// Example for custom API response
displayPicture(data) {
this.elements.title.textContent = data.name || data.title; // Your title field
this.elements.explanation.textContent = data.desc || data.explanation; // Your description field
// ... map other fields as needed
}The app expects these fields (customize as needed):
title- Picture titledate- Picture dateexplanation- Picture descriptionurl- Image URLhdurl- High-resolution image URL (optional)media_type- 'image' or 'video'copyright- Image credit (optional)
// For a custom API with different field names
const customApiConfig = {
baseUrl: 'https://my-space-api.com/pictures',
apiKey: 'my-secret-key',
dateParam: 'picture_date',
apiKeyParam: 'auth_token'
};
// Update the app configuration
app.updateApiConfig(customApiConfig);Your API should:
- Accept date parameter: To fetch pictures for specific dates
- Return JSON response: With picture data
- Support CORS: For browser requests (or serve from same domain)
- Include required fields: At minimum
titleandurl
astronomy-apod/
├── index.html # Main HTML file
├── styles.css # Styling and responsive design
├── app.js # JavaScript functionality
└── README.md # This file
Edit styles.css to customize:
- Colors: Update CSS custom properties
- Fonts: Change the
font-familydeclarations - Layout: Modify grid and flexbox properties
The modular JavaScript structure makes it easy to add:
- Favorite pictures functionality
- Social sharing
- Picture categories
- Search functionality
- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
If you encounter CORS errors:
- Serve the files from a local server
- Use a CORS proxy for development
- Ensure your API supports CORS headers
- Never commit API keys to public repositories
- Consider using environment variables or server-side proxies for production
- The app uses image lazy loading
- Consider implementing caching for better performance
Feel free to fork and customize this project for your needs!
Open source - modify and use as needed.