Skip to content

Commit

Permalink
Update website structure (#4)
Browse files Browse the repository at this point in the history
* Update Website structure

Add news and members pages. Also update events to new collection and create new content folder.

* unified page item width
  • Loading branch information
Catking14 authored Aug 27, 2024
1 parent a5278f1 commit 8fefc5c
Show file tree
Hide file tree
Showing 16 changed files with 2,777 additions and 1,343 deletions.
3,650 changes: 2,326 additions & 1,324 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/image": "^0.17.0",
"@astrojs/image": "^0.17.3",
"@astrojs/mdx": "^0.19.7",
"@astrojs/partytown": "^2.0.2",
"@astrojs/rss": "^2.4.3",
"@astrojs/sitemap": "^1.3.3",
"@astrojs/partytown": "^2.1.1",
"@astrojs/rss": "^2.4.4",
"@astrojs/sitemap": "^1.4.0",
"@astrojs/tailwind": "^3.1.3",
"astro": "^2.6.1",
"daisyui": "^3.0.3",
"dayjs": "^1.11.8",
"sharp": "^0.32.1"
"astro": "^2.10.15",
"daisyui": "^3.9.4",
"dayjs": "^1.11.13",
"sharp": "^0.32.6"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9"
"@tailwindcss/typography": "^0.5.14"
}
}
5 changes: 3 additions & 2 deletions src/components/SideBarMenu.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const activeClass = "bg-base-300"; // For primary color replace with `active` cl

<ul class="menu grow shrink menu-md overflow-y-auto">
<li><a class="py-3 text-base" id="home" href="/">Home</a></li>
<li><a class="py-3 text-base" id="news" href="/news">News</a></li>
<li><a class="py-3 text-base" id="competitions" href="/competitions">Competitions</a></li>
<li><a class="py-3 text-base" id="event" href="/event">Event</a></li>
<li><a class="py-3 text-base" id="events" href="/events">Events</a></li>
<!-- <li><a class="py-3 text-base" id="store" href="/store">Store</a></li> -->
<li><a class="py-3 text-base" id="blog" href="/blog/">Blog</a></li>
<li><a class="py-3 text-base" id="cv" href="/cv">CV</a></li>
<li><a class="py-3 text-base" id="members" href="/members">Members</a></li>
<li>
<a
class="py-3 text-base"
Expand Down
File renamed without changes.
26 changes: 25 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,40 @@ const competitionsSchema = z.object({
badge: z.string().optional(),
});

const eventsSchema = z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
updatedDate: z.string().optional(),
heroImage: z.string().optional(),
badge: z.string().optional(),
});

const newsSchema = z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
updatedDate: z.string().optional(),
heroImage: z.string().optional(),
badge: z.string().optional(),
});

export type BlogSchema = z.infer<typeof blogSchema>;
export type StoreSchema = z.infer<typeof storeSchema>;
export type CompetitionsSchema = z.infer<typeof competitionsSchema>;
export type EventsSchema = z.infer<typeof eventsSchema>;
export type NewsSchema = z.infer<typeof newsSchema>;

const blogCollection = defineCollection({ schema: blogSchema });
const storeCollection = defineCollection({ schema: storeSchema });
const competitionsCollection = defineCollection({ schema: competitionsSchema });
const eventsCollection = defineCollection({ schema: eventsSchema });
const newsCollection = defineCollection({ schema: newsSchema });

export const collections = {
'blog': blogCollection,
'store': storeCollection,
'competitions': competitionsCollection
'competitions': competitionsCollection,
'events': eventsCollection,
'news': newsCollection,
}
File renamed without changes.
39 changes: 39 additions & 0 deletions src/content/news/news_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: "News"
description: "News description"
pubDate: "Aug 25 2024"
heroImage: "/social_img.jpg"
badge: "NEW"
---

<!-- CSS Code: Place this code in the document's head (between the 'head' tags) -->
<style>
table.GeneratedTable {
width: 100%;
background-color: #ffffff;
border-collapse: collapse;
border-width: 2px;
border-color: #68624b;
border-style: solid;
color: #000000;
}

table.GeneratedTable td, table.GeneratedTable th {
border-width: 2px;
border-color: #68624b;
border-style: solid;
padding: 3px;
}

table.GeneratedTable thead {
background-color: #ffcc00;
}

.highlight-red-text {
color: #FF0000; /* 這是一個代表紅色的色碼,亮紅色 */
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); /* 添加文字陰影 */
}

</style>

