Skip to content

Conversation

Copy link

Copilot AI commented Oct 24, 2025

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)

@mixin transition-base($speed: var(--base-trans)) {
  transition: all $speed ease-in-out;
}

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 a and .post a:before
  • .blog-list-item a span

Consolidated CSS selectors

  • Merged ::selection and ::-moz-selection into a single rule (previously duplicated the same 3 properties)
  • Nested .post-meta a and .post-footer a color declarations within parent selectors
  • Fixed misleading duplicate comment "HOME: Intro" → renamed to "POST: Article Layout"

JavaScript Refactoring (assets/js/s.js)

Extracted helper function to eliminate duplication:

function getTime() {
  return "now" in window.performance ? performance.now() : new Date().getTime();
}

This replaces 2 instances of the same ternary expression.

Simplified conditional logic:

  • Added early return pattern when arrow element doesn't exist
  • Removed redundant null checks after early exit (3 instances of if (arrow && ...)if (...))
  • Changed let to const for immutable variables

HTML Layout Refactoring

Eliminated HTML boilerplate duplication:

Before, _layouts/home.html duplicated the entire HTML structure from default.html:

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

After, it now extends the default layout:

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

Updated _layouts/default.html to support optional body classes via body_class parameter, making it flexible for all layouts.

Testing

  • ✅ JavaScript syntax validated with Node.js
  • ✅ Code review completed with no issues
  • ✅ CodeQL security scan passed with zero vulnerabilities
  • ✅ All changes maintain backward compatibility

Impact

  • Maintainability: Future changes to transitions, time functions, or HTML structure only need to be made in one place
  • Consistency: Using shared mixins and helpers ensures consistent behavior across the site
  • Readability: Less code duplication makes the codebase easier to understand and navigate
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 self-assigned this Oct 24, 2025
Copilot AI changed the title [WIP] Refactor duplicated code in the project Refactor duplicated code across SCSS, JavaScript, and HTML layouts Oct 24, 2025
Copilot AI requested a review from adrianmg October 24, 2025 18:17
Copilot finished work on behalf of adrianmg October 24, 2025 18:17
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