octopress-categories 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58ba8d339175910c1d20d4f6cc57b07257d21573
4
+ data.tar.gz: 297c7afc1748627d049869774bf881d8cab32873
5
+ SHA512:
6
+ metadata.gz: d6b19ed84eaf9f2cfb3d79bae2f53b3d30e48d0f8edac153c2b83ea6712e09e60deb4b437ed6648c420885a505fe3403fc1bd963463e550c8a9d2d9193206ae9
7
+ data.tar.gz: c907a7296609b8b9285d94be86110401a8ea08bd68905fa1bd063954bbc5e3854f456c27a36f8fd3b27ef25460f950ec660c67843c44c89f97faae5d07a3af46
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ### 0.0.1 (2015-XX-XX)
4
+
5
+ - Support for category indexes
6
+ - Multilingual support
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Brandon Mathis, Patrice Brend'amour
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,118 @@
1
+ # Categories
2
+
3
+ TODO: Write a gem description
4
+
5
+ [![Build Status](http://img.shields.io/travis/octopress/categories.svg)](https://travis-ci.org/octopress/categories)
6
+ [![Gem Version](http://img.shields.io/gem/v/octopress-categories.svg)](https://rubygems.org/gems/octopress-multilingual)
7
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://octopress.mit-license.org)
8
+
9
+ ## Installation
10
+
11
+ If you're using bundler add this gem to your site's Gemfile in the `:jekyll_plugins` group:
12
+
13
+ group :jekyll_plugins do
14
+ gem 'octopress-categories'
15
+ end
16
+
17
+ Then install the gem with Bundler
18
+
19
+ $ bundle
20
+
21
+ To install manually without bundler:
22
+
23
+ $ gem install octopress-categories
24
+
25
+ Then add the gem to your Jekyll configuration.
26
+
27
+ gems:
28
+ - octopress-categories
29
+
30
+
31
+ ## Usage
32
+
33
+ For multilingual category pages, install [octopress-multilingual](https://github.com/octopress/multilingual).
34
+
35
+ ## Customize categories
36
+
37
+ To list detailed information about this plugin, run `$ octopress ink list categories`. This will output something like this:
38
+
39
+ ```
40
+ Plugin: Octopress Categories - v0.0.1
41
+ Slug: categories
42
+ Category pages for Octopress and Jekyll pages.
43
+ ================================================================================
44
+ includes:
45
+ - category_feed.xml
46
+ - category_index.html
47
+
48
+ config:
49
+ category_dir: "categories"
50
+ prefixes:
51
+ title: "Category: "
52
+ meta_description: "Category: "
53
+ feed:
54
+ enabled: false
55
+ count: 5
56
+ permalinks:
57
+
58
+ category-pages:
59
+ - announcements /categories/announcements/
60
+
61
+ ```
62
+
63
+ If you have posts written in English and German, and are using [octopress-multilingual](https://github.com/octopress/multilingual),
64
+ your permalinks will automatically be name-spaced by language, like this:
65
+
66
+ ```
67
+ category-pages:
68
+ - announcements-de /de/categories/announcements/
69
+ - announcements-en /en/categories/announcements/
70
+ ```
71
+
72
+ Octopress Ink can copy all of the plugin's assets to `_plugins/categories/*` where you can override them with your own modifications. This is
73
+ only necessary if you want to modify this plugin's behavior.
74
+
75
+ ```
76
+ octopress ink copy categories
77
+ ```
78
+
79
+ This will copy the plugin's configuration and includes from the gem, to your local site. If, for example, you want to change the HTML for a category's index, you can simply edit the `_plugins/includes/category_index.html` file.
80
+
81
+ If you want to revert to the defaults, simply delete any file you don't care to override from the `_plugins/categories/` directory.
82
+
83
+ ## Linking to the category pages
84
+
85
+ This plugin includes a handy filter `category_links` that allows you to automatically link to a post's category pages.
86
+ Here's how you use it:
87
+
88
+ ```
89
+ {% capture num_categories %}{% if post %}{{ post.categories | size }}{% else %}{{ page.categories | size }}{% endif %}{% endcapture %}
90
+ {% unless num_categories == '0' %}
91
+ <span class="categories">
92
+ {% if post %}
93
+ {{ post.categories | category_links }}
94
+ {% else %}
95
+ {{ page.categories | category_links }}
96
+ {% endif %}
97
+ </span>
98
+ {% endunless %}
99
+
100
+ ```
101
+
102
+ ## Configuration
103
+
104
+ To configure this plugin, first create a configuration file at `_plugins/categories/config.yml`. If you like, you can have Octopress Ink add it for you.
105
+
106
+ ```
107
+ $ octopress ink copy categories --config-file
108
+ ```
109
+
110
+ This will create a configuration file populated with the defaults for this plugin. Deleting this file will restore the default configuration.
111
+
112
+ ## Contributing
113
+
114
+ 1. Fork it ( https://github.com/drallgood/octopress-categories/fork )
115
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
116
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
117
+ 4. Push to the branch (`git push origin my-new-feature`)
118
+ 5. Create a new Pull Request
data/assets/config.yml ADDED
@@ -0,0 +1,7 @@
1
+ category_dir: categories
2
+ prefixes:
3
+ title: "Category: "
4
+ meta_description: "Category: "
5
+ feed:
6
+ enabled: false
7
+ count: 5
@@ -0,0 +1,7 @@
1
+ {% assign feed_type = 'category' %}{% include feeds:head.xml %}
2
+ {% for post in site.categories[page.category] limit: plugins.categories.feed_count %}
3
+ <entry>
4
+ {% include feeds:entry.xml %}
5
+ </entry>
6
+ {% endfor %}
7
+ </feed>
@@ -0,0 +1,22 @@
1
+ ---
2
+ layout: page
3
+ ---
4
+
5
+ <div class="category">
6
+ {% for post in site.categories[page.category] %}
7
+ {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
8
+ {% unless year == this_year %}
9
+ {% assign year = this_year %}
10
+ <h2>{{ year }}</h2>
11
+ {% endunless %}
12
+ <article>
13
+ <h3><a href="{{ root_url }}{{ post.url }}">{% if site.titlecase %}{{ post.title | titlecase }}{% else %}{{ post.title }}{% endif %}</a></h3>
14
+ <time datetime="{{ post.date | datetime | date_to_xmlschema }}" pubdate>{{ post.date | date: "<span class='month'>%b</span> <span class='day'>%d</span> <span class='year'>%Y</span>"}}</time>
15
+ {% if categoryNumber != '0' %}
16
+ <footer>
17
+ <span class="categories">Posted in {{ post.categories | category_links }}</span>
18
+ </footer>
19
+ {% endif %}
20
+ </article>
21
+ {% endfor %}
22
+ </div>
@@ -0,0 +1,95 @@
1
+ require 'octopress-ink'
2
+ require 'octopress-categories/version'
3
+ require 'octopress-categories/page_asset'
4
+ require 'octopress-categories/filters'
5
+
6
+ module Octopress
7
+ module Categories
8
+ class Plugin < Ink::Plugin
9
+
10
+ attr_reader :category_pages
11
+
12
+ def initialize(options)
13
+ super
14
+ @category_pages = []
15
+ end
16
+
17
+ def register
18
+ super
19
+ unless @assets_path.nil?
20
+ if Octopress::Ink.enabled?
21
+ add_category_pages
22
+ end
23
+ end
24
+ end
25
+
26
+ def assets
27
+ superAssets = super
28
+ superAssets.merge!({
29
+ "category-pages" => @category_pages
30
+ })
31
+ end
32
+
33
+ def add_category_pages
34
+
35
+ # Find the correct template
36
+ template = @includes.detect { |l|
37
+ l.file == "category_index.html"
38
+ }
39
+
40
+ created_pages = []
41
+ if defined? Octopress::Multilingual
42
+ # We need to create pages for each language
43
+ Octopress.site.languages.each do |lang|
44
+ category_pages_lang = createCategoryPages(template, config(lang))
45
+ category_pages_lang.each { |p|
46
+ p.data.merge!({"lang"=>lang})
47
+ }
48
+ created_pages.concat(category_pages_lang)
49
+ end
50
+ else
51
+ created_pages = createCategoryPages(template, config)
52
+ end
53
+
54
+ @category_pages.concat(created_pages)
55
+ end
56
+
57
+ def createCategoryPages(template, config)
58
+ categoryPages = []
59
+ Octopress.site.categories.keys.each do |category|
60
+ categoryPages << CategoryPageAsset.new(self, template, category)
61
+ end
62
+ categoryPages
63
+ end
64
+
65
+ def add_asset_files(options)
66
+ options << "category-pages"
67
+ super
68
+ end
69
+
70
+ def category_dir(category)
71
+ category_base_dir = config['category_dir'].gsub(/^\/*(.*)\/*$/, '\1')
72
+ # Make sure the category directory begins with a slash.
73
+ category_base_dir = "/#{category_base_dir}" unless category_base_dir =~ /^\//
74
+ File.join(category_base_dir, slugifyCategory(category))
75
+ end
76
+
77
+ def slugifyCategory(category)
78
+ category.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-').tr( '^A-Za-z0-9\-_', '-' ).downcase
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ #Octopress::Ink.add_plugin({
85
+ Octopress::Ink::Plugins.register_plugin(Octopress::Categories::Plugin,{
86
+ name: "Octopress Categories",
87
+ slug: "categories",
88
+ gem: "octopress-categories",
89
+ path: File.expand_path(File.join(File.dirname(__FILE__), "..")),
90
+ type: "plugin",
91
+ version: Octopress::Categories::VERSION,
92
+ description: "Category pages for Octopress and Jekyll pages.", # What does your theme/plugin do?
93
+ source_url: "https://github.com/drallgood/octopress-categories",
94
+ website: "https://github.com/drallgood/octopress-categories" # Optional project website
95
+ })
@@ -0,0 +1,37 @@
1
+ module Octopress
2
+ module Categories
3
+ module Filters
4
+ # Outputs a list of categories as comma-separated <a> links. This is used
5
+ # to output the category list for each post on a category page.
6
+ #
7
+ # +categories+ is the list of categories to format.
8
+ #
9
+ # Returns string
10
+ def category_links(categories)
11
+ plugin = Ink::Plugins.plugin("categories")
12
+ root = @context.registers[:site].baseurl
13
+ language = @context.registers[:page]['lang']
14
+
15
+
16
+ categories = categories.sort!.map do |category|
17
+ category_dir = plugin.category_dir(category)
18
+
19
+ if language
20
+ category_dir = "/#{language}#{category_dir}"
21
+ end
22
+ "<a class='category' href='#{root}#{category_dir}/'>#{category.capitalize}</a>"
23
+ end
24
+
25
+ case categories.length
26
+ when 0
27
+ ""
28
+ when 1
29
+ categories[0].to_s
30
+ else
31
+ categories.join(', ')
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ Liquid::Template.register_filter(Octopress::Categories::Filters)
@@ -0,0 +1,65 @@
1
+ module Octopress
2
+ module Categories
3
+ class CategoryPageAsset < Ink::Assets::PageAsset
4
+
5
+ attr_accessor :category
6
+
7
+ def initialize(plugin, template, category)
8
+ super(plugin, template.base, template.file)
9
+ self.category = category
10
+ end
11
+
12
+ def clone(plugin, template, category)
13
+ p = CategoryPageAsset.new(plugin, template, category)
14
+ p
15
+ end
16
+
17
+ def copy(target_dir)
18
+ # Don't copy anything
19
+ end
20
+
21
+ def info
22
+ message = super
23
+ name = permalink_name << page.ext
24
+ message.sub!(/#{name}\s*/, permalink_name.ljust(35))
25
+ message.sub!(/#{filename}\s*/, filename.ljust(35))
26
+ message.sub!(/\.\/#{filename}*/, "#{@plugin.slug}/includes/#{filename}")
27
+ message
28
+ end
29
+
30
+ def permalink_name
31
+ name = plugin.slugifyCategory(category)
32
+ if lang
33
+ name = "#{name}-#{lang}"
34
+ end
35
+ name
36
+ end
37
+
38
+ def permalink
39
+ link = "/#{plugin.category_dir(category)}/"
40
+ if lang
41
+ link = "/#{lang}#{link}"
42
+ end
43
+ link
44
+ end
45
+
46
+ def category=(category)
47
+ title_prefix = plugin.config['prefixes']['title'] || 'Category: '
48
+ meta_description_prefix = plugin.config['prefixes']['meta_description'] || 'Category: '
49
+ @data.merge!({
50
+ "category"=>category,
51
+ "title"=>"#{title_prefix}#{category.capitalize}",
52
+ "description"=>"#{meta_description_prefix}#{category.capitalize}"
53
+ })
54
+ @category = category
55
+ @category_dir = plugin.category_dir(category)
56
+ end
57
+
58
+ private
59
+
60
+ def lang
61
+ data['lang']
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module Categories
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-categories
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrice Brend'amour
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octopress-ink
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0.rc
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0.rc
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: octopress
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: clash
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: octopress-multilingual
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: octopress-debugger
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - patrice@brendamour.net
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - CHANGELOG.md
119
+ - LICENSE.txt
120
+ - README.md
121
+ - assets/config.yml
122
+ - assets/includes/category_feed.xml
123
+ - assets/includes/category_index.html
124
+ - lib/octopress-categories.rb
125
+ - lib/octopress-categories/filters.rb
126
+ - lib/octopress-categories/page_asset.rb
127
+ - lib/octopress-categories/version.rb
128
+ homepage: ''
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Category pages for Octopress and Jekyll pages.
152
+ test_files: []