@@ -191,21 +191,39 @@ export default defineComponent({
191191 } ,
192192 } ,
193193
194- mtimeOpacity ( ) {
195- const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
194+ mtime ( ) {
195+ // If the mtime is not a valid date, return it as is
196+ if ( this . source . mtime && ! isNaN ( this . source . mtime . getDate ( ) ) ) {
197+ return this . source . mtime
198+ }
199+
200+ if ( this . source . crtime && ! isNaN ( this . source . crtime . getDate ( ) ) ) {
201+ return this . source . crtime
202+ }
196203
197- const mtime = this . source . mtime ?. getTime ?.( )
198- if ( ! mtime ) {
204+ return null
205+ } ,
206+
207+ mtimeOpacity ( ) {
208+ if ( ! this . mtime ) {
199209 return { }
200210 }
201211
202- // 1 = today, 0 = 31 days ago
203- const ratio = Math . round ( Math . min ( 100 , 100 * ( maxOpacityTime - ( Date . now ( ) - mtime ) ) / maxOpacityTime ) )
204- if ( ratio < 0 ) {
212+ // The time when we start reducing the opacity
213+ const maxOpacityTime = 31 * 24 * 60 * 60 * 1000 // 31 days
214+ // everything older than the maxOpacityTime will have the same value
215+ const timeDiff = Date . now ( ) - this . mtime . getTime ( )
216+ if ( timeDiff < 0 ) {
217+ // this means we have an invalid mtime which is in the future!
205218 return { }
206219 }
220+
221+ // inversed time difference from 0 to maxOpacityTime (which would mean today)
222+ const opacityTime = Math . max ( 0 , maxOpacityTime - timeDiff )
223+ // 100 = today, 0 = 31 days ago or older
224+ const percentage = Math . round ( opacityTime * 100 / maxOpacityTime )
207225 return {
208- color : `color-mix(in srgb, var(--color-main-text) ${ ratio } %, var(--color-text-maxcontrast))` ,
226+ color : `color-mix(in srgb, var(--color-main-text) ${ percentage } %, var(--color-text-maxcontrast))` ,
209227 }
210228 } ,
211229
0 commit comments