Clanek: Weitere Artikel brez istega izvajalca (tudi ne istega kot clanek)
This commit is contained in:
@@ -15,6 +15,7 @@ import DOMPurify from "dompurify";
|
||||
import ShareButtons from "@/components/share-buttons";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useFocalPoints, objectPositionFor } from "@/lib/focal";
|
||||
import { artistGroup } from "@/lib/artists";
|
||||
|
||||
const ALLOWED_IFRAME_DOMAINS = [
|
||||
"iframe.mediadelivery.net",
|
||||
@@ -57,12 +58,35 @@ function ArticleSkeleton() {
|
||||
);
|
||||
}
|
||||
|
||||
function RelatedArticles({ currentSlug }: { currentSlug: string }) {
|
||||
function RelatedArticles({ currentSlug, currentTitle }: { currentSlug: string; currentTitle?: string }) {
|
||||
const { data: articles } = useQuery<Article[]>({
|
||||
queryKey: ["/api/articles/popular"],
|
||||
});
|
||||
|
||||
const filtered = articles?.filter((a) => a.slug !== currentSlug);
|
||||
// Pod clankom ne sme stati clanek o istem izvajalcu (niti o istem, kot je
|
||||
// clanek sam) - bralcu izgleda kot podvojitev.
|
||||
const filtered = useMemo(() => {
|
||||
const list = (articles || []).filter((a) => a.slug !== currentSlug);
|
||||
const g0 = artistGroup(currentTitle || "");
|
||||
const seen = new Set<string>(g0 ? [g0] : []);
|
||||
const out: Article[] = [];
|
||||
for (const a of list) {
|
||||
const g = artistGroup(a.title || "");
|
||||
if (g && seen.has(g)) continue;
|
||||
if (g) seen.add(g);
|
||||
out.push(a);
|
||||
if (out.length >= 3) break;
|
||||
}
|
||||
if (out.length < 3) {
|
||||
for (const a of list) {
|
||||
if (out.indexOf(a) < 0) {
|
||||
out.push(a);
|
||||
if (out.length >= 3) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}, [articles, currentSlug, currentTitle]);
|
||||
const focalPoints = useFocalPoints();
|
||||
|
||||
if (!filtered || filtered.length === 0) return null;
|
||||
@@ -436,7 +460,7 @@ export default function ArticlePage() {
|
||||
<MultiplexAd />
|
||||
</div>
|
||||
|
||||
<RelatedArticles currentSlug={slug || ""} />
|
||||
<RelatedArticles currentSlug={slug || ""} currentTitle={article?.title} />
|
||||
</main>
|
||||
<Footer narrow />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user