英文:
Is there a way to automatically add timestamp of a file's last commit in Github README.md file?
问题
假设一个Github仓库有多个文件。在README.md中,我可以按照以下方式为这些文件命名并提供链接:
[test1.py](path/to/test1.py)
[test2.py](path/to/test2.py)
我想要添加每个文件最后更新的时间戳,并将其与文件的路径一起显示。我不想获取仓库中最后提交的时间戳,而只想分别获取每个文件的最后提交时间戳。
英文:
Suppose a Github repo has multiple files. In README.md, I can name those files and provide a link to each file as follows:
[test1.py](path/to/test1.py)
[test2.py](path/to/test2.py)
I would like to add the timestamp of when each of the file was last updated in the repo and show it along with the path to the file. I don't want to get the timestamp of the last commit in the repo, but only the timestamp of the last commit of each of the files separately
答案1
得分: 1
不,没有。Git没有提供一种自动包含生成信息在文件中的方式,除非通过.gitattributes
中的ident
和filter
功能,以及Git LFS文件(使用filter
功能),而GitHub在渲染文件时没有调用任何此类功能。
请注意,通常来说,README应该是简单的标记轻型(例如,Markdown或AsciiDoc)文件,人们可以在文本编辑器或less
中阅读,以及在渲染形式中阅读,并且不应包含任何高科技自动渲染的内容。这应该留给项目特定的网站,该网站可以根据项目的需求生成文件。
英文:
No, there isn't. Git doesn't provide a way to automatically include generated information in files other than through the ident
and filter
functionality in .gitattributes
, and outside of Git LFS files (which use the filter
functionality), GitHub doesn't call any such functionality when rendering files.
Note that in general, READMEs are supposed to be simple markup-light (e.g., Markdown or AsciiDoc) files that people can read in a text editor or less
as well as in rendered form, and aren't supposed to contain any sort of high-tech automated rendering. That should be left to a project-specific website which can generate files as the project needs.
答案2
得分: 0
@bk2204 很好地指出了,没有预处理是无法做到的。由于类似的需求非常频繁,我创建了一个用于预处理的工具。
您可以使用
https://github.com/verhas/jamal
编辑您的 README.md.jam 文件。该文件应包含带有 Jamal 元标记的增强型 Markdown 内容。Jamal 处理元标记,输出为纯粹的 Markdown,然后按照手动创建的方式进行处理。
您可以使用 Jamal 有超过 200 种不同的宏可能性。开箱即用,您可以查询文件的修改并在文档中显示它,使用 {@file (format=$time)fileName}
宏。
如果您需要不存在的功能,您可以用 Java 编写自己的宏或建议该功能。如果功能足够通用,我们可能会在下一个版本中实现它。
英文:
@bk2204 points out very well that you cannot do that without preprocessing. Since similar needs are so frequent, I created a tool for such preprocessing.
You can use
https://github.com/verhas/jamal
editing your README.md.jam file. This file should contain your Markdown content enriched with the Jamal meta markup. Jamal processes the meta markup, and the output is the pure Markdown, which is then processed as it was manually created.
There are more than 200 different macro possibilities that you can use with Jamal. Out of the box, you can query the modification of a file and display it in the document using the {@file (format=$time)fileName}
macro.
If you need something that does not exist, you can write your macro in Java or suggest the functionality. We may implement it for the next release if the functionality is general-purpose enough.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论