File tree Expand file tree Collapse file tree 3 files changed +27
-10
lines changed
Expand file tree Collapse file tree 3 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,26 @@ export async function getSortedPostsDataWithContent(): Promise<PostData[]> {
105105 ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( )
106106 ) ;
107107}
108+
109+ export type PostMeta = PostFrontmatter & {
110+ id : string ;
111+ } ;
112+
113+ export function getPostsMetaOnly ( ) : PostMeta [ ] {
114+ const allFiles = getAllMdxFiles ( ) ;
115+
116+ const allPostsMeta : PostMeta [ ] = allFiles . map ( ( fullPath ) => {
117+ const id = extractIdFromFilename ( fullPath ) ;
118+ const fileContents = fs . readFileSync ( fullPath , 'utf8' ) ;
119+ const { data } = matter ( fileContents ) ;
120+
121+ return {
122+ id,
123+ ...( data as PostFrontmatter ) ,
124+ } ;
125+ } ) ;
126+
127+ return allPostsMeta . sort (
128+ ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( )
129+ ) ;
130+ }
Original file line number Diff line number Diff line change 11import Link from 'next/link' ;
22import Header from '../components/Header' ;
33import Footer from '../components/Footer' ;
4- import { MDXRemoteSerializeResult } from 'next-mdx-remote' ;
54import { GetStaticProps } from 'next' ;
6- import { getSortedPostsDataWithContent } from '../lib/posts' ;
5+ import { getPostsMetaOnly , getSortedPostsDataWithContent } from '../lib/posts' ;
76import AdSense from '../components/AdSense' ;
87
98const gradients = [
@@ -21,15 +20,13 @@ type Post = {
2120 title : string ;
2221 summary ?: string ;
2322 description ?: string ;
24- mdxSource : MDXRemoteSerializeResult < Record < string , unknown > > ;
2523} ;
2624
2725type HomeProps = {
2826 allPostsData : Post [ ] ;
2927 gradientsForPosts : string [ ] ;
3028} ;
3129
32- // Fisher-Yates 셔플
3330function shuffle < T > ( array : T [ ] ) : T [ ] {
3431 const copy = [ ...array ] ;
3532 for ( let i = copy . length - 1 ; i > 0 ; i -- ) {
@@ -40,12 +37,11 @@ function shuffle<T>(array: T[]): T[] {
4037}
4138
4239export const getStaticProps : GetStaticProps < HomeProps > = async ( ) => {
43- const allPostsData = await getSortedPostsDataWithContent ( ) ;
40+ const allPostsData = getPostsMetaOnly ( ) ;
4441 const [ latest , ...restAll ] = allPostsData ;
4542
4643 const rest = restAll . filter ( ( post ) => post . id !== latest . id ) . slice ( 0 , 3 ) ;
4744
48- // 서버에서 고정된 랜덤 gradient 선택 (중복 방지)
4945 const gradientsForPosts = shuffle ( gradients ) . slice ( 0 , rest . length ) ;
5046
5147 return {
Original file line number Diff line number Diff line change @@ -2,16 +2,14 @@ import { useState, useEffect } from 'react';
22import Link from 'next/link' ;
33import Header from '../components/Header' ;
44import { GetStaticProps } from 'next' ;
5- import { getSortedPostsDataWithContent } from '../lib/posts' ;
6- import { MDXRemoteSerializeResult } from 'next-mdx-remote' ;
5+ import { getPostsMetaOnly } from '../lib/posts' ;
76
87type Post = {
98 id : string ;
109 title : string ;
1110 summary ?: string ;
1211 description ?: string ;
1312 tags ?: string [ ] ;
14- mdxSource : MDXRemoteSerializeResult ;
1513} ;
1614
1715type Props = {
@@ -20,7 +18,7 @@ type Props = {
2018} ;
2119
2220export const getStaticProps : GetStaticProps < Props > = async ( ) => {
23- const posts = await getSortedPostsDataWithContent ( ) ;
21+ const posts = getPostsMetaOnly ( ) ;
2422
2523 const postsByTag : Record < string , Post [ ] > = { } ;
2624 const tagCounts : Record < string , number > = { } ;
You can’t perform that action at this time.
0 commit comments