jekyll-category_generator 0.0.3 → 0.0.4

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: e9190022eb9493e3e9ac4157263a6d81bdfb5bca
4
- data.tar.gz: c08736efa6b9b376d598b62f94139853f4670158
3
+ metadata.gz: d554cee62eeab79fd1fc2bde081c1c6747742bd0
4
+ data.tar.gz: 0b7b924d91668bd8b08be0a5e4c3c60c65730145
5
5
  SHA512:
6
- metadata.gz: 6b8fc47cc6626c3ebbd57b1150827d07ec14bc912e6828e4237e40e872cd6014202aa51891c19c47bf01187c8be0db9c4c4e5b74dbd4bb95a7a2159f997a9d3b
7
- data.tar.gz: e09a05d3d8176a8f11caa609c7ace9783fcf1607fe22b8e13dcabf6dedab8bfc1b086a4238afd8d09bfcc0decd4dfcf8870336e800980b3538fa65e6e51d52e0
6
+ metadata.gz: b11a75f5ef74522d0ae167b79d372eb561aab20e78e2bb4c26fad57c8084fdae02bb9e2a6fdbd1224992b63ef500b20ff014b8934d25e2ed6a58def88356fac7
7
+ data.tar.gz: 404e7820c7237683f31f7b2a14e83e3b1816fdcba0cee6c2963011057fa13d7088aaa412962000a5163bdb01521fb47674f10366cfc23811075d9c0abea58323
@@ -13,7 +13,7 @@ require 'jekyll/category_generator/category_filters.rb'
13
13
  module Jekyll
14
14
  # The category generator module
15
15
  module CategoryGenerator
16
- DIRECTORIES_FOLDER = 'categories'.freeze
16
+ CATEGORIES_FOLDER = 'categories'.freeze
17
17
  # Jekyll hook - the generate method is called by jekyll, and generates all of the category pages.
18
18
  class CGenerator < Generator
19
19
  safe true
@@ -14,6 +14,7 @@ module Jekyll
14
14
  # +context+ is the Liquid:Tag context
15
15
  #
16
16
  def initialize(category_names, context)
17
+ @context = context
17
18
  category_names = [category_names] unless category_names.is_a? Array
18
19
  initialize_category_list(category_names, context)
19
20
  end
@@ -29,25 +30,29 @@ module Jekyll
29
30
  end
30
31
 
31
32
  ##
32
- # Outputs a list of categories as comma-separated <a> links. This is used
33
+ # Outputs a list of categories as separated <a> links. This is used
33
34
  # to output the category list for each post on a category page.
34
35
  #
35
36
  # Returns string
36
37
  #
37
38
  def links
38
- comma_separate(@category_list.sort!.map(&:link))
39
+ separate(@category_list.sort!.map(&:link))
39
40
  end
40
41
 
41
42
  private
42
43
 
43
44
  ##
44
- # Join a list as comma-separated
45
- def comma_separate(list_of_links)
46
- if list_of_links.length == 1
47
- list_of_links[0].to_s
48
- else
49
- "#{list_of_links[0...-1].join(', ')}, #{list_of_links[-1]}"
50
- end
45
+ # Join the list of category
46
+ def separate(list_of_links)
47
+ list_of_links.join(category_link_separator).to_s
48
+ end
49
+
50
+ ##
51
+ # Get the defined category link separator
52
+ def category_link_separator
53
+ @context.registers[:site].config['jekyll-category_generator']['link_separator']
54
+ rescue
55
+ ' '
51
56
  end
52
57
  end
53
58
  end
@@ -38,8 +38,16 @@ module Jekyll
38
38
  #
39
39
  def link
40
40
  return '' until @name
41
- dir = @context.registers[:site].config['category_dir'] || CategoryGenerator::DIRECTORIES_FOLDER
42
- "<a class='category' href='/#{dir}/#{URI.encode(@name)}/'>#{@name}</a>"
41
+ "<a class='category' href='/#{categories_folder}/#{URI.encode(@name)}/'>#{@name}</a>"
42
+ end
43
+
44
+ ##
45
+ # Returns the categories folder
46
+ #
47
+ def categories_folder
48
+ @context.registers[:site].config['jekyll-category_generator']['category_dir']
49
+ rescue
50
+ CategoryGenerator::CATEGORIES_FOLDER
43
51
  end
44
52
  end
45
53
  end
@@ -20,22 +20,14 @@ module Jekyll
20
20
  data['category'] = category
21
21
  # Set the title for this page.
22
22
  data['title'] = "#{title_prefix}#{category}"
23
- # Set the meta-description for this page.
24
- data['description'] = "#{description_prefix}#{category}"
25
23
  end
26
24
 
