Skip to content

Commit

Permalink
Add Socials component to avoid code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
elpekenin committed Oct 16, 2022
1 parent 2acea86 commit 7ef631f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 39 deletions.
18 changes: 2 additions & 16 deletions src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import socialIcons from "@assets/socialIcons";
import { SOCIALS } from "src/config";
import Hr from "./Hr.astro";
import LinkButton from "./LinkButton.astro";
import Socials from "./Socials.astro";
const currentYear = new Date().getFullYear();
Expand All @@ -16,19 +17,7 @@ const { noMarginTop = false } = Astro.props;
<footer class={`${noMarginTop ? "" : "mt-auto"}`}>
<Hr noPadding />
<div class="footer-wrapper">
<div class="social-icons">
{
SOCIALS.filter((social) => social.active).map((social) => (
<LinkButton
href={social.href}
className="link-button"
title={social.name}
>
<Fragment set:html={socialIcons[social.name]} />
</LinkButton>
))
}
</div>
<Socials />
<div class="copyright-wrapper">
<span>Copyright &#169; {currentYear}</span>
<span class="separator">&nbsp;|&nbsp;</span>
Expand Down Expand Up @@ -56,7 +45,4 @@ const { noMarginTop = false } = Astro.props;
.separator {
@apply hidden sm:inline;
}
.social-icons {
@apply flex flex-wrap justify-center gap-1;
}
</style>
30 changes: 30 additions & 0 deletions src/components/Socials.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
import { SOCIALS } from "src/config";
import LinkButton from "./LinkButton.astro";
import socialIcons from "@assets/socialIcons";
---


<div class="social-icons">
{
SOCIALS.filter((social) => social.active).map((social) => (
<LinkButton
href={social.href}
className="link-button"
title={social.name}
>
<Fragment set:html={socialIcons[social.name]} />
</LinkButton>
))
}
</div>

<style>
.social-icons {
@apply flex flex-wrap justify-center gap-1;
@apply mt-1 sm:mt-0 sm:ml-2 sm:space-x-1;
}
.link-button {
@apply p-2 sm:p-1 hover:rotate-6;
}
</style>
26 changes: 3 additions & 23 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
---
import { SOCIALS } from "src/config";
import Layout from "@layouts/Layout.astro";
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import LinkButton from "@components/LinkButton.astro";
import Hr from "@components/Hr.astro";
import Card from "@components/Card";
import getSortedPosts from "@utils/getSortedPosts";
import socialIcons from "@assets/socialIcons";
import slugify from "@utils/slugify";
import type { Frontmatter } from "src/types";
import Socials from "@components/Socials.astro";
const posts = await Astro.glob<Frontmatter>("../contents/*.md");
Expand Down Expand Up @@ -49,19 +48,7 @@ const sortedPosts = getSortedPosts(posts);
</p>
<div class="social-wrapper">
<div class="whitespace-nowrap">Social Links:</div>
<div class="social-icons">
{
SOCIALS.filter((social) => social.active).map((social) => (
<LinkButton
href={social.href}
className="link-button"
title={social.name}
>
<Fragment set:html={socialIcons[social.name]} />
</LinkButton>
))
}
</div>
<Socials />
</div>
</section>

Expand Down Expand Up @@ -119,7 +106,7 @@ const sortedPosts = getSortedPosts(posts);
<Footer />
</Layout>

<style>
<style is:global>
/* ===== Hero Section ===== */
#hero {
@apply pt-8;
Expand All @@ -139,12 +126,6 @@ const sortedPosts = getSortedPosts(posts);
.social-wrapper {
@apply flex flex-col sm:flex-row sm:items-center mt-4 mb-6;
}
.social-icons {
@apply mt-1 sm:mt-0 sm:ml-2 sm:space-x-1;
}
.link-button {
@apply p-2 sm:p-1 hover:rotate-6;
}

/* ===== Featured & Recent Posts Sections ===== */
#featured,
Expand All @@ -155,7 +136,6 @@ const sortedPosts = getSortedPosts(posts);
#recent-posts h2 {
@apply font-semibold text-2xl tracking-wide;
}

.all-posts-btn-wrapper {
@apply text-center my-8;
}
Expand Down

0 comments on commit 7ef631f

Please sign in to comment.