jekyll-commit-blog 0.0.1

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 (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/jekyll-post-commit +104 -0
  3. metadata +60 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 89913a328bcacd96a461b7952b386815984b3be0
4
+ data.tar.gz: a576abfb98f076fb549232c477a5e52438ddf068
5
+ SHA512:
6
+ metadata.gz: 087afd4383be7fa4ca4558741772df500b5eb2ccb2a126bb1ddbc8d2e2c85ac7af07d2fa67ff409e677f1549bcda8488defc0de7b32502a8368f7c2a385f4c02
7
+ data.tar.gz: 7b304b2af98692da97f663c49b57314b46834b3d59b5d078aa31d308f509e0a9e6e8a611df4b6ba397594adab6d5dabde2b70f9497adbe2b4ca66830918578aa
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cgi'
4
+ require 'git'
5
+ require 'optparse'
6
+ require 'fileutils'
7
+
8
+ args = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: post-commit [options]"
11
+
12
+ opts.on("-c COMMIT", "--commit COMMIT", "Commit hash or HEAD offset. If not set then the latest commit is used.") { |c| args[:commit] = c }
13
+ opts.on("-p PROJECT", "--project PROJECT", "Directory where the .git folder is. If not set then the path to the command is used.") { |p| args[:project] = p }
14
+ opts.on("-o OUTPUT", "--output OUTPUT", "Directory to write the generated file to. If not set then the cwd is used.") { |o| args[:output] = o }
15
+ opts.on("-i", "--install-hook", "Install this hook into the --project directory") { |o|
16
+ unless args.key?(:project)
17
+ puts "No --project directory specified. Please set a project directory to install to.\n"
18
+ puts opts
19
+ exit 1
20
+ end
21
+ args[:install_hook] = o
22
+ }
23
+ opts.on("-h", "--help", "Display this help") { |h|
24
+ puts opts
25
+ exit 0
26
+ }
27
+ end.parse!
28
+
29
+ # Attempt to find the project root. If it isn't specified and
30
+ # there is a .git directory in our current path. Hop up until
31
+ # we get to the same directory level as the .git folder.
32
+ root = Dir.pwd
33
+ if args.key?(:project)
34
+ root = File.expand_path(args[:project])
35
+ elsif root.include?('/.git')
36
+ root.split('/').reverse.each { |s|
37
+ root += '/..'
38
+ break if s == '.git'
39
+ }
40
+ end
41
+
42
+ unless Dir.exist?(root + "/.git")
43
+ puts "No .git directory found. Either use the -p option or execute this command in a project directory."
44
+ exit 0
45
+ end
46
+
47
+ # If this is a hook installation then perform that and exit.
48
+ if args.key?(:install_hook)
49
+ root += "/.git/hooks/post-commit"
50
+ FileUtils.cp(File.expand_path(__FILE__), root)
51
+ puts "Successfully installed #{root} hook"
52
+ exit 0;
53
+ end
54
+
55
+ git = Git.open(root)
56
+
57
+ commit = args.key?(:commit) ? git.gcommit(args[:commit]) : git.log.first
58
+ body = commit.message
59
+ params = {}
60
+
61
+ match = body.match(/^(.*)\{BLOG(.*?)\}\s*$/im)
62
+ # If we match, then parse the params
63
+ if !match.nil?
64
+ body = match[1]
65
+ params = CGI::parse(match[2].strip)
66
+ params.each { |k, v| params[k] = v[0] if v.is_a?(Array) }
67
+ # If we don't match and no commit was
68
+ # specified then there's nothing to do.
69
+ elsif !args.key?(:commit)
70
+ exit 0
71
+ end
72
+
73
+ # Attempt to separate a title from the body
74
+ parts = body.match(/^(.*?)(?:\r|\n|\r\n){2}(.*)$/m);
75
+
76
+ # If we can't separate a title from the body then
77
+ # just use the first 60 chars of the body
78
+ title = body[0...60].strip
79
+ if !parts.nil? && parts.length >= 3
80
+ title = parts[1].strip
81
+ body = parts[2].strip
82
+ end
83
+ filename = args.key?(:output) ? File.expand_path(args[:output]) + '/' : ''
84
+ filename += git.log[0].date.strftime("%Y-%m-%d") + '-' + title.downcase.gsub(' ', '-').gsub(/[^\w-]/, '') + '.md'
85
+
86
+ puts "Creating Jekyll file #{filename}"
87
+
88
+ # Add some default front matter fields.
89
+ # These can be overwritten by set values.
90
+ frontmatter = {
91
+ "layout" => '"post"',
92
+ "author" => "\"#{commit.author.name}\"",
93
+ "title" => "\"#{title}\"",
94
+ "date" => '"' + commit.date.strftime("%Y-%m-%d %H:%M:%S") + '"',
95
+ }.merge(params)
96
+
97
+ post = File.open(filename, 'w+')
98
+ post.puts('---')
99
+ frontmatter.each { |k, v| post.puts "#{k}: #{v}" }
100
+ post.puts('---')
101
+ post.puts('')
102
+ post.puts(body)
103
+
104
+ post.close
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-commit-blog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jim Saunders
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ description: A simple command for generating Jekyll blog posts from git commit messages.
28
+ It can be run directly from the command line or installed as a post-commit hook.
29
+ email: jimdoescode@gmail.com
30
+ executables:
31
+ - jekyll-post-commit
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/jekyll-post-commit
36
+ homepage: https://github.com/jimdoescode/jekyll-commit-blog
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Format git commit messages into Jekyll markdown blog posts.
60
+ test_files: []