27
- private
28
-
29
25
  ##
30
26
  # Return the category title prefix
31
27
  def title_prefix
32
- site.config['jekyll-category_generator.title_prefix'] || 'Category: '
33
- end
34
-
35
- ##
36
- # Return the category description prefix
37
- def description_prefix
38
- site.config['jekyll-category_generator.description_prefix'] || 'Category: '
28
+ site.config['jekyll-category_generator']['title_prefix']
29
+ rescue
30
+ 'Category: '
39
31
  end
40
32
  end
41
33
  end
@@ -33,7 +33,9 @@ module Jekyll
33
33
  # Returns the categories folder
34
34
  #
35
35
  def categories_folder
36
- config['category_dir'] || CategoryGenerator::DIRECTORIES_FOLDER
36
+ config['jekyll-category_generator']['category_dir']
37
+ rescue
38
+ CategoryGenerator::CATEGORIES_FOLDER
37
39
  end
38
40
 
39
41
  # Raise an error on unexisting layout
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module CategoryGenerator
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.0.4'.freeze
4
4
  end
5
5
  end
data/readme.md CHANGED
@@ -23,7 +23,7 @@ plugins:
23
23
  - jekyll-category_generator
24
24
  ```
25
25
 
26
- # Configuration
26
+ ## Create your layout
27
27
  First of all, you need to create a *layout* named `category_index.html`; It will be used to create the index of all posts of a category.
28
28
 
29
29
  The file should at least have the following code.
@@ -37,18 +37,23 @@ The file should at least have the following code.
37
37
  ```
38
38
 
39
39
  # Using the plugin
40
- The plugin contains usefull filters and configuration variables helping you to create a nice *layout*.
40
+ The plugin contains usefull filters and [configuration](#configuration) variables helping you to create a nice *layout*.
41
41
 
42
42
  ## Filters
43
43
  ### category_links
44
- This filter allows you to create a list of links of all the given categories.
45
-
46
- Usefull to add to the end of a page for example.
44
+ Usefull to add to the bottom of a **page**, this filter allows you to create a list of links of all the given categories generated by default in the `categories` folder (see [category_dir](#category_dir) for configuration).
47
45
 
46
+ For example,
48
47
  ```html
49
48
  {{ page.categories | category_links }}
50
49
  ```
51
50
 
51
+ will render by default the following (see [link_separator](#link_separator) for configuration).
52
+ ```html
53
+ <a class="category" href="/categories/ionic/">ionic</a>
54
+ <a class="category" href="/categories/ruby%20on%20rails/">ruby on rails</a>
55
+ ```
56
+
52
57
  ### category_link
53
58
  This filter allows you to create the link of a given category.
54
59
 
@@ -63,25 +68,31 @@ Usefull for a menu listing all categories for example.
63
68
  ```
64
69
 
65
70
  ### date_to_html_string
66
- This filter allows you to output a HtML formatted date (`2017-03-12` by default).
71
+ This filter allows you to output a HtML formatted date (`%Y-%m-%d` by default, see [date format](#date-format) for configuration).
67
72
 
68
- This code
73
+ For example,
69
74
  ```html
70
75
  {{ post.date | date_to_html_string }}
71
76
  ```
72
77
 
73
- The format can be specified in the `_config.yml` file.
78
+ will render by default something like
79
+ ```
80
+ 2017-07-01
81
+ ```
74
82
 
75
- ## Variables in `_config.yml`
83
+ ## Configuration
84
+ All variables must be set under the `jekyll-category_generator` key in the `_config.yml` file!
76
85
 
77
- ### Basics configuration keys
78
- The title of the category can be prefixed by the `title_prefix` value, by default, it is set with **Category:**
86
+ ### title_prefix
87
+ The **title** of the category can be **prefixed** by the `title_prefix` value, by default, it is set with **Category:**. So when using `{{ page.title }}` in your `category_index` layout, it will be prefixed.
79
88
 
80
- The category directory is by default the `categories/` folder, but you can change it by adding the `category_dir` key.
89
+ ### category_dir
90
+ The category **directory** is by default the `categories/` folder, but you can change it by adding the `category_dir` key.
81
91
 
82
- The `description_prefix` configuration key can be used to prefix each post description.
92
+ ### link_separator
93
+ When joinning category links, the generator will use white space by default, but you can specify the separator using the `link_separator` key.
83
94
 
84
- ### Date format configuration
95
+ ### date format
85
96
  The `date_to_html_string` filter allows you to stringify the date for your own language by adding the following.
86
97
 
87
98
  The *format* variable uses the Ruby [Time#strftime](http://ruby-doc.org/core-2.2.1/Time.html#method-i-strftime) method.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-category_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alain ANDRE