This commit is contained in:
Michael Zhang 2024-04-02 10:30:51 -05:00
parent 565de50eb3
commit 62b4c105a9
4 changed files with 20 additions and 11 deletions

View file

@ -5,14 +5,21 @@ import { sortBy } from "lodash-es";
import TagList from "./TagList.astro"; import TagList from "./TagList.astro";
interface Props { interface Props {
className: string; class: string;
basePath: string; basePath: string;
drafts?: "exclude" | "include" | "only"; drafts?: "exclude" | "include" | "only";
filteredPosts?: Post[]; filteredPosts?: Post[];
timeFormat?: string;
} }
type Post = CollectionEntry<"posts">; type Post = CollectionEntry<"posts">;
const { className, basePath, drafts: includeDrafts, filteredPosts } = Astro.props; const {
class: className,
basePath,
drafts: includeDrafts,
filteredPosts,
timeFormat,
} = Astro.props;
type FilterFn = (_: Post) => boolean; type FilterFn = (_: Post) => boolean;
@ -49,7 +56,7 @@ const sortedPosts = sortBy(allPosts, (post) => -post.data.date);
<tr class="row"> <tr class="row">
<td class="info"> <td class="info">
<span class="spacer" /> <span class="spacer" />
<Timestamp timestamp={post.data.date} /> <Timestamp timestamp={post.data.date} format={timeFormat} />
</td> </td>
<td> <td>
<div class="title"> <div class="title">

View file

@ -1,15 +1,13 @@
--- ---
interface Props { interface Props {
timestamp: Date; timestamp: Date;
format: string | undefined;
} }
const { timestamp } = Astro.props; const { timestamp, format: customFormat } = Astro.props;
import { format } from "date-fns"; import { format } from "date-fns";
// const datestamp = timestamp.toLocaleDateString(undefined, {
// year: "numeric",
// month: "short",
// day: "numeric",
// });
--- ---
<span title={timestamp.toISOString()}>{format(timestamp, "yyyy MMM d")}</span> <span class="timestamp" title={timestamp.toISOString()}>
{format(timestamp, customFormat ?? "yyyy MMM d")}
</span>

View file

@ -10,5 +10,5 @@ const currentUrl = Astro.url;
<BaseLayout> <BaseLayout>
<h2>Blog</h2> <h2>Blog</h2>
<PostList className="home" basePath={join(currentUrl.pathname, "posts")} /> <PostList class="home" timeFormat="yyyy-MM-dd" basePath={join(currentUrl.pathname, "posts")} />
</BaseLayout> </BaseLayout>

View file

@ -1,4 +1,8 @@
.home.postListing { .home.postListing {
.timestamp {
font-family: var(--monofont);
}
.tags { .tags {
gap: 4px; gap: 4px;