1- import { LOCALE } from "@config" ;
1+ import { LOCALE , SITE } from "@config" ;
2+ import type { CollectionEntry } from "astro:content" ;
23
34interface DatetimesProps {
45 pubDatetime : string | Date ;
56 modDatetime : string | Date | undefined | null ;
67}
78
8- interface Props extends DatetimesProps {
9+ interface EditPostProps {
10+ editPost ?: CollectionEntry < "blog" > [ "data" ] [ "editPost" ] ;
11+ postId ?: CollectionEntry < "blog" > [ "id" ] ;
12+ }
13+
14+ interface Props extends DatetimesProps , EditPostProps {
915 size ?: "sm" | "lg" ;
1016 className ?: string ;
1117}
@@ -15,6 +21,8 @@ export default function Datetime({
1521 modDatetime,
1622 size = "sm" ,
1723 className = "" ,
24+ editPost,
25+ postId,
1826} : Props ) {
1927 return (
2028 < div
@@ -42,6 +50,7 @@ export default function Datetime({
4250 pubDatetime = { pubDatetime }
4351 modDatetime = { modDatetime }
4452 />
53+ { size === "lg" && < EditPost editPost = { editPost } postId = { postId } /> }
4554 </ span >
4655 </ div >
4756 ) ;
@@ -72,3 +81,40 @@ const FormattedDatetime = ({ pubDatetime, modDatetime }: DatetimesProps) => {
7281 </ >
7382 ) ;
7483} ;
84+
85+ const EditPost = ( { editPost, postId } : EditPostProps ) => {
86+ let editPostUrl = editPost ?. url ?? SITE ?. editPost ?. url ?? "" ;
87+ const showEditPost = ! editPost ?. disabled && editPostUrl . length > 0 ;
88+ const appendFilePath =
89+ editPost ?. appendFilePath ?? SITE ?. editPost ?. appendFilePath ?? false ;
90+ if ( appendFilePath && postId ) {
91+ editPostUrl += `/${ postId } ` ;
92+ }
93+ const editPostText = editPost ?. text ?? SITE ?. editPost ?. text ?? "Edit" ;
94+
95+ return (
96+ showEditPost && (
97+ < >
98+ < span aria-hidden = "true" > | </ span >
99+ < a
100+ className = "space-x-1.5 hover:opacity-75"
101+ href = { editPostUrl }
102+ rel = "noopener noreferrer"
103+ target = "_blank"
104+ >
105+ < svg
106+ xmlns = "http://www.w3.org/2000/svg"
107+ className = "icon icon-tabler icons-tabler-outline icon-tabler-edit inline-block !scale-90 fill-skin-base"
108+ aria-hidden = "true"
109+ >
110+ < path stroke = "none" d = "M0 0h24v24H0z" fill = "none" />
111+ < path d = "M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" />
112+ < path d = "M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
113+ < path d = "M16 5l3 3" />
114+ </ svg >
115+ < span className = "text-base italic" > { editPostText } </ span >
116+ </ a >
117+ </ >
118+ )
119+ ) ;
120+ } ;
0 commit comments