Skip to content

Commit

Permalink
ignore for home page
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Jan 18, 2025
1 parent 46eaebe commit 4c8d4d3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions .vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function getGitCreationDate(filePath) {
try {
// Extract file name from path
const fileName = path.basename(filePath);

// Use case-insensitive search for the file name
const cmd = `git log --diff-filter=A --format=%at -- "*${fileName}"`
const timestamp = execSync(cmd, { encoding: 'utf-8' }).trim();

// Convert git timestamp to Date
return new Date(parseInt(timestamp) * 1000);
} catch (e) {
Expand Down Expand Up @@ -103,12 +103,18 @@ export default defineConfig({
},
transformPageData(pageData) {
const relativePath = pageData.relativePath

if (!relativePath) {
console.log('No relative path found for page')
return
}

// Ignore file creation date for index.md
if (relativePath === 'index.md') {
// console.log('Ignoring file creation date for index.md')
return
}

// Get absolute path
const filePath = path.resolve(process.cwd(), relativePath)

Expand All @@ -121,7 +127,7 @@ export default defineConfig({
const createdAt = getGitCreationDate(filePath)
// Ensure frontmatter exists
pageData.frontmatter = pageData.frontmatter || {}

// Add both timestamp and formatted date
pageData.frontmatter.createdAt = createdAt
pageData.frontmatter.createdAtFormatted = createdAt.toLocaleDateString('en-US', {
Expand Down

0 comments on commit 4c8d4d3

Please sign in to comment.