Refactor duplicated code in layouts, JavaScript, and CSS #100
+38
−35
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 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.htmllayout was duplicating the entire HTML structure (DOCTYPE, html, head, body tags) that already exists indefault.html.Solution:
home.htmlto inherit fromdefault.htmlusing Jekyll's layout systembody_classparameter support todefault.htmlfor dynamic body class assignment_includes/home-scripts.htmlinclude fileImpact: Reduced ~31 lines of duplicated HTML structure and improved maintainability.
2. JavaScript Duplication Removal
Problem: The
scrollToItem()function inassets/js/s.jshad two instances of duplicated logic:start >= destinationOffsetToScrollappeared twice"now" in window.performance ? performance.now() : new Date().getTime()was duplicatedSolution:
isScrollingUpvariablegetCurrentTime()helper function to centralize time retrieval logicImpact: Improved code readability and reduced potential for inconsistencies.
3. CSS Optimization
Problem: The
.home-work-grid__project-description h2selector had a redundantoutline: noneproperty 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
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 scriptsassets/js/s.js- Extracted helper function and variable_sass/_layout.scss- Removed redundant CSS propertyindex.html- Added body_class parameterOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.