Home Projects Portfolio Dashboard Export PDF Log in
Astro TypeScript CSS

Modernizing Component Architecture in Astro: Streamlining Footer and Contact Data

Maintaining a clean, data-driven footer component is often the last thing on our minds, but it is frequently the first place a user looks for connectivity. Recently, I spent some time refactoring the footer and contact sections of the landing-cetzz-labs project to move away from hardcoded values and toward a more maintainable, modular structure.

The Problem: Hardcoding as a Barrier

In many early-stage Astro projects, contact information and social links are often scattered across static HTML files or embedded directly in components. This leads to "spaghetti components" where styling and content are inextricably linked, making simple updates like changing a social media handle a risky operation.

By centralizing this data into a structured format, we decouple the content layer from the presentation layer.

Implementing Data-Driven Components

To resolve this, I implemented a data-centric approach in TypeScript, ensuring that our footer reflects current organizational information without manual DOM manipulation.

// src/data/contactInfo.ts
export const socials = [
  { platform: "GitHub", url: "https://github.com/example" },
  { platform: "Twitter", url: "https://twitter.com/example" }
];

export const contactDetails = {
  email: "[email protected]",
  address: "123 Tech Lane"
};

By defining our socials and contact info in a dedicated data file, we can map through these arrays in our components. This allows the CSS styling to remain focused purely on layout while the component handles rendering logic:

/* src/styles/footer.css */
.footer-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
}

The Outcome

With this change, updating the landing-cetzz-labs footer is now a matter of updating a single data object.

Key takeaways:

  • Decouple Content: Separate your copy and contact links from your template files.
  • Use TypeScript: Leverage type safety for your data objects to ensure all required fields are present.
  • Standardize Layouts: Use CSS Grid or Flexbox to keep footer components responsive regardless of the amount of data injected.

By treating your footer and contact information as data, you ensure that your site stays dynamic and easy to maintain as the project grows.


Generated with Gitvlg.com

Modernizing Component Architecture in Astro: Streamlining Footer and Contact Data
LAUTARO NICOLAS ZULETA

LAUTARO NICOLAS ZULETA

Author

Share: