Skip to content

Conversation

Copy link

Copilot AI commented Oct 24, 2025

Overview

This PR refactors duplicated code across the repository to improve maintainability and follow DRY (Don't Repeat Yourself) principles. The changes eliminate code duplication in layouts, JavaScript, and CSS while preserving all existing functionality.

Changes

1. Layout Inheritance Refactoring

Problem: The home.html layout was duplicating the entire HTML structure (DOCTYPE, html, head, body tags) that already exists in default.html.

Solution:

  • Converted home.html to inherit from default.html using Jekyll's layout system
  • Added body_class parameter support to default.html for dynamic body class assignment
  • Extracted home-specific scripts into a new _includes/home-scripts.html include file

Impact: Reduced ~31 lines of duplicated HTML structure and improved maintainability.

2. JavaScript Duplication Removal

Problem: The scrollToItem() function in assets/js/s.js had two instances of duplicated logic:

  • Scroll direction check start >= destinationOffsetToScroll appeared twice
  • Time retrieval pattern "now" in window.performance ? performance.now() : new Date().getTime() was duplicated

Solution:

  • Extracted scroll direction check into a single isScrollingUp variable
  • Created getCurrentTime() helper function to centralize time retrieval logic

Impact: Improved code readability and reduced potential for inconsistencies.

3. CSS Optimization

Problem: The .home-work-grid__project-description h2 selector had a redundant outline: none property that was also applied to its nested anchor element.

Solution: Removed the redundant property from the h2 element (only the anchor needs it for focus management).

Testing

  • ✅ Code review completed - no issues found
  • ✅ CodeQL security scan - no vulnerabilities detected
  • ✅ All changes are non-breaking and preserve existing functionality

Files Changed

  • _layouts/default.html - Added dynamic body class support
  • _layouts/home.html - Converted to use layout inheritance
  • _includes/home-scripts.html - New include for home-specific scripts
  • assets/js/s.js - Extracted helper function and variable
  • _sass/_layout.scss - Removed redundant CSS property
  • index.html - Added body_class parameter
Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Refactor duplicated code to improve maintainability Refactor duplicated code in layouts, JavaScript, and CSS Oct 24, 2025
Copilot AI requested a review from adrianmg October 24, 2025 18:35
Copilot finished work on behalf of adrianmg October 24, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants