Skip to content

Conversation

Copy link

Copilot AI commented Oct 24, 2025

Overview

This PR addresses code duplication across the repository by refactoring HTML layouts, SCSS styles, and JavaScript code with minimal, surgical changes that maintain all existing functionality.

Changes Made

HTML Layout Refactoring

The _layouts/home.html file was duplicating the entire HTML document structure (DOCTYPE, html, head, body tags) from _layouts/default.html. This has been refactored so that home.html now uses Jekyll's layout inheritance:

Before:

<!DOCTYPE html>
<html lang="en">
{% include head.html %}
<body class="home">
  <!-- content -->
</body>
</html>

After:

---
layout: default
body_class: home
---
<!-- content only -->

To support this change, _layouts/default.html now accepts an optional body_class parameter, making it more flexible for future use.

Meta Tags Consolidation

Open Graph and Twitter meta tags were hardcoded in _includes/head.html. These have been extracted into a new reusable include _includes/meta-tags.html that supports page-level overrides:

{% include meta-tags.html %}

This allows individual pages to override default values for title, description, and OG image by setting front matter variables like page.og_image, page.og_image_width, etc.

CSS Transition Patterns

Repeated transition declarations were consolidated using SCSS mixins and placeholder classes:

Before:

.element { transition: all var(--base-trans) ease-in-out; }
.another { transition: all var(--base-trans) ease-in-out; }

After:

%transition-base { @include transition(var(--base-trans)); }
.element { @extend %transition-base; }
.another { @extend %transition-base; }

This pattern was applied to 6 instances across _sass/_layout.scss, creating three reusable placeholders: %transition-base, %transition-mid, and %transition-slow.

JavaScript Optimization

The scrollToItem function in assets/js/s.js had duplicate logic for getting the current time:

Before:

const startTime = "now" in window.performance ? performance.now() : new Date().getTime();
// ... later in the code
const now = "now" in window.performance ? performance.now() : new Date().getTime();

After:

const getTime = () => "now" in window.performance ? performance.now() : new Date().getTime();
const startTime = getTime();
// ... later in the code
const now = getTime();

CSS Cleanup

Removed outdated vendor prefixes that are no longer needed for modern browsers:

  • -webkit-transition: nonetransition: none
  • -moz-box-sizing: border-boxbox-sizing: border-box

Testing

  • ✅ Code review passed with no issues
  • ✅ Security scan (CodeQL) passed with no vulnerabilities
  • ✅ No breaking changes to functionality
  • ✅ All changes are backward compatible

Impact

  • 7 files changed: 70 insertions(+), 54 deletions(-)
  • Net reduction: 16 lines of code
  • Improved maintainability through DRY principles
  • More flexible layout system for future pages
  • Cleaner, more modern CSS without outdated prefixes
Original prompt

Find and refactor duplicated code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Refactor duplicated code across HTML layouts, CSS, and JavaScript Oct 24, 2025
Copilot AI requested a review from adrianmg October 24, 2025 18:16
Copilot finished work on behalf of adrianmg October 24, 2025 18:16
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