Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add modified time #1839

Closed
wants to merge 11 commits into from
Closed

feat: add modified time #1839

wants to merge 11 commits into from

Conversation

Barbapapazes
Copy link
Contributor

@Barbapapazes Barbapapazes commented Jan 22, 2023

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Jan 22, 2023

βœ… Deploy Preview for nuxt-content canceled.

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit 18f06ea
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-content/deploys/63f9ce641946450008ade6ad

@Barbapapazes
Copy link
Contributor Author

Can use unjs/unstorage#136

@Barbapapazes
Copy link
Contributor Author

Unfortunately, the created time can't be get from unstorage because it create a new file and return time from this new file.

@Barbapapazes Barbapapazes marked this pull request as draft February 25, 2023 09:28
@Barbapapazes
Copy link
Contributor Author

After deeper investigations, it seems that unstorage won't help to solve this issue (adding the created at time). (unstorage will only help for the updatedAt meta. But because using this method, we can't get createdAt, I think it's not the best option.)

However, in the file src/runtime/markdown-parser/index.ts, at the line 57, there is a function called parseFrontMatter which return content and data. And because the parse method return a meta object, I think we could use it to get updatedAtand createdAt.
Unfortunaly, this could be a solution but git does not store timestamps. (https://stackoverflow.com/questions/62039244/does-git-store-the-file-creation-time).

So, there is no way to easily get creation date from a content file.

@Benbinbin
Copy link
Contributor

Benbinbin commented Mar 30, 2023

I also want to figure out how to get the created and updated time.

Checked out the starckoverflow you mention above, the answer provides an idea: each commit has timestamp

So my solution is searching the added commit and last updated commit associated with the specify file and get the timestamp

I write a server plugin for my Nuxt Content project BlogiNote

/**
 * add timestamp for markdown file
 */
import { execSync } from 'node:child_process'
// ...

export default defineNitroPlugin((nitroApp) => {
   // ...
    const firstCommitTime = execSync(`git log --diff-filter=A --format=%as -- ${filePath}`, { encoding: 'utf-8' }).trim();

   // ...
    const lastCommitTime = execSync(`git log -1 --format=%as -- ${filePath}`, { encoding: 'utf-8' }).trim();

 // ...
})

This won't be the precise time as the created and updated, and it works!

However I encouter another problem, this method just work fine locally.

When I deploy to Vercel, because the .git directory is not deployed, so it fail to get the commit time from git log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants