@@ -15,10 +15,18 @@ import {
1515import type { PluginOptions } from '@docusaurus/types' ;
1616
1717export type LastUpdateData = {
18- /** A timestamp in **milliseconds**, usually read from `git log` */
19- lastUpdatedAt ?: number ;
20- /** The author's name, usually coming from `git log` */
21- lastUpdatedBy ?: string ;
18+ /**
19+ * A timestamp in **milliseconds**, usually read from `git log`
20+ * `undefined`: not read
21+ * `null`: no value to read (usual for untracked files)
22+ */
23+ lastUpdatedAt : number | undefined | null ;
24+ /**
25+ * The author's name, usually coming from `git log`
26+ * `undefined`: not read
27+ * `null`: no value to read (usual for untracked files)
28+ */
29+ lastUpdatedBy : string | undefined | null ;
2230} ;
2331
2432let showedGitRequirementError = false ;
@@ -68,9 +76,15 @@ export const LAST_UPDATE_FALLBACK: LastUpdateData = {
6876 lastUpdatedBy : 'Author' ,
6977} ;
7078
79+ // Not proud of this, but convenient for tests :/
80+ export const LAST_UPDATE_UNTRACKED_GIT_FILEPATH = `file/path/${ Math . random ( ) } .mdx` ;
81+
7182export async function getLastUpdate (
7283 filePath : string ,
7384) : Promise < LastUpdateData | null > {
85+ if ( filePath === LAST_UPDATE_UNTRACKED_GIT_FILEPATH ) {
86+ return null ;
87+ }
7488 if (
7589 process . env . NODE_ENV !== 'production' ||
7690 process . env . DOCUSAURUS_DISABLE_LAST_UPDATE === 'true'
@@ -103,7 +117,7 @@ export async function readLastUpdateData(
103117 const { showLastUpdateAuthor, showLastUpdateTime} = options ;
104118
105119 if ( ! showLastUpdateAuthor && ! showLastUpdateTime ) {
106- return { } ;
120+ return { lastUpdatedBy : undefined , lastUpdatedAt : undefined } ;
107121 }
108122
109123 const frontMatterAuthor = lastUpdateFrontMatter ?. author ;
@@ -116,9 +130,21 @@ export async function readLastUpdateData(
116130 // If all the data is provided as front matter, we do not call it
117131 const getLastUpdateMemoized = _ . memoize ( ( ) => getLastUpdate ( filePath ) ) ;
118132 const getLastUpdateBy = ( ) =>
119- getLastUpdateMemoized ( ) . then ( ( update ) => update ?. lastUpdatedBy ) ;
133+ getLastUpdateMemoized ( ) . then ( ( update ) => {
134+ // Important, see https://github.com/facebook/docusaurus/pull/11211
135+ if ( update === null ) {
136+ return null ;
137+ }
138+ return update ?. lastUpdatedBy ;
139+ } ) ;
120140 const getLastUpdateAt = ( ) =>
121- getLastUpdateMemoized ( ) . then ( ( update ) => update ?. lastUpdatedAt ) ;
141+ getLastUpdateMemoized ( ) . then ( ( update ) => {
142+ // Important, see https://github.com/facebook/docusaurus/pull/11211
143+ if ( update === null ) {
144+ return null ;
145+ }
146+ return update ?. lastUpdatedAt ;
147+ } ) ;
122148
123149 const lastUpdatedBy = showLastUpdateAuthor
124150 ? frontMatterAuthor ?? ( await getLastUpdateBy ( ) )
0 commit comments