jekyll-readme-index 0.0.4 → 0.1.0

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
  SHA1:
3
- metadata.gz: 92d5d65f136e0fb3a174c22cea5fa6b20f9a8e0f
4
- data.tar.gz: e11c2bfea7414fc7c9c3ac9f544666ec43588512
3
+ metadata.gz: 4a6dbcea7f7b27ff87d656d95b87378598989165
4
+ data.tar.gz: 413e078182aab9e9a0116fbc8e6cf67c6758ff7a
5
5
  SHA512:
6
- metadata.gz: db9cf78c152d7a0b17ce5cddad7ab7fdfe061d9c4157cfd3ce224e7c16fe8b17ce1cb45d285fdb5e8207427eccfeb9fe08b6b55b1e67d0fa8f0c1f02c5622cef
7
- data.tar.gz: 6dec5692130b04d5d781bd75bfe01caf0fa8a582962275fbf04346c6d57f68c9cb174ce5497a9601e1333c16049d8a2a4cfc22113df2641bfb8e5b79313651ba
6
+ metadata.gz: '07838efab593f1637a60272937fbed94b6234f6a2795681bee23217303034beae03ff65572ef16335bb02d4057332fc73bc6b1bcaf31b839a1019fbad85673a8'
7
+ data.tar.gz: 8e7b984a6bc9ca0e81ea42f2480917cb48f5378c6b88bcc234bb6f039c0c16ba290395ba6800ce3304e8840fbb1f44e0a9603769530966b9201af51bb13c8cac
@@ -1,5 +1,6 @@
1
1
  require "jekyll"
2
2
  require "jekyll-readme-index/generator"
3
+ require_relative "./jekyll/static_file_ext"
3
4
 
4
5
  module JekyllReadmeIndex
5
6
  end
@@ -1,7 +1,6 @@
1
1
  module JekyllReadmeIndex
2
2
  class Generator < Jekyll::Generator
3
- README_REGEX = %r!^/readme(\.[^.]+)?$!i
4
- INDEX_REGEX = %r!^/($|index\.(html?|xhtml|xml)$)!i
3
+ INDEX_REGEX = %r!$|index\.(html?|xhtml|xml)$!i
5
4
 
6
5
  attr_accessor :site
7
6
 
@@ -15,27 +14,41 @@ module JekyllReadmeIndex
15
14
  def generate(site)
16
15
  @site = site
17
16
 
18
- return if index? || readme.nil?
19
- site.pages << page
17
+ readmes.each do |readme|
18
+ next unless should_be_index?(readme)
19
+ site.pages << readme.to_page
20
+ end
20
21
  end
21
22
 
22
23
  private
23
24
 
24
- def readme
25
- site.static_files.find { |file| file.relative_path =~ README_REGEX }
25
+ # Returns an array of all READMEs as StaticFiles
26
+ def readmes
27
+ site.static_files.select { |file| file.relative_path =~ readme_regex }
26
28
  end
27
29
 
28
- def index?
29
- (site.pages + site.static_files).any? { |file| file.url =~ INDEX_REGEX }
30
+ # Should the given readme be the containing directory's index?
31
+ def should_be_index?(readme)
32
+ return false unless readme
33
+ !dir_has_index? File.dirname(readme.url)
30
34
  end
31
35
 
32
- def page
33
- base = readme.instance_variable_get("@base")
34
- dir = readme.instance_variable_get("@dir")
35
- name = readme.instance_variable_get("@name")
36
- page = Jekyll::Page.new(site, base, dir, name)
37
- page.data["permalink"] = "/"
38
- page
36
+ # Does the given directory have an index?
37
+ #
38
+ # relative_path - the directory path relative to the site root
39
+ def dir_has_index?(relative_path)
40
+ relative_path << "/" unless relative_path.end_with? "/"
41
+ regex = %r!^#{Regexp.escape(relative_path)}#{INDEX_REGEX}!i
42
+ (site.pages + site.static_files).any? { |file| file.url =~ regex }
43
+ end
44
+
45
+ # Regexp to match a file path against to detect if the given file is a README
46
+ def readme_regex
47
+ @readmes_regex ||= %r!/readme(#{Regexp.union(markdown_converter.extname_list)})$!i
48
+ end
49
+
50
+ def markdown_converter
51
+ @markdown_converter ||= site.find_converter_instance(Jekyll::Converters::Markdown)
39
52
  end
40
53
  end
41
54
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllReadmeIndex
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
@@ -0,0 +1,10 @@
1
+ module Jekyll
2
+ class StaticFile
3
+ # Convert this static file to a Page
4
+ def to_page
5
+ page = Jekyll::Page.new(@site, @base, @dir, @name)
6
+ page.data["permalink"] = File.dirname(url) + "/"
7
+ page
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-readme-index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -62,6 +62,7 @@ files:
62
62
  - lib/jekyll-readme-index.rb
63
63
  - lib/jekyll-readme-index/generator.rb
64
64
  - lib/jekyll-readme-index/version.rb
65
+ - lib/jekyll/static_file_ext.rb
65
66
  homepage: https://github.com/benbalter/jekyll-readme-index
66
67
  licenses:
67
68
  - MIT