From d6d75eff3782e4f7a5cef509f087197823793c35 Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Sun, 21 Dec 2025 01:45:28 -0700 Subject: [PATCH] Fixed RSS date/time --- .env.example | 3 +++ .github/workflows/deploy.yml | 2 ++ Dockerfile | 12 +++--------- docker-compose.yml | 1 + src/pages/rss.xml.js | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8407751 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +# RSS Feed Configuration +# Will default to GMT +PUBLIC_RSS_TIMEZONE=America/Edmonton diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index abea909..d67040d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -30,6 +30,8 @@ jobs: context: . platforms: linux/amd64 push: true + build-args: | + PUBLIC_RSS_TIMEZONE=${{ vars.PUBLIC_RSS_TIMEZONE }} tags: | ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }} ${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest diff --git a/Dockerfile b/Dockerfile index 3475f79..8ec9c7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,35 +46,29 @@ RUN --mount=type=cache,id=pnpm,target=/.pnpm-store \ FROM build-deps AS builder -# Copy source code +ARG PUBLIC_RSS_TIMEZONE +ENV PUBLIC_RSS_TIMEZONE=${PUBLIC_RSS_TIMEZONE} + COPY . . -# Build the application RUN pnpm run build FROM node:24-alpine AS runtime -# Install pnpm for runtime RUN npm install -g pnpm WORKDIR /app -# Copy built application COPY --from=builder /app/dist ./dist -# Copy production dependencies COPY --from=deps /app/node_modules ./node_modules -# Copy package.json for any runtime needs COPY package.json ./ -# Set environment variables ENV HOST=0.0.0.0 \ PORT=4321 \ NODE_ENV=production -# Expose port EXPOSE 4321 -# Start the application CMD ["node", "./dist/server/entry.mjs"] diff --git a/docker-compose.yml b/docker-compose.yml index 438bdf1..b75f4fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,5 @@ services: - "${APP_PORT}:4321" environment: NODE_ENV: production + PUBLIC_RSS_TIMEZONE: ${PUBLIC_RSS_TIMEZONE:-} restart: unless-stopped diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 6bd68aa..1a29fe6 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -1,6 +1,38 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; +function formatPubDate(date) { + const timezone = process.env.PUBLIC_RSS_TIMEZONE + ? process.env.PUBLIC_RSS_TIMEZONE + : import.meta.env.PUBLIC_RSS_TIMEZONE; + + if (!timezone) { + return date; + } + + try { + const year = date.getUTCFullYear(); + const month = String(date.getUTCMonth() + 1).padStart(2, '0'); + const day = String(date.getUTCDate()).padStart(2, '0'); + + const formatter = new Intl.DateTimeFormat('en-US', { + timeZone: timezone, + timeZoneName: 'longOffset', + }); + + const parts = formatter.formatToParts(date); + const offsetPart = parts.find(p => p.type === 'timeZoneName'); + const offset = offsetPart ? offsetPart.value.replace('GMT', '') : '+00:00'; + + const dateStr = `${year}-${month}-${day}T00:00:00${offset}`; + + return new Date(dateStr); + } catch (e) { + console.warn(`Invalid timezone "${timezone}":`, e.message); + return date; + } +} + export async function GET(context) { const posts = await getCollection('posts'); @@ -10,7 +42,7 @@ export async function GET(context) { site: context.site, items: posts.map((post) => ({ title: post.data.title, - pubDate: post.data.pubDate, + pubDate: formatPubDate(post.data.pubDate), description: post.data.description || '', link: `/post/${post.slug}/`, })),