random selection of project proposals
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { MDXRemote } from "next-mdx-remote/rsc";
|
import { MDXRemote } from "next-mdx-remote/rsc";
|
||||||
import { getAllProjects, getProjectBySlug, getProjectSlugs } from "@/lib/projects/get-projects";
|
import { getProjectBySlug, getProjectSlugs, getRandomOtherProjects } from "@/lib/projects/get-projects";
|
||||||
import { mdxComponents } from "@/components/mdx/mdxComponents";
|
import { mdxComponents } from "@/components/mdx/mdxComponents";
|
||||||
import { ProjectHero } from "@/app/[locale]/works/_components/ProjectHero";
|
import { ProjectHero } from "@/app/[locale]/works/_components/ProjectHero";
|
||||||
import { ProjectMeta } from "@/app/[locale]/works/_components/ProjectMeta";
|
import { ProjectMeta } from "@/app/[locale]/works/_components/ProjectMeta";
|
||||||
@@ -38,10 +38,7 @@ export default async function ProjectPage({ params }: props) {
|
|||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const otherProjects = getAllProjects(locale)
|
const otherProjects = getRandomOtherProjects(locale, slug, 2).map((item) => ({
|
||||||
.filter((item: any) => item.slug !== slug && item.ready)
|
|
||||||
.slice(0, 2)
|
|
||||||
.map((item: any) => ({
|
|
||||||
slug: item.slug,
|
slug: item.slug,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
|
|||||||
@@ -42,3 +42,16 @@ export function getAllProjects(locale: string): Project[] {
|
|||||||
.filter((project): project is Project => project !== null)
|
.filter((project): project is Project => project !== null)
|
||||||
.sort((a, b) => a.priority - b.priority);
|
.sort((a, b) => a.priority - b.priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRandomOtherProjects(locale: string, excludeSlug: string, count: number): Project[] {
|
||||||
|
const candidates = getAllProjects(locale).filter(
|
||||||
|
(project) => project.slug !== excludeSlug && project.ready
|
||||||
|
);
|
||||||
|
|
||||||
|
for (let i = candidates.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[candidates[i], candidates[j]] = [candidates[j], candidates[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates.slice(0, count);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user