Skip to content

Commit

Permalink
Show an In the Code module on the homepage in a /beta route
Browse files Browse the repository at this point in the history
Add GitHubEvents React component to render recent sfbrigade commits/PRs.
Use CSS modules with camelCase option in the Vite config.
Use SVG arrows for scroll buttons with a hover state.
Clean up GitHubEventCard spacing with nested styles, added PostCSS config for nested classes, and clipped card body tooltips.
Add repo name to the bottom of cards, make cards square, limit summary text length, and reorganize CSS and card layout.
Refactor GitHubEvents by creating ScrollButton components, adding GitHubEventCard.tsx and ghEventsAPI.ts, and using date-fns for relative time strings.
Move scroll arrows below the carousel to prevent accidental card clicks when arrows disappear.
  • Loading branch information
fwextensions committed Dec 10, 2024
1 parent 31f3695 commit c0602a1
Show file tree
Hide file tree
Showing 14 changed files with 856 additions and 232 deletions.
9 changes: 9 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from "astro/config";
import react from "@astrojs/react";
import icon from "astro-icon";

export default defineConfig({
Expand All @@ -7,6 +8,7 @@ export default defineConfig({
trailingSlash: "ignore",
compressHTML: true,
integrations: [
react(),
icon({
iconDir: "src/assets/icons",
include: {
Expand All @@ -23,4 +25,11 @@ export default defineConfig({
},
}),
],
vite: {
css: {
modules: {
localsConvention: "camelCase",
}
}
}
});
587 changes: 375 additions & 212 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@
},
"dependencies": {
"@astrojs/check": "^0.8.3",
"@astrojs/react": "^3.6.3",
"@astrojs/rss": "^4.0.8",
"@iconify-json/fa": "^1.2.0",
"@picocss/pico": "^2.0.6",
"@stylistic/eslint-plugin": "^2.8.0",
"@stylistic/stylelint-config": "^2.0.0",
"@stylistic/stylelint-plugin": "^3.0.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/parser": "^8.6.0",
"astro": "^4.15.8",
"astro-icon": "^1.1.1",
"date-fns": "^4.1.0",
"dayjs": "^1.11.13",
"eslint-plugin-astro": "^1.2.4",
"fast-glob": "^3.3.2",
"marked": "^14.1.2",
"postcss-html": "^1.7.0",
"postcss-nesting": "^13.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"stylelint": "^16.9.0",
"stylelint-config-html": "^1.1.0",
"typescript": "^5.6.2",
Expand Down
11 changes: 11 additions & 0 deletions src/components/CodeSummary.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import GitHubEvents from "@/components/react/GitHubEvents";
import HomeSection from "@/components/HomeSection.astro";
---

<HomeSection title="In the Code">
<GitHubEvents
org="sfbrigade"
client:only="react"
/>
</HomeSection>
24 changes: 24 additions & 0 deletions src/components/HomeSection.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
interface Props {
title: string;
}
const { title } = Astro.props;
---

<section>
<h2>{title}</h2>
<div class="grid">
<slot />
</div>
</section>

<style>
section:last-of-type {
margin-bottom: 0;
}

h2 {
margin-bottom: calc(2 * var(--pico-typography-spacing-vertical));
}
</style>
21 changes: 4 additions & 17 deletions src/components/NewsSummary.astro
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
---
import { getCollection } from "astro:content";
import NewsSummaryItem from "@/components/NewsSummaryItem.astro";
import HomeSection from "@/components/HomeSection.astro";
interface Props {
title?: string;
}
const { title = "In the News" } = Astro.props;
const posts = await getCollection("blog");
const recentPosts = posts.slice(-3).reverse();
---

<section>
<h2>{title}</h2>
<div class="grid">
{recentPosts.map((post) => <NewsSummaryItem post={post} />)}
</div>
</section>

<style>
section {
margin-bottom: 0;
}
</style>
<HomeSection title="In the News">
{recentPosts.map((post) => <NewsSummaryItem post={post} />)}
</HomeSection>
2 changes: 1 addition & 1 deletion src/components/NewsSummaryItem.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const dateString = formatShortMDY(date);
background-size: cover;
background-position: center;
padding: 0;
margin-bottom: 0;
margin: 0;
border-radius: 0;
overflow: hidden;
position: relative;
Expand Down
59 changes: 59 additions & 0 deletions src/components/react/GitHubEventCard.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.event-card {
--sp1: calc(.25 * var(--pico-block-spacing));
--sp2: calc(2 * var(--sp1));
--sp4: calc(4 * var(--sp1));
aspect-ratio: 1;
width: 25%;
min-width: 28ch;
height: 100%;
text-decoration: none;
padding: var(--sp2);
text-align: center;
display: flex;
flex-direction: column;
flex-shrink: 0;
align-items: center;
justify-content: space-between;
background: #f9f9f9;
border: 1px solid #ddd;
border-radius: var(--pico-border-radius);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
scroll-snap-align: start;
overflow: hidden;

img {
width: calc(3 * var(--sp2));
height: calc(3 * var(--sp2));
border-radius: 50%;
margin-bottom: var(--sp1);
}

h3 {
margin: 0 0 var(--sp1) 0;
font-size: 1rem;
}

p {
font-size: smaller;
color: #555;
margin: 0;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}

footer > * {
font-size: .75rem;
}

h4 {
margin: var(--sp1) 0 0;
color: #888;
}

time {
color: #999;
}
}
45 changes: 45 additions & 0 deletions src/components/react/GitHubEventCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { intlFormatDistance } from "date-fns/intlFormatDistance";
import type { GitHubEvent } from "@/components/react/ghEventsAPI.ts";
import styles from "@/components/react/GitHubEventCard.module.css";

const MaxTooltipLength = 350;

interface GitHubEventProps {
event: GitHubEvent;
now?: Date;
}

export default function GitHubEventCard({
event,
now = new Date() }: GitHubEventProps)
{
const { repoName, link, avatar, handle, message, timestamp } = event;
const tooltip = message.length > MaxTooltipLength
? message.slice(0, MaxTooltipLength) + "..."
: message;

return (
<a
className={styles.eventCard}
key={link}
href={link}
target="_blank"
rel="noopener noreferrer"
>
<header>
<img src={avatar} alt={`${handle}'s avatar`} />
<h3>{handle}</h3>
</header>
<p title={tooltip}>{message}</p>
<footer>
<h4>{repoName}</h4>
<time
dateTime={timestamp}
title={new Date(timestamp).toLocaleString()}
>
{intlFormatDistance(timestamp, now)}
</time>
</footer>
</a>
);
}
60 changes: 60 additions & 0 deletions src/components/react/GitHubEvents.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.github-events-container {
position: relative;
width: 100%;
overflow: hidden;
}

.event-list {
display: flex;
overflow-x: auto;
gap: var(--pico-grid-column-gap);
padding-bottom: 16px;
scroll-snap-type: x mandatory;
scrollbar-width: none; /* Hide scrollbar for Firefox */
-ms-overflow-style: none; /* Hide scrollbar for IE/Edge */
}

.event-list::-webkit-scrollbar {
display: none; /* Hide scrollbar for Chrome/Safari */
}

.button-container {
margin-top: .5rem;
width: 100%;
height: 2rem;
position: relative;
}

.scroll-button {
position: absolute;
top: 0;
width: 2rem;
height: 2rem;
padding: 0;
color: hsla(0, 0%, 10%, .25);
transition: color 0.3s ease;
background: none;
border: none;
border-radius: 50%;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
box-shadow: none;

&:hover {
color: hsla(0, 0%, 10%, .5);
}

&:active {
color: hsla(0, 0%, 10%, .65);
}

&.left {
left: 0;
}

&.right {
right: 0;
}
}
Loading

0 comments on commit c0602a1

Please sign in to comment.