bhook 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a429bac22b3cc378e763dabbad48a1b22263160b1ce2e84a8e476f69c2f0783
4
- data.tar.gz: bebc1d4b7ae5e570e29a8075505d8a326adc16af6abc6d62113e1cb21db4c14f
3
+ metadata.gz: e294643cd33777109cba77c7582e4d145f300f8d3960c4dbf5862f616a6a6929
4
+ data.tar.gz: 4031364646363638654b1b98a9c8d026c2d8c6ac368554315853701d918bb188
5
5
  SHA512:
6
- metadata.gz: 9bbffd373a9b185635617be72154d16f358fad87b6592b1e9bb23e9295eb7a682f229dc004bcf43f1fef02e5e9838b0b15475343b2040a94b78803cbd6844e61
7
- data.tar.gz: 2033c32dc2107c52197a6b71581970324cf0e05164948b5c83cdbf80bf0bc7665b8d3f89372e432344b6d0e23728a4b5b68a8c0bb6df40dcb079b47c6f8121a4
6
+ metadata.gz: 11a403217488e651e2627f053e7de1658a831d2def49679b1fb767bb35885008431cc37c333fd37e4b97b564289af9f6a573fb074b40e48dccb8c6e46e42bfd1
7
+ data.tar.gz: 16336203e9e8c511361cd529bae17dcb845ba8bb654a63719b378e66ceda6188b4ac7854ec98fa0057afeabd88cc385c19c0669718a1e6613836fac4c8b69180
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bhook (0.1.1)
4
+ bhook (0.1.2)
5
5
  git (~> 1.10)
6
6
  kramdown (~> 2.3)
7
7
  listen (~> 3.7)
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Bhook
2
2
 