#### 新聞測試
2 changes: 1 addition & 1 deletion src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { image, title = SITE_TITLE, description = SITE_DESCRIPTION, includeSideba
<div class="drawer-content bg-base-100">
<Header title={SITE_TITLE} />
<div class="md:flex md:justify-center">
<main class="p-6 pt-10 max-w-[900px]">
<main class="p-6 pt-10 basis-[900px]">
<slot />
</main>
</div>
Expand Down
48 changes: 48 additions & 0 deletions src/layouts/EventsLayout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
import { EventsSchema } from "../content/config";
import BaseLayout from "./BaseLayout.astro";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
export interface Props extends EventsSchema {}
const { title, description, pubDate, updatedDate, heroImage, badge } =
Astro.props;
dayjs.extend(localizedFormat);
const displayDate = dayjs(pubDate).format("ll");
import { Image } from "@astrojs/image/components";
---

<BaseLayout title={title} description={description} image={heroImage}>
<main class="md:flex md:justify-center">
<article class="prose prose-lg max-w-[750px] prose-img:mx-auto">
{
heroImage && (
<Image
aspectRatio={"16:9"}
width={750}
height={422}
format="webp"
src={heroImage}
alt={title}
class="w-full mb-6"
/>
)
}
<h1 class="title my-2 text-4xl font-bold">{title}</h1>
{pubDate && <time>{displayDate}</time>}
<br />
{badge && <div class="badge badge-secondary my-1">{badge}</div>}
{
updatedDate && (
<div>
{" "}
Last updated on <time>{updatedDate}</time>{" "}
</div>
)
}
<div class="divider my-2"></div>
<slot />
</article>
</main>
</BaseLayout>
48 changes: 48 additions & 0 deletions src/layouts/NewsLayout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
import { NewsSchema } from "../content/config";
import BaseLayout from "./BaseLayout.astro";
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
export interface Props extends NewsSchema {}
const { title, description, pubDate, updatedDate, heroImage, badge } =
Astro.props;
dayjs.extend(localizedFormat);
const displayDate = dayjs(pubDate).format("ll");
import { Image } from "@astrojs/image/components";
---

<BaseLayout title={title} description={description} image={heroImage}>
<main class="md:flex md:justify-center">
<article class="prose prose-lg max-w-[750px] prose-img:mx-auto">
{
heroImage && (
<Image
aspectRatio={"16:9"}
width={750}
height={422}
format="webp"
src={heroImage}
alt={title}
class="w-full mb-6"
/>
)
}
<h1 class="title my-2 text-4xl font-bold">{title}</h1>
{pubDate && <time>{displayDate}</time>}
<br />
{badge && <div class="badge badge-secondary my-1">{badge}</div>}
{
updatedDate && (
<div>
{" "}
Last updated on <time>{updatedDate}</time>{" "}
</div>
)
}
<div class="divider my-2"></div>
<slot />
</article>
</main>
</BaseLayout>
85 changes: 85 additions & 0 deletions src/pages/events/[...page].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
import BaseLayout from "../../layouts/BaseLayout.astro";
import HorizontalCard from "../../components/HorizontalCard.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths({ paginate }) {
const posts = await getCollection("events");
posts.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
return paginate(posts, { pageSize: 10 });
}
const { page } = Astro.props;
---

<BaseLayout title="Events" sideBarActiveItemID="events">
<div class="mb-5">
<div class="text-3xl w-full font-bold">Events</div>
</div>

{
page.data.length === 0 ? (
<div class="bg-base-200 border-l-4 border-secondary w-full p-4 min-w-full">
<p class="font-bold">Sorry!</p>
<p>There are no events posts to show at the moment. Check back later!</p>
</div>
) : (
<ul>
{page.data.map((post) => (
<>
<HorizontalCard
title={post.data.title}
img={post.data.heroImage}
desc={post.data.description}
url={"/events/" + post.slug}
target="_self"
badge={post.data.badge}
/>
<div class="divider my-0" />
</>
))}
</ul>
)
}

<div class="flex justify-between">
{
page.url.prev ? (
<a href={page.url.prev} class="btn btn-ghost my-10 mx-5">
{" "}
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />
</svg>{" "}
Recent posts
</a>
) : (
<div />
)
}
{
page.url.next ? (
<a href={page.url.next} class="btn btn-ghost my-10 mx-5">
Older Posts{" "}
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
{" "}
<path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" />
</svg>
</a>
) : (
<div />
)
}
</div>
</BaseLayout>
30 changes: 30 additions & 0 deletions src/pages/events/[slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
import { CollectionEntry, getCollection } from 'astro:content';
import { EventsSchema } from '../../content/config';
import EventLayout from '../../layouts/EventsLayout.astro';
export async function getStaticPaths() {
const EventEntries = await getCollection('events');
return EventEntries.map(entry => ( {
params: { slug: entry.slug }, props: { entry },
} ));
}
interface Props {
entry: CollectionEntry<"events">;
}
const { entry } = Astro.props;
const Event : EventsSchema = entry.data;
const { Content } = await entry.render();
---

<EventLayout
title={Event.title}
description={Event.description}
pubDate={Event.pubDate}
heroImage={Event.heroImage}
updatedDate={Event.updatedDate}
badge={Event.badge}>
<Content/>
</EventLayout>
Loading

0 comments on commit 8fefc5c

Please sign in to comment.