markup icon indicating copy to clipboard operation
markup copied to clipboard

Placeholder for hash of current commit in README.md file

Open mkczyk opened this issue 5 years ago • 21 comments

Preface

To link to specific file in README.md we have some several ways (#1, #2):

1. Link to latest version of file in specific branch:

https://github.com/mkczyk/test-experiment/blob/master/index.html

2. Permanent link to specific version (commit) of file:

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

We have to know SHA of commit, so it is not possible to place this link in README.me in the same commit (we don't know what hash will be generated).

3. Relative link do file.

Markdown:

[index.html](index.html)

This will be dynamically replaced with (rendered):

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Feature request

I would like to be able to specify a placeholder that would be automatically replaced with the current hash of current commit.

For example. Markdown:

This commit have hash: {current-commit-id}

Rendered:

This commit have hash: d7a4c7953d2b9084ca520eeb4434dd6d6689880d

Related issue/feature

I know that there was related feature request https://github.com/github/markup/issues/913 (https://github.com/github/markup/issues/472) with placeholder for branch name. And as I understood this isn't easy to implement.

But this issue refers to SHA of commit, not branch name. This feature looks looks similar to relative link do file (the 3. way to create a link).

Rendering from/to exists:

[index.html](index.html)
https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Maybe rendering from/to is easier to implement than rendering branch name:

{current-commit-id}
d7a4c7953d2b9084ca520eeb4434dd6d6689880d

Motivation for requesting feature

Primary motivation

I'm looking for a way to show demo of my HTML/JS code, separately for every commit (not only for last version of file).

I've researched several ways here: https://stackoverflow.com/questions/62740362/how-to-show-demo-with-html-and-javascript-d3-js-on-github-for-every-commit

It seems that closest to success is using external service for serving HTML directly from GitHub file. There are several services of that kind: HtmlPreview, RawGit, raw.githack.com.

Example link for preview of HTML file (specific version of file):

https://rawcdn.githack.com/mkczyk/test-experiment/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

You can see I need hash to create this link (I want to place this link in README.md).

If the placeholder existed I could easily create link. Markdown:

https://rawcdn.githack.com/mkczyk/test-experiment/{current-commit-id}/index.html

Rendered:

https://rawcdn.githack.com/mkczyk/test-experiment/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

With this you can see demo for every historical commit.

Secondary motivation

In this related issue https://github.com/github/markup/issues/913 motivation is sending branch name to external service. If he could send hash of commit, maybe he can easily get branch name in external tool (there you usually have access to the entire Git repository) and it could be sufficient to archive his goal.

Another variant of feature request

If this is hard to implement I got an idea that can be easier to implement: relative link as text.

If this:

[index.html](index.html)

can be rendered to:

https://github.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

and more specifically (in view) to:

<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

Maybe this can be rendered in view just as plain text?

/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

For example placeholder: {raw-url}.

With this I could build this URL:

https://rawcdn.githack.com{raw-url}

That will be rendered as:

https://rawcdn.githack.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

And this will also solve my problem.

(Bad) shortcut for implementing another variant

I've got another idea (that doesn't seem good). If this / is rendered on view like this:

[index.html](index.html)
<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

Maybe it would be enough to support custom <base> tag. For example configuring this in README.md:

<base href="https://rawcdn.githack.com">

And markdown with relative link:

[index.html](index.html)

will be rendered as:

<a href="/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html">index.html</a>

But clicking on it redirect to:

https://rawcdn.githack.com/mkczyk/test-experiment/blob/d7a4c7953d2b9084ca520eeb4434dd6d6689880d/index.html

Instead of standard this:

https://github.com/mkczyk/test-experiment/blob/master/index.html

Supporting <base> tag was mentioned here https://github.com/github/markup/issues/84#issuecomment-3220586, but I think the same it is not good idea (Because what about the rest of the relative links? It will be broken).

mkczyk avatar Jul 07 '20 21:07 mkczyk

I would like to second this request, and add the following use case:

As the author of a paper whose drafts I share publicaly on github, I would like to include a Cite Me section in the readme. There I would like to share a github code block of a BibText file as well as a rendered text indicating how one may cite the draft. Both blocks should contain the short version of the revision being quoted as well as the comitt date.

koraa avatar Jun 23 '21 11:06 koraa

This would be really useful. And I also would like to reference past commits in a similar way.

Example: {{ HEAD^2 }}

danisztls avatar Jun 25 '21 21:06 danisztls

This would be super handy for commit-based package management, like for example, in Bazel WORKSPACEs

cpsauer avatar Jan 26 '22 03:01 cpsauer

This would be useful for clojure deps.edn projects, where dependency information can be shared as

{:git/sha "abcdefg"}

bowbahdoe avatar May 15 '22 13:05 bowbahdoe