Merge pull request #97 from Music47ell/v1
refactor: use formatDate util
This commit is contained in:
		| @@ -3,8 +3,7 @@ import Tag from '@/components/Tag' | ||||
| import siteMetadata from '@/data/siteMetadata' | ||||
| import { useState } from 'react' | ||||
| import Pagination from '@/components/Pagination' | ||||
|  | ||||
| const postDateTemplate = { year: 'numeric', month: 'long', day: 'numeric' } | ||||
| import formatDate from '@/lib/utils/formatDate' | ||||
|  | ||||
| export default function ListLayout({ posts, title, initialDisplayPosts = [], pagination }) { | ||||
|   const [searchValue, setSearchValue] = useState('') | ||||
| @@ -58,9 +57,7 @@ export default function ListLayout({ posts, title, initialDisplayPosts = [], pag | ||||
|                   <dl> | ||||
|                     <dt className="sr-only">Published on</dt> | ||||
|                     <dd className="text-base font-medium leading-6 text-gray-500 dark:text-gray-400"> | ||||
|                       <time dateTime={date}> | ||||
|                         {new Date(date).toLocaleDateString(siteMetadata.locale, postDateTemplate)} | ||||
|                       </time> | ||||
|                       <time dateTime={date}>{formatDate(date)}</time> | ||||
|                     </dd> | ||||
|                   </dl> | ||||
|                   <div className="space-y-3 xl:col-span-3"> | ||||
|   | ||||
| @@ -3,8 +3,7 @@ import PageTitle from '@/components/PageTitle' | ||||
| import SectionContainer from '@/components/SectionContainer' | ||||
| import { BlogSeo } from '@/components/SEO' | ||||
| import siteMetadata from '@/data/siteMetadata' | ||||
|  | ||||
| const postDateTemplate = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' } | ||||
| import formatDate from '@/lib/utils/formatDate' | ||||
|  | ||||
| export default function PostLayout({ frontMatter, authorDetails, next, prev, children }) { | ||||
|   const { date, title } = frontMatter | ||||
| @@ -20,9 +19,7 @@ export default function PostLayout({ frontMatter, authorDetails, next, prev, chi | ||||
|                 <div> | ||||
|                   <dt className="sr-only">Published on</dt> | ||||
|                   <dd className="text-base font-medium leading-6 text-gray-500 dark:text-gray-400"> | ||||
|                     <time dateTime={date}> | ||||
|                       {new Date(date).toLocaleDateString(siteMetadata.locale, postDateTemplate)} | ||||
|                     </time> | ||||
|                     <time dateTime={date}>{formatDate(date)}</time> | ||||
|                   </dd> | ||||
|                 </div> | ||||
|               </dl> | ||||
|   | ||||
							
								
								
									
										14
									
								
								lib/utils/formatDate.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								lib/utils/formatDate.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import siteMetadata from '@/data/siteMetadata' | ||||
|  | ||||
| const formatDate = (date) => { | ||||
|   const options = { | ||||
|     year: 'numeric', | ||||
|     month: 'long', | ||||
|     day: 'numeric', | ||||
|   } | ||||
|   const now = new Date(date).toLocaleDateString(siteMetadata.locale, options) | ||||
|  | ||||
|   return now | ||||
| } | ||||
|  | ||||
| export default formatDate | ||||
| @@ -3,9 +3,9 @@ import { PageSeo } from '@/components/SEO' | ||||
| import Tag from '@/components/Tag' | ||||
| import siteMetadata from '@/data/siteMetadata' | ||||
| import { getAllFilesFrontMatter } from '@/lib/mdx' | ||||
| import formatDate from '@/lib/utils/formatDate' | ||||
|  | ||||
| const MAX_DISPLAY = 5 | ||||
| const postDateTemplate = { year: 'numeric', month: 'long', day: 'numeric' } | ||||
|  | ||||
| export async function getStaticProps() { | ||||
|   const posts = await getAllFilesFrontMatter('blog') | ||||
| @@ -37,9 +37,7 @@ export default function Home({ posts }) { | ||||
|                     <dl> | ||||
|                       <dt className="sr-only">Published on</dt> | ||||
|                       <dd className="text-base font-medium leading-6 text-gray-500 dark:text-gray-400"> | ||||
|                         <time dateTime={date}> | ||||
|                           {new Date(date).toLocaleDateString(siteMetadata.locale, postDateTemplate)} | ||||
|                         </time> | ||||
|                         <time dateTime={date}>{formatDate(date)}</time> | ||||
|                       </dd> | ||||
|                     </dl> | ||||
|                     <div className="space-y-5 xl:col-span-3"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user