jekyll-git 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +45 -0
  3. data/.gitignore +22 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +84 -0
  8. data/Rakefile +8 -0
  9. data/jekyll-git_metadata.gemspec +29 -0
  10. data/lib/jekyll/git_metadata/generator.rb +151 -0
  11. data/lib/jekyll/git_metadata/version.rb +5 -0
  12. data/lib/jekyll/git_metadata.rb +8 -0
  13. data/lib/jekyll-git_metadata.rb +1 -0
  14. data/test/helper.rb +32 -0
  15. data/test/test_git_metadata.rb +227 -0
  16. data/test/test_repo/.gitignore +1 -0
  17. data/test/test_repo/_config.yml +17 -0
  18. data/test/test_repo/_gizmos/yoyo.md +9 -0
  19. data/test/test_repo/_includes/footer.html +61 -0
  20. data/test/test_repo/_includes/head.html +12 -0
  21. data/test/test_repo/_includes/header.html +28 -0
  22. data/test/test_repo/_layouts/default.html +19 -0
  23. data/test/test_repo/_layouts/page.html +14 -0
  24. data/test/test_repo/_layouts/post.html +15 -0
  25. data/test/test_repo/_posts/2014-07-14-welcome-to-jekyll.markdown +30 -0
  26. data/test/test_repo/about.md +11 -0
  27. data/test/test_repo/css/main.css +410 -0
  28. data/test/test_repo/dot_git/COMMIT_EDITMSG +1 -0
  29. data/test/test_repo/dot_git/HEAD +1 -0
  30. data/test/test_repo/dot_git/MERGE_RR +0 -0
  31. data/test/test_repo/dot_git/ORIG_HEAD +1 -0
  32. data/test/test_repo/dot_git/config +7 -0
  33. data/test/test_repo/dot_git/description +1 -0
  34. data/test/test_repo/dot_git/hooks/applypatch-msg.sample +15 -0
  35. data/test/test_repo/dot_git/hooks/commit-msg.sample +24 -0
  36. data/test/test_repo/dot_git/hooks/post-update.sample +8 -0
  37. data/test/test_repo/dot_git/hooks/pre-applypatch.sample +14 -0
  38. data/test/test_repo/dot_git/hooks/pre-commit.sample +49 -0
  39. data/test/test_repo/dot_git/hooks/pre-push.sample +54 -0
  40. data/test/test_repo/dot_git/hooks/pre-rebase.sample +169 -0
  41. data/test/test_repo/dot_git/hooks/prepare-commit-msg.sample +36 -0
  42. data/test/test_repo/dot_git/hooks/update.sample +128 -0
  43. data/test/test_repo/dot_git/index +0 -0
  44. data/test/test_repo/dot_git/info/exclude +6 -0
  45. data/test/test_repo/dot_git/logs/HEAD +9 -0
  46. data/test/test_repo/dot_git/logs/refs/heads/master +8 -0
  47. data/test/test_repo/dot_git/objects/00/26c4c5df4d5148a07b9fbd790620f4e11d0802 +0 -0
  48. data/test/test_repo/dot_git/objects/0a/842bc255214909543fb198145783107e735907 +0 -0
  49. data/test/test_repo/dot_git/objects/0b/6d4b0cffe0117537f4ac31c918588c394778ef +0 -0
  50. data/test/test_repo/dot_git/objects/0e/a9d20342677512902dde3175a73e1dd1059e67 +0 -0
  51. data/test/test_repo/dot_git/objects/13/30fa92b3c8d94ee3ebb645b04154e735c04cf1 +0 -0
  52. data/test/test_repo/dot_git/objects/1a/24ab60234bd846f0f1532f914d66ea986fadbb +0 -0
  53. data/test/test_repo/dot_git/objects/25/d62f6feeb7190483f81564f4a76c1ec33d5118 +0 -0
  54. data/test/test_repo/dot_git/objects/32/3a65e20f0feb846438bbda1a0396ea2db7616e +0 -0
  55. data/test/test_repo/dot_git/objects/32/fff15665e830f9bdd82ea46a906bd3cf1122b0 +1 -0
  56. data/test/test_repo/dot_git/objects/3d/32f2f8ec3470e6a88ad1f9096e539cec42a47a +0 -0
  57. data/test/test_repo/dot_git/objects/3e/d64bb62b98b0827096cda5da5a728ec1bf5e3e +1 -0
  58. data/test/test_repo/dot_git/objects/48/d97759a460f607e077eea99a2df7b3cd5a2601 +0 -0
  59. data/test/test_repo/dot_git/objects/4c/2dd956115a971f5376a998bc4b243022c8881e +0 -0
  60. data/test/test_repo/dot_git/objects/4d/1b13c2e1ef1c1a944aae52994682da833a5bef +1 -0
  61. data/test/test_repo/dot_git/objects/4d/7f8a4c1a1bac8d553ba169e18882a7f51235bd +0 -0
  62. data/test/test_repo/dot_git/objects/59/821b143fbc62850d08e3f70c70d02af08df684 +0 -0
  63. data/test/test_repo/dot_git/objects/59/bc060e8c1fbe31c985e00c6cc2fef3b46c0c62 +0 -0
  64. data/test/test_repo/dot_git/objects/60/9711c27d50b5ab6ecc7d8fd485082481f9fc4a +0 -0
  65. data/test/test_repo/dot_git/objects/62/61f5911f204a827c313081c33e2522f0dd457c +0 -0
  66. data/test/test_repo/dot_git/objects/70/343eb1287191b30371400048167253a883d6ca +0 -0
  67. data/test/test_repo/dot_git/objects/78/845656f899d0bfd86d2806b85b0c54adddd3c8 +0 -0
  68. data/test/test_repo/dot_git/objects/7f/9eb0e6044998d71653c06fdc6e359dfbfc4211 +0 -0
  69. data/test/test_repo/dot_git/objects/83/65a44c640d5c7cafc8788607a274dfd91b89bb +3 -0
  70. data/test/test_repo/dot_git/objects/83/8ad7a02ebe551a90bea885c94191667f29009c +1 -0
  71. data/test/test_repo/dot_git/objects/83/8daa5e0163161d6e47bd1b0d783ca7307066c6 +0 -0
  72. data/test/test_repo/dot_git/objects/88/090a3ea8ce80e49ea42d249836aaa25f257454 +0 -0
  73. data/test/test_repo/dot_git/objects/8d/1f788990d1f80ebcbe7b78c3e5c393b7a41943 +0 -0
  74. data/test/test_repo/dot_git/objects/99/117f666995e8836652d9590daa2fdcb4de8b2a +0 -0
  75. data/test/test_repo/dot_git/objects/9e/00340e45d33e52bb16100f1b613a36f82f9c57 +0 -0
  76. data/test/test_repo/dot_git/objects/a9/f5097c614e0d4be7f900c04d782d3b1d675ee2 +0 -0
  77. data/test/test_repo/dot_git/objects/ae/45638b71046b28d46a764d8a2f7780fec58c01 +1 -0
  78. data/test/test_repo/dot_git/objects/af/415865cd1f1c0a5963a5d45b1335856e23dae8 +0 -0
  79. data/test/test_repo/dot_git/objects/b8/ffd38affdd1cc22ee4cb830cbe5c398b4e3df1 +2 -0
  80. data/test/test_repo/dot_git/objects/ba/a938862bbe45533863069649b40fdebf59e81c +0 -0
  81. data/test/test_repo/dot_git/objects/c0/8f9add7a1d48045bec46451dfdbb5b5ebf8dc0 +0 -0
  82. data/test/test_repo/dot_git/objects/c8/f101653f2c1de3611232fc4c940246b06779cd +0 -0
  83. data/test/test_repo/dot_git/objects/da/077394cb4d5bf7ffac527dbfc652ec0592b423 +2 -0
  84. data/test/test_repo/dot_git/objects/e1/ec08bcf36967f7be9ec6df51c862cc86305f4f +3 -0
  85. data/test/test_repo/dot_git/objects/e3/c2be348eb0873f7ac3f500ae6daaa93ebd7959 +0 -0
  86. data/test/test_repo/dot_git/objects/e5/e6f26a0481e83434feb2de4ef29843c8a1b8b2 +0 -0
  87. data/test/test_repo/dot_git/objects/e7/76acafd9b27ddcdd8e8a2c973b1fa1ccd690ab +3 -0
  88. data/test/test_repo/dot_git/objects/ff/74852f93c8e337b7ae3088c31cfe8673def356 +0 -0
  89. data/test/test_repo/dot_git/refs/heads/master +1 -0
  90. data/test/test_repo/feed.xml +30 -0
  91. data/test/test_repo/index.html +20 -0
  92. metadata +280 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3e81fefb94077e191ada3164a4aae3b61b0a8213134818b155771c0267cb77f
