Skip to content

Commit

Permalink
Improved rss now accept until param
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolive committed Dec 28, 2023
1 parent c43da54 commit d96d7f9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Feed } from "feed";

const getAllArticles = async () => {
const getAllArticles = async (days = 14) => {
const { getCalendarEvents } = require("@lib/helpers");

const now = new Date();
const from = new Date();
const until = new Date(now.setDate(now.getDate() + 14));
const until = new Date(now.setDate(now.getDate() + days));

const { events } = await getCalendarEvents({
from,
Expand Down Expand Up @@ -67,9 +67,10 @@ const buildFeed = (items) => {

export const getServerSideProps = async (context) => {
if (context && context.res) {
const { res } = context;
const { res, query } = context;
const days = query.until || 14;

const articles = await getAllArticles();
const articles = await getAllArticles(days);

const feed = buildFeed(articles);
res.setHeader("content-type", "text/xml");
Expand Down

1 comment on commit d96d7f9

@vercel
Copy link

@vercel vercel bot commented on d96d7f9 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.