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

找不到this.$page.lastUpdated #1

Open
codeLove9 opened this issue Apr 12, 2023 · 0 comments
Open

找不到this.$page.lastUpdated #1

codeLove9 opened this issue Apr 12, 2023 · 0 comments

Comments

@codeLove9
Copy link
Owner

源码地址: https://www.npmjs.com/package/@vuepress/plugin-last-updated?activeTab=code

这是一个使用JavaScript编写的VuePress插件脚本,用于获取页面源文件的最后一次Git提交时间戳,并将其添加到页面元数据中。以下是代码的概述:

  1. 它从Node.js导入了两个模块:path和cross-spawn包中的spawn。

  2. 它导出一个函数,该函数接受两个参数:options和context,并返回包含名为extendPageData的方法的对象。

  3. extendPageData方法检索当前页面源文件的Git时间戳,并将其作为lastUpdated和lastUpdatedTimestamp属性添加到$page对象中。

  4. 如果提供了options.transformer函数,则使用它来将时间戳格式化为字符串表示形式;否则使用脚本中定义的defaultTransformer函数。

  5. getGitLastUpdatedTimeStamp函数获取页面的文件路径,并使用spawn模块运行Git命令以检索修改文件的最后一次提交时间戳。然后解析并返回自Unix纪元以来的时间戳值(毫秒)。

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

No branches or pull requests

1 participant