Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Jul 19, 2016

This commit adds a GitInfo object to Page if EnableGitInfo is set.

It then also sets Lastmod for the given Page to the author date provided by Git.

The Git integrations should be fairly performant, but it adds "some time" to the build, somewhat depending on the Git history size.

If you want, you can run without during development and turn it on when deploying to the live server: hugo --enableGitInfo.

Fixes #2102

@bep
Copy link
Member Author

bep commented Jul 19, 2016

This should work:

git -C /Users/bep/go/src/github.com/spf13/hugo/ log --name-only --format=format:"%t|%aN|%aE|%ai|%s" HEAD
@bep
Copy link
Member Author

bep commented Jul 20, 2016

I have updated the PR. There are still some small holes, but it is complete enough to know that it is doable.

So if other could chime in with their opinions about:

  1. Is this a good idea? (I know I want it)
  2. Does this implementation make sense?
  3. Does setting Lastmod make sense?

/cc @spf13

@bep bep force-pushed the gitinfo branch 3 times, most recently from 316a2e5 to 13893e6 Compare July 20, 2016 09:37
@moorereason
Copy link
Contributor

Haven't tested this, but I like the idea. 👍

Is the AbbreviatedHash necessary? That could be derived later from the Hash if you needed it.

@bep
Copy link
Member Author

bep commented Jul 25, 2016

Is the AbbreviatedHash necessary?

You get it for free, and that is the value I want to show on my pages (if any); it's not possible to derive it from the Hash from inside of a Hugo template.

@moorereason
Copy link
Contributor

{{ substr .GitInfo.Hash 0 -7 }}
@bep
Copy link
Member Author

bep commented Jul 25, 2016

{{ substr .GitInfo.Hash 0 -7 }}

Which assumes 7 is a constant value.

@moorereason
Copy link
Contributor

My understanding was that it's configurable (via the core.abbrev setting). Defaults to 7. If you change the setting in your repo, you could update your template to match.

I just thought we could save memory allocs, but it's not that much of a win to drop it. You win. :)

@bep
Copy link
Member Author

bep commented Jul 25, 2016

You kind of got a point, but it is simplest to let Git and the Git config win ... The memory loss is ... not much. Maybe Git-Junio will invent some smart "sliding abbreviated" hashes in the future ... Which is only length 3 for small repos ...

@bep
Copy link
Member Author

bep commented Oct 24, 2016

Note to self: Maybe add a CLI flag for this as well, to make it easier to switch it off when in server mode etc.

@bep bep force-pushed the gitinfo branch 10 times, most recently from 30f1276 to 6aa03c3 Compare October 29, 2016 16:06
This commit adds a `GitInfo` object to `Page` if `EnableGitInfo` is set.

It then also sets `Lastmod` for the given `Page` to the author date provided by Git.

The Git integrations should be fairly performant, but it adds "some time" to the build, somewhat depending on the Git history size.

If you want, you can run without during development and turn it on when deploying to the live server: `hugo --enableGitInfo`.

Fixes gohugoio#2102
@bep bep changed the title Work in progress: Add GitInfo Oct 29, 2016
@bep
Copy link
Member Author

bep commented Oct 29, 2016

This is ready now. It needs some docs, but that will have to wait.

/cc @digitalcraftsman @moorereason @spf13 and gang.

@bep bep merged commit e8380e6 into gohugoio:master Nov 1, 2016
@bep bep deleted the gitinfo branch April 18, 2017 09:19
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

3 participants