Enhanced Code Styling for Jekyll Blog

Enhanced Code Styling for Jekyll Blog

This enhancement adds Stack Overflow-style code block styling to your Jekyll blog with the following features:

Features Added

1. Visual Code Block Styling

  • Stack Overflow-inspired design with rounded corners and shadows
  • Language labels automatically displayed in the top-right corner
  • Syntax highlighting with improved color schemes
  • Dark mode support for better readability

2. Code Block Categories

Each code block now has descriptive emoji headers that make the purpose clear:

  • πŸ“‹ Sample Data Setup - Data initialization and setup code
  • ⚠️ Traditional Approach (Slow) - Old/slow methods for comparison
  • πŸ”§ Step-by-step Solutions - Individual optimization steps
  • ⚑ Vectorized Operations - High-performance optimized code
  • πŸ”„ Index Formatting - Data structure formatting
  • βœ… Complete Solutions - Full working examples
  • ❌ Complex Logic - Examples where optimization doesn’t apply
  • πŸ—‚οΈ Memory-Efficient Processing - Large dataset handling

3. Interactive Features

  • Copy button on each code block for easy copying
  • Smooth scrolling when clicking on code headers
  • Automatic language detection based on code content
  • Responsive design that works on mobile devices

4. Accessibility

  • ARIA labels for screen readers
  • Keyboard navigation support
  • High contrast color schemes
  • Clear visual hierarchy

Files Added/Modified

New Files:

  1. _sass/code-styling.scss - Main styling for code blocks
  2. assets/js/code-enhancements.js - Interactive JavaScript functionality

Modified Files:

  1. assets/main.scss - Added import for new code styling
  2. _includes/scripts.html - Added JavaScript include
  3. _posts/2025-01-31-fast-groupwise-calculations-pandas.md - Enhanced with styled code blocks

Usage in Blog Posts

To use these enhanced code blocks in your posts, follow this pattern:

**πŸ“‹ Sample Data Setup**
```python
import pandas as pd
# Your Python code here

⚑ Optimized Solution

# High-performance code here

## Customization

### Changing Colors
Edit `_sass/code-styling.scss` to modify:
- Background colors
- Border colors  
- Language label colors
- Syntax highlighting colors

### Adding New Language Labels
In `assets/js/code-enhancements.js`, add detection patterns:

```javascript
if (code.includes('your_pattern')) {
    highlight.classList.add('language-yourtype');
}

Then add CSS in code-styling.scss:

.highlight.language-yourtype::before {
  content: "Your Language";
  background: #your-color;
}

Modifying Emoji Categories

Simply change the emoji and text in your markdown:

**🎯 Your Category Name**
```python
# code here

```

Browser Support

  • Modern browsers: Full feature support including copy functionality
  • Older browsers: Graceful degradation with basic styling
  • Mobile devices: Responsive design with touch-friendly copy buttons

Performance

  • Minimal impact: CSS and JS are lightweight
  • Cached resources: Static files cached by browser
  • Progressive enhancement: Works without JavaScript

This enhancement makes your technical blog posts more engaging and professional while maintaining excellent readability and usability.