nesta-plugin-dateslugs 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.mdown +35 -0
- data/Rakefile +1 -0
- data/lib/nesta-plugin-dateslugs.rb +3 -0
- data/lib/nesta-plugin-dateslugs/init.rb +38 -0
- data/lib/nesta-plugin-dateslugs/version.rb +7 -0
- data/nesta-plugin-dateslugs.gemspec +22 -0
- metadata +11 -2
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Adam Michel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.mdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Date Slugs on Blog Posts for Nesta CMS
|
2
|
+
|
3
|
+
This plugin will add the post date to the URL for your blogs posts in [Nesta](http://nestacms.com). Right now the date format is hard-coded in the year/month/permalink format, but plans are already in place to allow customizations to the format. An example of a link would be "2012/07/sample-post". Users migrating from other blogging tools are probably familiar with this format already.
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
Add the following line to your Gemfile:
|
8
|
+
|
9
|
+
gem 'nesta-plugin-dateslugs'
|
10
|
+
|
11
|
+
### Usage
|
12
|
+
|
13
|
+
The plugin will automatically update the permalinks for all blog posts. Blog posts are defined as pages that have a Post Date in their metadata. In order for the plugin to work correctly you must ensure your theme uses the article permalink method and not the abspath method.
|
14
|
+
|
15
|
+
## TODO
|
16
|
+
|
17
|
+
* Allow date format to be customized.
|
18
|
+
* Improve matching of dates in paths.
|
19
|
+
|
20
|
+
## Pull Requests
|
21
|
+
|
22
|
+
* Fork this project.
|
23
|
+
* Create a feature or hotfix branch.
|
24
|
+
* Make changes.
|
25
|
+
* Commit changes without modifying the rakefile, version, or changelog.
|
26
|
+
(I will update those as needed.)
|
27
|
+
* Submit a pull request.
|
28
|
+
|
29
|
+
## Thanks
|
30
|
+
|
31
|
+
Special thanks to [Wynn Netherland](http://wynnnetherland.com/), most of this plugin is based on his [nesta-plugin-sluggable](https://github.com/pengwynn/nesta-plugin-sluggable) plugin.
|
32
|
+
|
33
|
+
## Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2012 Adam Michel. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Plugin
|
3
|
+
module Dateslugs
|
4
|
+
DATE_MATCH = /\d{4}\/\d{2}\/[\w-]+$/
|
5
|
+
DATE_FORMAT = "%Y/%m"
|
6
|
+
|
7
|
+
def self.resolve_path(path)
|
8
|
+
segments = path.split('/')
|
9
|
+
date_path = segments[-3..4]
|
10
|
+
if date_path && date_path.join('/').match(DATE_MATCH)
|
11
|
+
path = segments[0..-4].push(segments.last).join('/')
|
12
|
+
end
|
13
|
+
path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class App
|
19
|
+
before do
|
20
|
+
params[:splat] = [ Nesta::Plugin::Dateslugs.resolve_path(request.path) ]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Page
|
25
|
+
def article?
|
26
|
+
self.metadata('date') != nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def permalink
|
30
|
+
if self.article?
|
31
|
+
date_slug = DateTime.parse(metadata('date')).strftime(Nesta::Plugin::Dateslugs::DATE_FORMAT)
|
32
|
+
File.join(File.dirname(self.abspath), "#{date_slug}/#{super}")
|
33
|
+
else
|
34
|
+
self.abspath
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "nesta-plugin-dateslugs/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nesta-plugin-dateslugs"
|
7
|
+
s.version = Nesta::Plugin::Dateslugs::VERSION
|
8
|
+
s.authors = ["Adam Michel"]
|
9
|
+
s.email = ["awmichel90@gmail.com"]
|
10
|
+
s.homepage = "http://amichel.me"
|
11
|
+
s.summary = %q{Date slugs in blog posts for Nesta CMS.}
|
12
|
+
s.description = %q{Adds the post date to blog post permalinks in Nesta CMS.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "nesta-plugin-dateslugs"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_dependency("nesta", ">= 0.9.13")
|
21
|
+
s.add_development_dependency("rake")
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nesta-plugin-dateslugs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -49,7 +49,16 @@ email:
|
|
49
49
|
executables: []
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
|
-
files:
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.mdown
|
57
|
+
- Rakefile
|
58
|
+
- lib/nesta-plugin-dateslugs.rb
|
59
|
+
- lib/nesta-plugin-dateslugs/init.rb
|
60
|
+
- lib/nesta-plugin-dateslugs/version.rb
|
61
|
+
- nesta-plugin-dateslugs.gemspec
|
53
62
|
homepage: http://amichel.me
|
54
63
|
licenses: []
|
55
64
|
post_install_message:
|