3
- Bhook is a static website generator that works off a git repo containing a markdown file based wiki.
3
+ Bhook is a static website generator that works off a git repo containing a markdown file based wiki, like for example, the [India Startup Wiki](https://gitlab.com/india-startups/wiki).
4
+
5
+ I use this to create [HTML versions of the wiki](https://sidu.in/wiki/startups) and of [my essays](https://sidu.in/essays/) that I can publish.
4
6
 
5
7
  ## Installation
6
8
 
@@ -13,17 +15,20 @@ Install it yourself as:
13
15
  Getting help:
14
16
 
15
17
  $ bhook --help
16
- Bhook version 0.1.0
18
+ Bhook version 0.1.2
17
19
  Usage: bhook --source /source/path --output /output/path
18
20
  -s, --source=SOURCE Path to version controlled directory containing source md files
19
21
  -o, --output=OUTPUT Path to directory where output files are to be generated
20
22
  -w, --watch Continuously watch the source directory for changes and generate output
21
- -t, --typechecking Enables sorbet runtime typechecking. Only useful when developing bhook.
23
+ -v, --verbose Print detailed information about files as they are processed
24
+ -t, --theme=PATH Path to directory containing theme files to use when generating html
25
+ --generate-theme=PATH Generate a baseline theme that you can then modify to your needs
22
26
  -h, --help Prints this help
23
27
 
24
28
  How I use it:
25
29
 
26
- ➜ essays git:(main) ✗ bhook -s . -o /tmp/out -w
30
+ ➜ essays git:(main) ✗ bhook -s . -o /tmp/out -t /tmp/out/theme -w -v
31
+
27
32
  ## Development
28
33
 
29
34
  1. `git clone --recursive git@gitlab.com:kaiwren/bhook.git`
data/bin/bhook CHANGED
@@ -7,6 +7,12 @@ require 'bhook'
7
7
  puts "Bhook version #{Bhook::VERSION}"
8
8
  args = Bhook::ArgsParser.new(ARGV).parse
9
9
 
10
+ if args.verbose
11
+ Bhook::L.level = Logger::DEBUG
12
+ else
13
+ Bhook::L.level = Logger::INFO
14
+ end
15
+
10
16
  if args.generate_theme
11
17
  Bhook::ThemeGenerator.new(args.generate_theme).generate!
12
18
  exit
@@ -1,6 +1,6 @@
1
1
  module Bhook
2
2
  class ArgsParser
3
- Options = Struct.new(:source, :output, :watch, :typechecking, :theme, :generate_theme)
3
+ Options = Struct.new(:source, :output, :watch, :verbose, :theme, :generate_theme)
4
4
 
5
5
  def initialize(argv)
6
6
  @args = Options.new(nil, nil, false, false, nil, nil)
@@ -56,6 +56,12 @@ module Bhook
56
56
  @args.watch = true
57
57
  end
58
58
 
59
+ opts.on("-v", "--verbose",
60
+ FalseClass,
61
+ "Print detailed information about files as they are processed") do
62
+ @args.verbose = true
63
+ end
64
+
59
65
  opts.on("-tPATH", "--theme=PATH",
60
66
  String,
61
67
  "Path to directory containing theme files to use when generating html") do |path|
@@ -16,7 +16,7 @@ module Bhook
16
16
  def convert_a(el, indent)
17
17
  href_path = el.attr['href']
18
18
  if valid_relative_md_link?(href_path)
19
- puts "Found link: #{href_path}"
19
+ L.debug "Found link: #{href_path}"
20
20
  el.attr['href'].gsub!(/\.md/, '.html')
21
21
  end
22
22
  super(el, indent)
@@ -8,31 +8,25 @@ module Bhook
8
8
  GIT_DIR = '.git'
9
9
  MD_EXT = '.md'
10
10
 
11
- sig { params(src_path: Pathname, git: T.nilable(Git::Base)).void }
12
- def initialize(src_path, git = nil)
11
+ sig { params(src_path: Pathname, out_path: Pathname, git: Git::Base).void }
12
+ def initialize(src_path, out_path, git)
13
13
  @src_path = src_path
14
+ @out_path = T.let(out_path.join(src_path.basename), Pathname)
14
15
  @git = git
15
16
  @sub_dirs = T.let([], T::Array[Directory])
16
17
  @md_files = T.let([], T::Array[MdFile])
17
18
  build_next_level_nodes
18
19
  end
19
20
 
20
- sig { returns(T::Boolean) }
21
- def root_dir_for_a_commit?
22
- !@git
23
- end
24
-
25
- sig { params(out_path: String, theme: Theme).void }
26
- def write!(out_path, theme)
27
- dir_path = if root_dir_for_a_commit?
28
- out_path
29
- else
30
- File.join(out_path, @src_path.basename)
31
- end
32
-
33
- FileUtils.mkdir_p(dir_path, verbose: true)
34
- @sub_dirs.each { |dir| dir.write!(dir_path, theme) }
35
- @md_files.each { |file| file.write!(dir_path, theme) }
21
+ sig { params(theme: Theme).void }
22
+ def write!(theme)
23
+ FileUtils.mkdir_p(@out_path, verbose: true)
24
+ @sub_dirs.each { |dir| dir.write!(theme) }
25
+ @md_files.map do |file|
26
+ Thread.new { file.write!(theme) }
27
+ end.each do |thread|
28
+ thread.join
29
+ end
36
30
  end
37
31
 
38
32
  sig { returns(T::Array[MdFile]) }
@@ -44,25 +38,23 @@ module Bhook
44
38
  def to_s
45
39
  @src_path.to_s
46
40
  end
47
-
41
+
48
42
  private
49
43
 
50
44
  sig { void }
51
45
  def build_next_level_nodes
52
- if root_dir_for_a_commit?
53
- @git = Git.open(@src_path)
54
- end
55
-
56
- @sub_dirs = @src_path.children.map do |child|
57
- if child.directory? && child.basename.to_s != GIT_DIR
58
- Directory.new(child, @git)
46
+ children = @src_path.children
47
+ children.delete(@src_path.join(GIT_DIR))
48
+
49
+ file_threads = []
50
+ children.each do |child_path|
51
+ if child_path.directory?
52
+ @sub_dirs << Directory.new(child_path, @out_path, @git)
53
+ elsif child_path.extname == MD_EXT
54
+ file_threads << Thread.new { MdFile.new(child_path, @out_path, @git) }
59
55
  end
60
- end.compact
61
- @md_files = @src_path.children.select do |child|
62
- !child.directory? && child.extname == MD_EXT
63
- end.map do |child|
64
- MdFile.new(child, @git)
65
- end.compact
56
+ end
57
+ file_threads.each { |thread| @md_files << thread.value }
66
58
  end
67
59
  end
68
60
  end
@@ -0,0 +1,8 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module Bhook
5
+ L = Logger.new(STDOUT, formatter: proc {|severity, datetime, progname, msg|
6
+ "#{Thread.current.object_id} #{msg}\n"
7
+ })
8
+ end
data/lib/bhook/md_file.rb CHANGED
@@ -8,30 +8,34 @@ module Bhook
8
8
  PAGE_TEMPLATE = T.let(File.read(Bhook::PAGE_TEMPLATE_PATH), String)
9
9
  AFTER_H1_TEMPLATE = T.let(File.read(Bhook::AFTER_H1_TEMPLATE_PATH), String)
10
10
 
11
- sig { params(src_file_path: Pathname, git: Git::Base).void }
12
- def initialize(src_file_path, git)
11
+ sig { returns(Pathname) }
12
+ attr_reader :src_file_path
13
+
14
+ sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base).void }
15
+ def initialize(src_file_path, out_path, git)
16
+ L.debug "Reading: #{src_file_path}"
13
17
  @md = T.let(File.read(src_file_path), String)
