Skip to content

Commit

Permalink
Merge pull request #20 from azvyae/hotfix/infinite-redirections
Browse files Browse the repository at this point in the history
Infinite redirection fixed
  • Loading branch information
Azvya Erstevan authored Aug 21, 2024
2 parents aaa77cc + 643deed commit ab4ba77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/app/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ function MostHighlightedStory({ story }: { story?: StoriesIndexEntry }) {
function LatestStories({ stories }: { stories: StoriesIndexEntry[] }) {
return (
<section data-item="latest-stories-section" className="px-8 md:px-16 py-8">
<h4 className="text-left text-3xl font-bold mb-6">Latest Stories</h4>
{stories.length > 0 && (
<h4 className="text-left text-3xl font-bold mb-6">Latest Stories</h4>
)}
{stories.length === 0 && (
<p className="text-left text-3xl font-bold mb-6">
No published stories yet
</p>
)}
<div className="grid gap-8 sm:grid-cols-2 xl:grid-cols-4 mb-6">
{stories.map((index, k) => (
<StoryCard story={index} key={k} />
Expand Down
10 changes: 5 additions & 5 deletions src/app/stories/sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readFileSync } from 'fs';
import jsonata from 'jsonata';
import Image from 'next/image';
import Link from 'next/link';
import { notFound, redirect } from 'next/navigation';
import { redirect } from 'next/navigation';
import path from 'path';
import { cache } from 'react';
import { FiChevronLeft, FiChevronRight } from 'react-icons/fi';
Expand Down Expand Up @@ -53,17 +53,17 @@ async function listStories(
}
const expression = jsonata(query);
const result: StoriesIndexEntry[] = await expression.evaluate(indexStories);

const maxPage = Math.ceil(result.length / 6);
return {
total: query === `$[]` ? meta.totalStories : result.length,
result: result.slice((page - 1) * 6, 6 * page) ?? [],
maxPage: Math.ceil(result.length / 6),
maxPage: maxPage === 0 ? 1 : maxPage,
};
} catch (error) {
return {
total: 0,
result: [],
maxPage: 0,
maxPage: 1,
};
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ async function FilteringSection({
}) {
const meta = await checkMeta();
if (category && !meta.categories.includes(category)) {
return notFound();
return redirect('/stories');
}
return (
<section data-item="stories-filter" className="relative px-2 w-full">
Expand Down
2 changes: 1 addition & 1 deletion src/components/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Link from 'next/link';

function Footer() {
return (
<footer className="w-full pt-10 px-8 xl:px-32 sm:pt-20">
<footer className="w-full pt-10 px-8 xl:px-32 sm:pt-20 relative">
<div className="w-full mx-auto transition-colors md:items-center duration-500 bg-[#FAFBFC] dark:bg-bgdark grid md:grid-cols-3 items-start justify-between gap-8 py-4 md:gap-2.5 max-w-screen-2k">
<Link className="inline-block h-10 py-2" href={'/'}>
<Image
Expand Down

0 comments on commit ab4ba77

Please sign in to comment.