Skip to content

Commit

Permalink
おすすめをもっと見る
Browse files Browse the repository at this point in the history
  • Loading branch information
eatski committed Apr 6, 2024
1 parent c285acf commit 109fb50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/storyList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const StoryList: React.FC<{ stories: Item[]; seeMoreUrl?: string }> = ({
</ul>
{seeMoreUrl && (
<div className={styles.seeMore}>
<Link className={components.buttonLink} href="/stories">
<Link className={components.buttonLink} href={seeMoreUrl}>
もっと見る
</Link>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
getStories({
count: 5,
}),
getStoriesRecommended(),
getStoriesRecommended(8),
]);
return {
props: {
Expand All @@ -44,7 +44,7 @@ export default function Home({ stories, recommend }: Props) {
</div>
<section style={{ marginBottom: "24px" }}>
<H2 label="おすすめストーリー" />
<StoryList stories={recommend} />
<StoryList stories={recommend} seeMoreUrl={"/stories/rank"} />
</section>
<div style={{ marginBottom: "24px" }}>
<RecommendCreateStory />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/stories/rank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
};

export const getStaticProps: GetStaticProps<Props> = async () => {
const stories = await getStoriesRecommended();
const stories = await getStoriesRecommended(30);
return {
props: {
stories: stories.map((story) => ({
Expand Down
8 changes: 5 additions & 3 deletions src/server/services/story/ranking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { StoryHead } from "@/server/model/story";
const ONE_DAY = 1000 * 60 * 60 * 24;
const ONE_MONTH = ONE_DAY * 30;

export const getStoriesRecommended = async (): Promise<StoryHead[]> => {
export const getStoriesRecommended = async (
count: number,
): Promise<StoryHead[]> => {
const now = Date.now();
// すべてのストーリーを取得
const stories = await prisma.story.findMany({
Expand All @@ -32,7 +34,7 @@ export const getStoriesRecommended = async (): Promise<StoryHead[]> => {
orderBy: {
publishedAt: "desc",
},
take: 50,
take: 100,
});
const scoredStories = stories.map((story) => {
const { questionLogs, evaluations, solutionLogs, ...rest } = story;
Expand Down Expand Up @@ -64,5 +66,5 @@ export const getStoriesRecommended = async (): Promise<StoryHead[]> => {
};
});
scoredStories.sort((a, b) => b.score - a.score);
return scoredStories.map((e) => e.story).slice(0, 8);
return scoredStories.map((e) => e.story).slice(0, count);
};

0 comments on commit 109fb50

Please sign in to comment.