14
- @src_file_path = T.let(src_file_path.expand_path, Pathname)
15
- src_file_date, src_file_sha = git.lib.send(:command, 'log',
16
- '-n 1',
17
- '--pretty=format:%ad|%h',
18
- '--date=short',
19
- '--',
18
+ @src_file_path = src_file_path
19
+ @out_path = out_path
20
+ src_file_date, src_file_sha = git.lib.send(:command, 'log',
21
+ '-n 1',
22
+ '--pretty=format:%ad|%h',
23
+ '--date=short',
24
+ '--',
20
25
  @src_file_path).split('|')
21
26
  @src_file_date = T.let(src_file_date, T.nilable(String))
22
27
  @src_file_sha = T.let(src_file_sha, T.nilable(String))
23
28
  end
24
29
 
25
- sig { returns(Pathname) }
26
- attr_reader :src_file_path
30
+ sig { params(theme: Bhook::Theme).void }
31
+ def write!(theme)
32
+ out_file_name = @src_file_path.basename.sub(/\.md$/, '.html')
33
+ out_file_path = @out_path.join(out_file_name)
27
34
 
28
- sig { params(out_path: String, theme: Bhook::Theme).void }
29
- def write!(out_path, theme)
30
- out_file_name = File.basename(@src_file_path).gsub(/\.md$/, '.html')
31
- out_file_path = File.join(out_path, out_file_name)
32
- puts "Processing: #{@src_file_sha} #{@src_file_path}"
35
+ L.debug "Processing: #{@src_file_sha || 'unversioned'} #{@src_file_path}"
33
36
  rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date)
34
- puts "Writing: #{@src_file_sha} #{out_file_path}"
37
+
38
+ L.debug "Writing: #{@src_file_sha} #{out_file_path}"
35
39
  File.write(out_file_path, rendered_page)
36
40
  end
37
41
 
@@ -0,0 +1,13 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module Bhook
5
+ class RootDirectory < Directory
6
+ extend T::Sig
7
+
8
+ sig { params(src_path: Pathname, out_path: Pathname).void }
9
+ def initialize(src_path, out_path)
10
+ super(src_path, out_path, Git.open(src_path))
11
+ end
12
+ end
13
+ end
data/lib/bhook/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Bhook
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
@@ -7,25 +7,25 @@ module Bhook
7
7
 
8
8
  sig { params(src_path: String, out_path: String, theme_path: String).void }
9
9
  def initialize(src_path, out_path, theme_path)
10
- @src_path = src_path
11
- @out_path = out_path
10
+ @src_path = T.let(Pathname.new(src_path).expand_path, Pathname)
11
+ @out_path = T.let(Pathname.new(out_path).expand_path, Pathname)
12
12
  @theme = T.let(Theme.new(theme_path), Bhook::Theme)
13
13
  end
14
14
 
15
15
  sig { void }
16
- def process!
17
- root = root_dir
18
- root.write!(@out_path, @theme)
16
+ def process!
17
+ root_dir.write!(@theme)
18
+ L.info "Done!"
19
19
  end
20
20
 
21
21
  sig { void }
22
22
  def watch!
23
23
  process!
24
- puts
25
- puts "Watching #{@src_path} for changes..."
26
- listener = Listen.to(@src_path, File.join(@src_path, '.git')) do |_modified, _added, _removed|
24
+
25
+ L.info "Watching: #{@src_path} for changes..."
26
+ listener = Listen.to(@src_path.to_s, File.join(@src_path.to_s, '.git')) do |_modified, _added, _removed|
27
+ L.info "Detected changes..."
27
28
  process!
28
- puts "-----\n"
29
29
  end
30
30
  listener.start
31
31
  sleep
@@ -35,12 +35,11 @@ module Bhook
35
35
  def all_md_files
36
36
  root_dir.all_md_files
37
37
  end
38
-
39
- private
40
-
41
- sig { returns(Bhook::Directory) }
38
+
39
+ private
40
+ sig { returns(Bhook::RootDirectory) }
42
41
  def root_dir
43
- Directory.new(Pathname.new(@src_path))
42
+ RootDirectory.new(@src_path, @out_path)
44
43
  end
45
44
  end
46
45
  end
data/lib/bhook.rb CHANGED
@@ -6,6 +6,7 @@ require 'fileutils'
6
6
  require 'pathname'
7
7
  require 'erb'
8
8
  require 'optparse'
9
+ require 'logger'
9
10
  require 'sorbet-runtime'
10
11
  require 'git'
11
12
  require 'kramdown'
@@ -22,10 +23,12 @@ module Bhook
22
23
  end
23
24
 
24
25
  require_relative 'bhook/version'
26
+ require_relative 'bhook/logger'
25
27
  require_relative 'bhook/args_parser'
26
28
  require_relative 'bhook/theme_generator'
27
29
  require_relative 'bhook/theme'
28
30
  require_relative 'bhook/converter/html'
29
31
  require_relative 'bhook/directory'
32
+ require_relative 'bhook/root_directory'
30
33
  require_relative 'bhook/md_file'
31
34
  require_relative 'bhook/workspace'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-13 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -171,7 +171,9 @@ files:
171
171
  - lib/bhook/args_parser.rb
172
172
  - lib/bhook/converter/html.rb
173
173
  - lib/bhook/directory.rb
174
+ - lib/bhook/logger.rb
174
175
  - lib/bhook/md_file.rb
176
+ - lib/bhook/root_directory.rb
175
177
  - lib/bhook/theme.rb
176
178
  - lib/bhook/theme/_after_h1.erb
177
179
  - lib/bhook/theme/page.erb