4
+ data.tar.gz: 22a905b0b143b9ef49b453a008f033835c3c7dfadd2b7b0ca49e6ef1e4656223
5
+ SHA512:
6
+ metadata.gz: 5f3ddfa2e34d5c71ed90028a05525b10888442a00cc73d0064a7ab6187446e5671bcca7b9cb945f0fbe1fc242e12a7c15d945cfb29e83ae7404c90b9b8743be5
7
+ data.tar.gz: b194ccbf3caa47a2ffac402f6597bf9a1146aa8d0451f4055b2c1ee3d22bb2fd6892a46399c84fe144a5bdded82035e759a94d86275d4ffe9742f1d72905a41d
@@ -0,0 +1,45 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ os: [ ubuntu-24.04 ]
16
+ ruby: [ruby-3.3.4]
17
+ runs-on: ${{ matrix.os }}
18
+ permissions:
19
+ contents: read
20
+ packages: write
21
+
22
+ steps:
23
+
24
+ - uses: actions/checkout@v4
25
+ - name: Set up Ruby 2.6
26
+ id: ruby
27
+ run: |
28
+ ruby=${{ matrix.ruby }}
29
+ if [[ "$ruby" == [0-9]* ]]; then
30
+ ruby="ruby-$ruby"
31
+ fi
32
+ echo "ruby=$ruby" >> $GITHUB_OUTPUT
33
+ echo "archive=$ruby-${{ steps.platform.outputs.platform }}.tar.gz" >> $GITHUB_OUTPUT
34
+
35
+ - name: Publish to GPR
36
+ run: |
37
+ mkdir -p $HOME/.gem
38
+ touch $HOME/.gem/credentials
39
+ chmod 0600 $HOME/.gem/credentials
40
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
+ gem build *.gemspec
42
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
43
+ env:
44
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
45
+ OWNER: ${{ github.repository_owner }}
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ sudo: required
3
+ dist: trusty
4
+ script: bundle exec rake test
5
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-git_metadata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Tse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # 📝 Jekyll Git Metadata
2
+
3
+ > [!NOTE]
4
+ This is a fork of a [fork](https://github.com/b1r3k/jekyll-git_metadata) of a [gem](https://github.com/ivantsepp/jekyll-git_metadata) made for Jekyll 3. The previous fork was not published to any package registry (but made several very helpful additions) so this one serves as an accessible way to continue using the functionality of the original package in new Jekyll sites. You can see an example of the package in the footer of [this site](https://joshpinto6.github.io/doctored) and I plan on accepting contributions/improvements through PRs.
5
+
6
+ ## 👋 Introduction
7
+
8
+ Expose Git metadata to Jekyll. Just like how Github exposes [repository metadata](https://help.github.com/articles/repository-metadata-on-github-pages), this plugin will expose information about your git repository for your templates. For example:
9
+
10
+ ```
11
+ {{site.git.total_commits}} # => Will return the total number of commits for your Jekyll repository
12
+ ```
13
+
14
+ See [usage](#usage) for more detail on the schema of `site.git`.
15
+
16
+ ## 💾 Installation
17
+
18
+ My version of thie gem is installable from GitHub Package Registry (GPR)'s rubygems accesspoint.
19
+
20
+ > [!IMPORTANT]
21
+ > You must provide a GitHub access token with `read:packages` permission to install this package! This is just something that GPR requires and you can learn more about the ways to do it [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry#authenticating-with-a-personal-access-token) or see an example of how to implement this package in a GitHub action [here](https://github.com/joshpinto6/doctored/blob/main/.github/workflows/jekyll.yml)
22
+
23
+ Install with the command line:
24
+ ```bash
25
+ gem install jekyll-git_metadata
26
+ ```
27
+
28
+ Add to your `Gemfile`:
29
+
30
+ ```
31
+ source "https://rubygems.pkg.github.com/joshpinto6" do
32
+ gem "jekyll-git_metadata"
33
+ end
34
+ ```
35
+
36
+ Add to your `_config.yml`:
37
+
38
+ ```yml
39
+ gems:
40
+ - jekyll-git_metadata
41
+ ```
42
+
43
+ ## ⌨️ Usage
44
+
45
+ This plugin adds a hash of git information to the `site` and `page` variables. The hash looks something like this:
46
+
47
+ ```
48
+ {"authors"=>
49
+ [
50
+ {"commits"=>2, "name"=>"Ivan Tse", "email"=>"ivan@example.com"},
51
+ {"commits"=>5, "name"=>"John Smith", "email"=>"john@example.com"}
52
+ ],
53
+ "total_commits"=>7,
54
+ "total_additions"=>57,
55
+ "total_subtractions"=>22,
56
+ "first_commit"=>
57
+ {"short_sha"=>"d15cbe8",
58
+ "long_sha"=>"d15cbe8d0f4d4db9efda7a3daabbe966c21f3848",
59
+ "author_name"=>"John Smith",
60
+ "author_email"=>"john@example.com",
61
+ "author_date"=>"Thu Jan 16 23:36:00 2014 -0500",
62
+ "commit_name"=>"John Smith",
63
+ "commit_email"=>"john@example.com",
64
+ "commit_date"=>"Thu Jan 16 23:36:00 2014 -0500",
65
+ "message"=>"A commit!"},
66
+ "last_commit"=>
67
+ {"short_sha"=>"f88ca3b",
68
+ "long_sha"=>"f88ca3bff630efb6cdb356fad3d640534b109572",
69
+ "author_name"=>"Ivan Tse",
70
+ "author_email"=>"ivan@example.com",
71
+ "author_date"=>"Mon Jul 14 04:04:47 2014 -0400",
72
+ "commit_name"=>"John Smith",
73
+ "commit_email"=>"john@example.com",
74
+ "commit_date"=>"Mon Jul 14 04:04:47 2014 -0400",
75
+ "message"=>"Fix some stuff"}}
76
+ ```
77
+
78
+ To access this hash, use either `page.git` or `site.git`. `page.git` contains the git information about that particuliar page/file. `site.git` contains the git information for the entire git repository. `site.git` also includes `total_files` and `project_name` variables.
79
+
80
+ ## 🙌 Acknowledgements
81
+
82
+ - [Ivan Tse](https://github.com/ivantsepp) - The package's original author/maintainer (2017)
83
+ - [Łukasz Jachym ](https://github.com/b1r3k) - For forking the original and making improvements (2023)
84
+ - Me
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/test_*.rb']
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/git_metadata/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-git"
8
+ spec.version = Jekyll::GitMetadata::VERSION
9
+ spec.authors = ["joshpinto6"]
10
+ spec.email = [""]
11
+ spec.summary = %q{Expose Git metadata to Jekyll.}
12
+ spec.description = %q{Get access to Git information in your Jekyll templates}
13
+ spec.homepage = "https://github.com/joshpinto6/jekyll-git"
14
+ spec.license = "MIT"
15
+ spec.metadata["homepage"] = "https://github.com/joshpinto6/jekyll"
16
+ spec.metadata["source_code_uri"] = "https://github.com/joshpinto6/jekyll-git"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "jekyll", '~> 4.0'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "shoulda"
28
+ spec.add_development_dependency "mocha"
29
+ end
@@ -0,0 +1,151 @@
1
+ require 'rbconfig'
2
+
3
+ module Jekyll
4
+ module GitMetadata
5
+ class Generator < Jekyll::Generator
6
+
7
+ safe true
8
+
9
+ def generate(site)
10
+ raise "Git is not installed" unless git_installed?
11
+
12
+ Dir.chdir(site.source) do
13
+ data = load_git_metadata(site)
14
+ site.config['git'] = data['site_data']
15
+ jekyll_items(site).each do |page|
16
+ if page.is_a?(Jekyll::Page)
17
+ path = page.path
18
+ else
19
+ path = page.relative_path
20
+ end
21
+ page.data['git'] = data['pages_data'][path]
22
+ end
23
+ end
24
+ end
25
+
26
+ def load_git_metadata(site)
27
+
28
+ current_sha = %x{ git rev-parse HEAD }.strip
29
+
30
+ cache_dir = site.source + '/.git-metadata'
31
+ FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
32
+ cache_file = cache_dir + "/#{current_sha}.json"
33
+
34
+ if File.exist?(cache_file)
35
+ cached = JSON.parse(IO.read(cache_file))
36
+ # deserialize dates into Time objects
37
+ new_commits = cached['site_data']['commits'].map do |commit|
38
+ commit.merge('commit_date' => Time.parse(commit['commit_date']))
39
+ end
40
+ cached['site_data']['commits'] = new_commits
41
+ return cached
42
+ end
43
+
44
+ pages_data = {}
45
+ jekyll_items(site).each do |page|
46
+ if page.is_a?(Jekyll::Page)
47
+ path = page.path
48
+ else
49
+ path = page.relative_path
50
+ end
51
+ pages_data[path] = page_data(path)
52
+ end
53
+ data = { 'site_data' => site_data, 'pages_data' => pages_data }
54
+
55
+ File.open(cache_file, 'w') { |f| f.write(data.to_json) }
56
+
57
+ data
58
+ end
59
+
60
+ def site_data
61
+ {
62
+ 'project_name' => project_name,
63
+ 'files_count' => files_count,
64
+ }.merge!(page_data)
65
+ end
66
+
67
+ def page_data(relative_path = nil)
68
+ return if relative_path && !tracked_files.include?(relative_path)
69
+
70
+ authors = self.authors(relative_path)
71
+ lines = self.lines(relative_path)
72
+ {
73
+ 'authors' => authors,
74
+ 'total_commits' => authors.inject(0) { |sum, h| sum += h['commits'] },
75
+ 'total_additions' => lines.inject(0) { |sum, h| sum += h['additions'] },
76
+ 'total_subtractions' => lines.inject(0) { |sum, h| sum += h['subtractions'] },
77
+ 'commits' => lines.map { |line| commit(line['sha']) }, # Get commit data for each line
78
+ 'first_commit' => commit(lines.last['sha']),
79
+ 'last_commit' => commit(lines.first['sha'])
80
+ }
81
+ end
82
+
83
+ def authors(file = nil)
84
+ results = []
85
+ cmd = 'git shortlog -se HEAD'
86
+ cmd << " -- #{file}" if file
87
+ result = %x{ #{cmd} }
88
+ result.lines.each do |line|
89
+ commits, name, email = line.scan(/(.*)\t(.*)<(.*)>/).first.map(&:strip)
90
+ results << { 'commits' => commits.to_i, 'name' => name, 'email' => email }
91
+ end
92
+ results
93
+ end
94
+
95
+ def lines(file = nil)
96
+ cmd = "git log --numstat --format=%h"
97
+ cmd << " -- #{file}" if file
98
+ result = %x{ #{cmd} }
99
+ results = result.scan(/(.*)\n\n((?:.*\t.*\t.*\n)*)/)
100
+ results.map do |line|
101
+ files = line[1].scan(/(.*)\t(.*)\t(.*)\n/)
102
+ line[1] = files.inject(0){|s,a| s+=a[0].to_i}
103
+ line[2] = files.inject(0){|s,a| s+=a[1].to_i}
104
+ end
105
+ results.map do |line|
106
+ { 'sha' => line[0], 'additions' => line[1], 'subtractions' => line[2] }
107
+ end
108
+ end
109
+
110
+ def commit(sha)
111
+ result = %x{ git show --format=fuller --name-only #{sha} }
112
+ long_sha, author_name, author_email, author_date, commit_name, commit_email, commit_date, message, changed_files = result.scan(/commit (.*)\nAuthor:(.*)<(.*)>\nAuthorDate:(.*)\nCommit:(.*)<(.*)>\nCommitDate:(.*)\n\n((?:\s\s\s\s[^\r\n]*\n)*)\n(.*)/m).first.map(&:strip)
113
+ {
114
+ 'short_sha' => sha,
115
+ 'long_sha' => long_sha,
116
+ 'author_name' => author_name,
117
+ 'author_email' => author_email,
118
+ 'author_date' => author_date,
119
+ 'commit_name' => commit_name,
120
+ 'commit_email' => commit_email,
121
+ 'commit_date' => Time.strptime(commit_date, '%a %b %d %H:%M:%S %Y %z'),
122
+ 'message' => message.gsub(/ /, ''),
123
+ 'changed_files' => changed_files.split("\n")
124
+ }
125
+ end
126
+
127
+ def tracked_files
128
+ @tracked_files ||= %x{ git ls-tree --full-tree -r --name-only HEAD }.split("\n")
129
+ end
130
+
131
+ def project_name
132
+ File.basename(%x{ git rev-parse --show-toplevel }.strip)
133
+ end
134
+
135
+ def files_count
136
+ %x{ git ls-tree -r HEAD }.lines.count
137
+ end
138
+
139
+ def git_installed?
140
+ null = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
141
+ system "git --version >>#{null} 2>&1"
142
+ end
143
+
144
+ private
145
+
146
+ def jekyll_items(site)
147
+ site.pages + site.collections.values.map(&:docs).flatten
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module GitMetadata
3
+ VERSION = "0.3.3"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'jekyll/git_metadata/version'
2
+ require 'jekyll/git_metadata/generator'
3
+
4
+ module Jekyll
5
+ module GitMetadata
6
+
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ require 'jekyll/git_metadata'
data/test/helper.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'shoulda'
4
+ require 'mocha/mini_test'
5
+ require 'jekyll'
6
+ require 'jekyll-git_metadata'
7
+
8
+ def jekyll_test_repo_path
9
+ File.join(File.dirname(__FILE__), 'test_repo')
10
+ end
11
+
12
+ def remove_cache_dir
13
+ FileUtils.rm_rf(File.join(jekyll_test_repo_path, '.git-metadata'))
14
+ end
15
+
16
+ class Minitest::Test
17
+ def dot_git_path
18
+ File.join(jekyll_test_repo_path, 'dot_git')
19
+ end
20
+
21
+ def real_dot_git_path
22
+ File.join(jekyll_test_repo_path, '.git')
23
+ end
24
+
25
+ def create_temp_git_dir
26
+ FileUtils.cp_r(dot_git_path, real_dot_git_path)
27
+ end
28
+
29
+ def remove_temp_git_dir
30
+ FileUtils.rm_rf(real_dot_git_path)
31
+ end
32
+ end
@@ -0,0 +1,227 @@
1
+ require 'helper'
2
+
3
+ Minitest.after_run do
4
+ remove_cache_dir
5
+ end
6
+
7
+ class Jekyll::GitMetadataTest < Minitest::Test
8
+ context 'GitMetadata' do
9
+
10
+ setup do
11
+ create_temp_git_dir
12
+ Jekyll.instance_variable_set(:@logger, Jekyll::LogAdapter.new(Jekyll::Stevenson.new, :error))
13
+
14
+ config = Jekyll.configuration(
15
+ :source => jekyll_test_repo_path,
16
+ :destination => File.join(jekyll_test_repo_path, '_site'))
17
+ @site = Jekyll::Site.new(config)
18
+ @site.read
19
+ @site.generate
20
+ end
21
+
22
+ teardown do
23
+ remove_temp_git_dir
24
+ end
25
+
26
+ context 'site data' do
27
+ setup do
28
+ @site_data = @site.config['git']
29
+ end
30
+
31
+ should 'have correct project name' do
32
+ assert_equal 'test_repo', @site_data['project_name']
33
+ end
34
+
35
+ should 'have correct files count' do
36
+ assert_equal 14, @site_data['files_count']
37
+ end
38
+
39
+ should 'have correct totals count' do
40
+ assert_equal 7, @site_data['total_commits']
41
+ assert_equal 688, @site_data['total_additions']
42
+ assert_equal 11, @site_data['total_subtractions']
43
+ end
44
+
45
+ should 'have correct authors data' do
46
+ assert_equal 3, @site_data['authors'].count
47
+ assert @site_data['authors'].include?({"commits"=>5, "name"=>"Ivan Tse", "email"=>"ivan.tse1@gmail.com"})
48
+ assert @site_data['authors'].include?({"commits"=>1, "name"=>"LeBron James", "email"=>"lbj@example.com"})
49
+ assert @site_data['authors'].include?({"commits"=>1, "name"=>"Mark Morga", "email"=>"mmorga@rackspace.com"})
50
+ end
51
+
52
+ should 'have correct first commit data' do
53
+ assert_equal '7884565', @site_data['first_commit']['short_sha']
54
+ assert_equal '78845656f899d0bfd86d2806b85b0c54adddd3c8', @site_data['first_commit']['long_sha']
55
+ assert_equal 'Ivan Tse', @site_data['first_commit']['author_name']
56
+ assert_equal 'ivan.tse1@gmail.com', @site_data['first_commit']['author_email']
57
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @site_data['first_commit']['author_date']
58
+ assert_equal 'Ivan Tse', @site_data['first_commit']['commit_name']
59
+ assert_equal 'ivan.tse1@gmail.com', @site_data['first_commit']['commit_email']
60
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @site_data['first_commit']['commit_date']
61
+ assert_equal 'First commit with jekyll scaffold', @site_data['first_commit']['message']
62
+ end
63
+
64
+ should 'have correct last commit data' do
65
+ assert_equal 'b8ffd38', @site_data['last_commit']['short_sha']
66
+ assert_equal 'b8ffd38affdd1cc22ee4cb830cbe5c398b4e3df1', @site_data['last_commit']['long_sha']
67
+ assert_equal 'Mark Morga', @site_data['last_commit']['author_name']
68
+ assert_equal 'mmorga@rackspace.com', @site_data['last_commit']['author_email']
69
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @site_data['last_commit']['author_date']
70
+ assert_equal 'Mark Morga', @site_data['last_commit']['commit_name']
71
+ assert_equal 'mmorga@rackspace.com', @site_data['last_commit']['commit_email']
72
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @site_data['last_commit']['commit_date']
73
+ assert_equal 'Adding example collection doc for git metadata', @site_data['last_commit']['message']
74
+ end
75
+ end
76
+
77
+ context 'page data' do
78
+ setup do
79
+ @about_page = @site.pages.select{|p| p.name == 'about.md'}.first
80
+ @page_data = @about_page.data['git']
81
+ end
82
+
83
+ should 'have correct totals count' do
84
+ assert_equal 4, @page_data['total_commits']
85
+ assert_equal 16, @page_data['total_additions']
86
+ assert_equal 5, @page_data['total_subtractions']
87
+ end
88
+
89
+ should 'have correct authors data' do
90
+ assert_equal 2, @page_data['authors'].count
91
+ assert @page_data['authors'].include?({"commits"=>3, "name"=>"Ivan Tse", "email"=>"ivan.tse1@gmail.com"})
92
+ assert @page_data['authors'].include?({"commits"=>1, "name"=>"LeBron James", "email"=>"lbj@example.com"})
93
+ end
94
+
95
+ should 'have correct first commit data' do
96
+ assert_equal '7884565', @page_data['first_commit']['short_sha']
97
+ assert_equal '78845656f899d0bfd86d2806b85b0c54adddd3c8', @page_data['first_commit']['long_sha']
98
+ assert_equal 'Ivan Tse', @page_data['first_commit']['author_name']
99
+ assert_equal 'ivan.tse1@gmail.com', @page_data['first_commit']['author_email']
100
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @page_data['first_commit']['author_date']
101
+ assert_equal 'Ivan Tse', @page_data['first_commit']['commit_name']
102
+ assert_equal 'ivan.tse1@gmail.com', @page_data['first_commit']['commit_email']
103
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @page_data['first_commit']['commit_date']
104
+ assert_equal 'First commit with jekyll scaffold', @page_data['first_commit']['message']
105
+ end
106
+
107
+ should 'have correct last commit data' do
108
+ assert_equal '70343eb', @page_data['last_commit']['short_sha']
109
+ assert_equal '70343eb1287191b30371400048167253a883d6ca', @page_data['last_commit']['long_sha']
110
+ assert_equal 'Ivan Tse', @page_data['last_commit']['author_name']
111
+ assert_equal 'ivan.tse1@gmail.com', @page_data['last_commit']['author_email']
112
+ assert_equal 'Sun Feb 12 02:21:26 2017 -0500', @page_data['last_commit']['author_date']
113
+ assert_equal 'Ivan Tse', @page_data['last_commit']['commit_name']
114
+ assert_equal 'ivan.tse1@gmail.com', @page_data['last_commit']['commit_email']
115
+ assert_equal 'Sun Feb 12 02:21:26 2017 -0500', @page_data['last_commit']['commit_date']
116
+ assert_equal "This is a long commit message\n\nAs you can tell this commit message will span several lines long because\nI need to test long comit messages too!", @page_data['last_commit']['message']
117
+ assert_equal ["_posts/2014-07-14-welcome-to-jekyll.markdown", "about.md"], @page_data['last_commit']['changed_files']
118
+ end
119
+ end
120
+
121
+ context 'post data' do
122
+ setup do
123
+ @welcome_post = @site.posts.docs.select{|p| p.basename == '2014-07-14-welcome-to-jekyll.markdown'}.first
124
+ @page_data = @welcome_post.data['git']
125
+ end
126
+
127
+ should 'have correct totals count' do
128
+ assert_equal 3, @page_data['total_commits']
129
+ assert_equal 30, @page_data['total_additions']
130
+ assert_equal 0, @page_data['total_subtractions']
131
+ end
132
+
133
+ should 'have correct authors data' do
134
+ assert_equal 1, @page_data['authors'].count
135
+ assert @page_data['authors'].include?({"commits"=>3, "name"=>"Ivan Tse", "email"=>"ivan.tse1@gmail.com"})
136
+ end
137
+
138
+ should 'have correct first commit data' do
139
+ assert_equal '7884565', @page_data['first_commit']['short_sha']
140
+ assert_equal '78845656f899d0bfd86d2806b85b0c54adddd3c8', @page_data['first_commit']['long_sha']
141
+ assert_equal 'Ivan Tse', @page_data['first_commit']['author_name']
142
+ assert_equal 'ivan.tse1@gmail.com', @page_data['first_commit']['author_email']
143
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @page_data['first_commit']['author_date']
144
+ assert_equal 'Ivan Tse', @page_data['first_commit']['commit_name']
145
+ assert_equal 'ivan.tse1@gmail.com', @page_data['first_commit']['commit_email']
146
+ assert_equal 'Mon Jul 14 02:01:29 2014 -0400', @page_data['first_commit']['commit_date']
147
+ assert_equal 'First commit with jekyll scaffold', @page_data['first_commit']['message']
148
+ end
149
+
150
+ should 'have correct last commit data' do
151
+ assert_equal '70343eb', @page_data['last_commit']['short_sha']
152
+ assert_equal '70343eb1287191b30371400048167253a883d6ca', @page_data['last_commit']['long_sha']
153
+ assert_equal 'Ivan Tse', @page_data['last_commit']['author_name']
154
+ assert_equal 'ivan.tse1@gmail.com', @page_data['last_commit']['author_email']
155
+ assert_equal 'Sun Feb 12 02:21:26 2017 -0500', @page_data['last_commit']['author_date']
156
+ assert_equal 'Ivan Tse', @page_data['last_commit']['commit_name']
157
+ assert_equal 'ivan.tse1@gmail.com', @page_data['last_commit']['commit_email']
158
+ assert_equal 'Sun Feb 12 02:21:26 2017 -0500', @page_data['last_commit']['commit_date']
159
+ assert_equal "This is a long commit message\n\nAs you can tell this commit message will span several lines long because\nI need to test long comit messages too!", @page_data['last_commit']['message']
160
+ assert_equal ["_posts/2014-07-14-welcome-to-jekyll.markdown", "about.md"], @page_data['last_commit']['changed_files']
161
+ end
162
+ end
163
+
164
+ context 'untracked file' do
165
+ setup do
166
+ @site.reset
167
+ @untracked_file = File.join(jekyll_test_repo_path, 'untracked_file.html')
168
+ File.open(@untracked_file, 'w') do |f|
169
+ f.write("---\n---")
170
+ end
171
+ @site.read
172
+ @untracked_page = @site.pages.select{|p| p.name == 'untracked_file.html'}.first
173
+ @site.generate
174
+ end
175
+
176
+ teardown do
177
+ File.delete(@untracked_file)
178
+ end
179
+
180
+ should 'not have git data' do
181
+ assert_nil @untracked_page.data['git']
182
+ end
183
+ end
184
+
185
+ context 'collection doc data' do
186
+ setup do
187
+ @gizmo_page = @site.collections['gizmos'].docs.select{|p| p.relative_path == '_gizmos/yoyo.md'}.first
188
+ @page_data = @gizmo_page.data['git']
189
+ end
190
+
191
+ should 'have correct totals count' do
192
+ assert_equal 1, @page_data['total_commits']
193
+ assert_equal 9, @page_data['total_additions']
194
+ assert_equal 0, @page_data['total_subtractions']
195
+ end
196
+
197
+ should 'have correct authors data' do
198
+ assert_equal 1, @page_data['authors'].count
199
+ assert @page_data['authors'].include?({"commits"=>1, "name"=>"Mark Morga", "email"=>"mmorga@rackspace.com"})
200
+ end
201
+
202
+ should 'have correct first commit data' do
203
+ assert_equal 'b8ffd38', @page_data['first_commit']['short_sha']
204
+ assert_equal 'b8ffd38affdd1cc22ee4cb830cbe5c398b4e3df1', @page_data['first_commit']['long_sha']
205
+ assert_equal 'Mark Morga', @page_data['first_commit']['author_name']
206
+ assert_equal 'mmorga@rackspace.com', @page_data['first_commit']['author_email']
207
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @page_data['first_commit']['author_date']
208
+ assert_equal 'Mark Morga', @page_data['first_commit']['commit_name']
209
+ assert_equal 'mmorga@rackspace.com', @page_data['first_commit']['commit_email']
210
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @page_data['first_commit']['commit_date']
211
+ assert_equal 'Adding example collection doc for git metadata', @page_data['first_commit']['message']
212
+ end
213
+
214
+ should 'have correct last commit data' do
215
+ assert_equal 'b8ffd38', @page_data['last_commit']['short_sha']
216
+ assert_equal 'b8ffd38affdd1cc22ee4cb830cbe5c398b4e3df1', @page_data['last_commit']['long_sha']
217
+ assert_equal 'Mark Morga', @page_data['last_commit']['author_name']
218
+ assert_equal 'mmorga@rackspace.com', @page_data['last_commit']['author_email']
219
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @page_data['last_commit']['author_date']
220
+ assert_equal 'Mark Morga', @page_data['last_commit']['commit_name']
221
+ assert_equal 'mmorga@rackspace.com', @page_data['last_commit']['commit_email']
222
+ assert_equal 'Tue Jun 20 11:36:43 2017 -0500', @page_data['last_commit']['commit_date']
223
+ assert_equal 'Adding example collection doc for git metadata', @page_data['last_commit']['message']
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1 @@
1
+ _site