Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,37 @@ async function get_articles_by_query(
).map(fixArticleCoverImage) as [ReceivedArticle];
return articles;
}

async function get_articles_by_recommended(
title: string,
text: string,
num_of_articles?: number,
department?: string,
): Promise<ReceivedArticle[]> {
const db = (await clientPromise).db();
let articles_collection = await db.collection("articles");
const limit = num_of_articles || 10;
let articles = (
await articles_collection
.aggregate([
{ $match: department },
{
$search: {
index: "default",
text: {
query: text,
path: "text",
}
},
}
])
.limit(limit)
.toArray()
).map(fixArticleCoverImage) as ReceivedArticle[];
return articles;
}


async function get_articles_by_string_query(
query: string,
num?: number
Expand Down Expand Up @@ -365,4 +396,5 @@ export {
get_staffs_by_query,
get_media_by_author,
get_articles_by_string_query,
get_articles_by_recommended,
};
8 changes: 7 additions & 1 deletion pages/article/[article_slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import styles from "../../styles/[article_slug].module.css";
import ShareButton from "../../components/ShareButton";
import Link from "next/link";
import generate_contributors_jsx from "../../components/GenerateContributorsJSX";
import { get_articles_by_recommended } from "../../db";

interface Props {
article: ReceivedArticle;
Expand All @@ -29,7 +30,12 @@ const Article = (props: Props) => {
cover_image_contributor,
cover_image_source,
} = props.article;


function RecommendedArticle(props: ReceivedArticle) {
return (
<div> Article </div>
);
}
const generateApproxReadingTime = () => {
let count = text.split(" ");
let readTime = Math.round(count.length / 250); // average reading time in min
Expand Down