Skip to content

Commit

Permalink
last modified: add debug logs for prod errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ooloth committed Dec 23, 2024
1 parent bfd7bcf commit 939cb67
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/remark/last-modified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@ import { resolve } from 'path'

function remarkModifiedTime() {
return function (tree, file) {

Check failure on line 7 in lib/remark/last-modified.ts

View workflow job for this annotation

GitHub Actions / Format, lint and check types

Parameter 'tree' implicitly has an 'any' type.

Check failure on line 7 in lib/remark/last-modified.ts

View workflow job for this annotation

GitHub Actions / Format, lint and check types

Parameter 'file' implicitly has an 'any' type.
console.log('tree:', tree)
console.log('file:', file)
const filepath = file.history[0]
console.log('filepath:', filepath)

if (!filepath) {
console.error('Error: filepath is undefined')
return
}

try {
// Resolve the absolute path of the file
const absoluteFilePath = resolve(filepath)
console.log('absoluteFilePath:', absoluteFilePath)

// Get the root directory of the repository
const repoRoot = execSync('git rev-parse --show-toplevel').toString().trim()
console.log('repoRoot:', repoRoot)

// Get the relative path of the file from the repository root
const relativeFilePath = absoluteFilePath.replace(`${repoRoot}/`, '')
console.log('relativeFilePath:', relativeFilePath)

// Check if the file is within a submodule
const submodulePath = execSync(`git submodule foreach --quiet 'echo $path'`)
.toString()
.trim()
.split('\n')
.find(submodule => relativeFilePath.startsWith(submodule))
console.log('submodulePath:', submodulePath)

let result
if (submodulePath) {
Expand All @@ -40,6 +52,7 @@ function remarkModifiedTime() {
}

file.data.astro.frontmatter.lastModified = result
console.log('lastModified:', result)
} catch (error) {
console.error('Error getting last modified time:', error)
}
Expand Down

0 comments on commit 939cb67

Please sign in to comment.