fix(transformer): find last modified date form commit on submodule (#1831)
* fix(transformer): find last modified date form commit on submodule when the content folder has a submodule git, the relative path start in content folder and not root folder of quartz * fix(transformer): use path.relative for improved path handling in last modified date calculation * fix(transformer): keep find file from relative path of repo workdir * fix(transformer): use variable for repository workdir use default value if repo.workdir is undefined to user fullFp value
This commit is contained in:
		@@ -2,6 +2,7 @@ import fs from "fs"
 | 
				
			|||||||
import { Repository } from "@napi-rs/simple-git"
 | 
					import { Repository } from "@napi-rs/simple-git"
 | 
				
			||||||
import { QuartzTransformerPlugin } from "../types"
 | 
					import { QuartzTransformerPlugin } from "../types"
 | 
				
			||||||
import chalk from "chalk"
 | 
					import chalk from "chalk"
 | 
				
			||||||
 | 
					import path from "path"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface Options {
 | 
					export interface Options {
 | 
				
			||||||
  priority: ("frontmatter" | "git" | "filesystem")[]
 | 
					  priority: ("frontmatter" | "git" | "filesystem")[]
 | 
				
			||||||
@@ -34,9 +35,11 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
 | 
				
			|||||||
      return [
 | 
					      return [
 | 
				
			||||||
        () => {
 | 
					        () => {
 | 
				
			||||||
          let repo: Repository | undefined = undefined
 | 
					          let repo: Repository | undefined = undefined
 | 
				
			||||||
 | 
					          let repositoryWorkdir: string
 | 
				
			||||||
          if (opts.priority.includes("git")) {
 | 
					          if (opts.priority.includes("git")) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
              repo = Repository.discover(ctx.argv.directory)
 | 
					              repo = Repository.discover(ctx.argv.directory)
 | 
				
			||||||
 | 
					              repositoryWorkdir = repo.workdir() ?? ""
 | 
				
			||||||
            } catch (e) {
 | 
					            } catch (e) {
 | 
				
			||||||
              console.log(
 | 
					              console.log(
 | 
				
			||||||
                chalk.yellow(`\nWarning: couldn't find git repository for ${ctx.argv.directory}`),
 | 
					                chalk.yellow(`\nWarning: couldn't find git repository for ${ctx.argv.directory}`),
 | 
				
			||||||
@@ -62,7 +65,8 @@ export const CreatedModifiedDate: QuartzTransformerPlugin<Partial<Options>> = (u
 | 
				
			|||||||
                published ||= file.data.frontmatter.published as MaybeDate
 | 
					                published ||= file.data.frontmatter.published as MaybeDate
 | 
				
			||||||
              } else if (source === "git" && repo) {
 | 
					              } else if (source === "git" && repo) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                  modified ||= await repo.getFileLatestModifiedDateAsync(fullFp)
 | 
					                  const relativePath = path.relative(repositoryWorkdir, fullFp)
 | 
				
			||||||
 | 
					                  modified ||= await repo.getFileLatestModifiedDateAsync(relativePath)
 | 
				
			||||||
                } catch {
 | 
					                } catch {
 | 
				
			||||||
                  console.log(
 | 
					                  console.log(
 | 
				
			||||||
                    chalk.yellow(
 | 
					                    chalk.yellow(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user