Skip to content

Commit

Permalink
Add dates to blog post summaries
Browse files Browse the repository at this point in the history
Fix links to posts on blog summary page.
List in descending date order.
Make footer text smaller.
  • Loading branch information
fwextensions committed Apr 14, 2024
1 parent f93fe78 commit f41cd6f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
// site: "https://www.sfcivictech.org/"
// base: "/",
site: "https://sfbrigade.github.io",
base: "/astro-static-site",
base: "/astro-static-site/",
compressHTML: false,
integrations: [
icon({
Expand Down
10 changes: 5 additions & 5 deletions src/components/FooterNav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const columns = [

<style>
footer {
padding-top: 0;
font-size: smaller;
display: flex;
flex-direction: row;
justify-content: space-between;
Expand All @@ -77,8 +77,8 @@ const columns = [
}

h3 {
font-size: 1.25rem;
margin-bottom: 0.5rem;
font-size: 1.25em;
margin-bottom: 0.5em;
}

ul {
Expand All @@ -91,7 +91,7 @@ const columns = [
}

li {
padding: .15rem 0;
padding: .15em 0;
display: block;
}

Expand All @@ -103,7 +103,7 @@ const columns = [

.icon {
display: inline-block;
min-width: 1.5rem;
min-width: 1.5em;
text-align: center;
}
</style>
6 changes: 1 addition & 5 deletions src/components/NewsSummary.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Props {
const { title = "In the News" } = Astro.props;
const posts = await getCollection("blog");
const recentPosts = posts.slice(-3);
const recentPosts = posts.slice(-3).reverse();
---

<section>
Expand All @@ -17,7 +17,3 @@ const recentPosts = posts.slice(-3);
{recentPosts.map((post) => <NewsSummaryItem post={post} />)}
</div>
</section>

<style>

</style>
35 changes: 28 additions & 7 deletions src/components/NewsSummaryItem.astro
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
---
import type { CollectionEntry } from "astro:content";
import { dateFromSlug } from "@/utils/dateFromSlug";
import { getBlogImage } from "@/utils/getBlogImage";
interface Props {
post: CollectionEntry<"blog">;
}
const { post: { slug, data: { title, image } } } = Astro.props;
const {
post: {
slug,
data: {
title,
image,
date = dateFromSlug(slug)
}
}
} = Astro.props;
const imageData = await getBlogImage(image);
const backgroundImageURL = imageData?.src ?? "";
const postURL = "blog/" + slug;
const dateString = date?.toLocaleDateString("en-US",
{ year: "numeric", month: "short", day: "numeric" });
---

<article style={`background-image: url(${backgroundImageURL})`}>
<div class="dimmer"></div>
<a href={postURL}>
<div class="dimmer"></div>
<time datetime={date?.toISOString()}>{dateString}</time>
<h3>{title}</h3>
</a>
</article>
Expand All @@ -24,23 +37,31 @@ const postURL = "blog/" + slug;
aspect-ratio: 1;
background-size: cover;
background-position: center;
padding: var(--pico-block-spacing-horizontal);
padding: 0;
overflow: hidden;
position: relative;
flex-direction: column;
justify-content: flex-end;
display: flex;
}

article > a {
--pico-color: white;
text-decoration: none;
height: 100%;
padding: var(--pico-block-spacing);
flex-direction: column;
justify-content: space-between;
display: flex;
position: relative;
}

article time {
color: var(--pico-color, white);
font-size: 0.75rem;
}

article h3 {
--pico-color: white;
font-size: 1rem;
margin-bottom: 0;
position: relative;
}

.dimmer {
Expand Down
6 changes: 6 additions & 0 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ const { title, header = title } = Astro.props;
</main>
<FooterNav />
</Page>

<style>
h1 {
margin-bottom: calc(var(--pico-block-spacing-vertical) * 2);
}
</style>
2 changes: 1 addition & 1 deletion src/pages/blog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const posts = await getCollection("blog");
<BaseLayout title="Blog">
<ul>
{
posts.map((post) => (
posts.reverse().map((post) => (
<li>
<a href={"blog/" + post.slug}>{post.data.title}</a>
</li>
Expand Down
11 changes: 11 additions & 0 deletions src/utils/dateFromSlug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function dateFromSlug(
slug: string)
{
const leadingDate = slug.match(/^\d{4}-\d{2}-\d{2}/)?.[0];

if (leadingDate) {
return new Date(leadingDate);
}

return null;
}
2 changes: 1 addition & 1 deletion src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const githubURL = "https://github.com/sfbrigade";
export const facebookURL = "https://www.facebook.com/sfcivictech";
export const linkedinURL = "https://www.linkedin.com/company/sfbrigade/";

export const base = (url: string) => `${url.startsWith("/") ? import.meta.env.BASE_URL : ""}${url}`;
export const base = (url: string) => ((url.startsWith("/") ? import.meta.env.BASE_URL : "") + url).replaceAll("//", "/");

0 comments on commit f41cd6f

Please sign in to comment.