Refactor duplicated code across SCSS, JavaScript, and HTML layouts #95
      
        
          +52
        
        
          −48
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Overview
This PR eliminates code duplication throughout the codebase, reducing repetitive patterns by ~50 lines while maintaining all existing functionality. The changes improve maintainability and follow DRY (Don't Repeat Yourself) principles.
Changes
SCSS Refactoring
Created reusable transition mixin (
_sass/main.scss)This mixin replaces 5 instances of duplicated transition declarations across
_sass/_layout.scss:.home-navigation a.home-intro-scroll.home-work-grid__project-description h2 a.post aand.post a:before.blog-list-item a spanConsolidated CSS selectors
::selectionand::-moz-selectioninto a single rule (previously duplicated the same 3 properties).post-meta aand.post-footer acolor declarations within parent selectorsJavaScript Refactoring (
assets/js/s.js)Extracted helper function to eliminate duplication:
This replaces 2 instances of the same ternary expression.
Simplified conditional logic:
arrowelement doesn't existif (arrow && ...)→if (...))lettoconstfor immutable variablesHTML Layout Refactoring
Eliminated HTML boilerplate duplication:
Before,
_layouts/home.htmlduplicated the entire HTML structure fromdefault.html:After, it now extends the default layout:
Updated
_layouts/default.htmlto support optional body classes viabody_classparameter, making it flexible for all layouts.Testing
Impact
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.