feat: Improve banner fetching logic and integrate Banner component
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
- Adjusted server logic in `/banners/active` to resolve timezone issues and ensure consistent date handling. - Sorted active banners by creation date in descending order for better relevance. - Integrated `Banner.astro` component into the homepage layout for displaying active banners.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import { FastifyPluginAsync } from 'fastify';
|
import { FastifyPluginAsync } from 'fastify';
|
||||||
import { db } from '../config/database.js';
|
import { db } from '../config/database.js';
|
||||||
import { banners } from '../db/schema.js';
|
import { banners } from '../db/schema.js';
|
||||||
import { eq, and, lte, gte } from 'drizzle-orm';
|
import { eq, and, lte, gte, desc } from 'drizzle-orm';
|
||||||
|
|
||||||
const bannerBodyJsonSchema = {
|
const bannerBodyJsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -18,7 +18,11 @@ const bannersRoute: FastifyPluginAsync = async (fastify) => {
|
|||||||
|
|
||||||
// Get active banner (public endpoint)
|
// Get active banner (public endpoint)
|
||||||
fastify.get('/banners/active', async (request, reply) => {
|
fastify.get('/banners/active', async (request, reply) => {
|
||||||
const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD
|
// Use local date to avoid timezone issues
|
||||||
|
const now = new Date();
|
||||||
|
const today = new Date(now.getTime() - (now.getTimezoneOffset() * 60000))
|
||||||
|
.toISOString()
|
||||||
|
.split('T')[0]; // YYYY-MM-DD
|
||||||
|
|
||||||
const [activeBanner] = await db
|
const [activeBanner] = await db
|
||||||
.select()
|
.select()
|
||||||
@ -30,6 +34,7 @@ const bannersRoute: FastifyPluginAsync = async (fastify) => {
|
|||||||
gte(banners.endDate, today)
|
gte(banners.endDate, today)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.orderBy(desc(banners.createdAt))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!activeBanner) {
|
if (!activeBanner) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
import Layout from "../components/Layout.astro";
|
import Layout from "../components/Layout.astro";
|
||||||
|
import Banner from "../components/Banner.astro";
|
||||||
import Hero from "../components/Hero.astro";
|
import Hero from "../components/Hero.astro";
|
||||||
import Welcome from "../components/Welcome.astro";
|
import Welcome from "../components/Welcome.astro";
|
||||||
import EventsGrid from "../components/EventsGrid.astro";
|
import EventsGrid from "../components/EventsGrid.astro";
|
||||||
@ -75,6 +76,7 @@ const images = [
|
|||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
|
<Banner />
|
||||||
<Hero id="hero" />
|
<Hero id="hero" />
|
||||||
<Welcome id="welcome" />
|
<Welcome id="welcome" />
|
||||||
<EventsGrid id="events" events={events} />
|
<EventsGrid id="events" events={events} />
|
||||||
|
|||||||
Reference in New Issue
Block a user