nesta-plugin-sluggable 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.mdown +49 -0
- data/Rakefile +1 -0
- data/lib/nesta-plugin-sluggable.rb +3 -0
- data/lib/nesta-plugin-sluggable/init.rb +54 -0
- data/lib/nesta-plugin-sluggable/version.rb +7 -0
- data/nesta-plugin-sluggable.gemspec +22 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.mdown
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Sluggable posts for Nesta CMS
|
|
2
|
+
|
|
3
|
+
This plugin allows you to create [Nesta](http://nestacms.com) articles with an numeric filename (probably based on date and serial) but serve the page with an SEO-friendly slug, like so [http://wynnnetherland.com/linked/2011092203/making-blogazine-with-nesta](http://wynnnetherland.com/linked/2011092203/making-blogazine-with-nesta). The slug is optional. As long as the numeric filename path is included, Nesta will redirect to add the current slug.
|
|
4
|
+
|
|
5
|
+
Sluggable posts provide a few of benefits:
|
|
6
|
+
|
|
7
|
+
* You can change the slug if your headline changes and Nesta will automatically find the new article.
|
|
8
|
+
* You don't have to know your headline and slug when you create your file.
|
|
9
|
+
* Mangled, truncated URLs can still find the way to the latest version of your page.
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
|
|
13
|
+
To install add the plugin to your Nesta Gemfile
|
|
14
|
+
|
|
15
|
+
gem "nesta-plugin-sluggable"
|
|
16
|
+
|
|
17
|
+
### Setting the slug
|
|
18
|
+
|
|
19
|
+
Slugs can be set in the page [metadata](http://nestacms.com/docs/creating-content/metadata-reference):
|
|
20
|
+
|
|
21
|
+
date: 2011-09-24
|
|
22
|
+
slug: this-is-my-first-sluggable-post
|
|
23
|
+
|
|
24
|
+
# This is the headline
|
|
25
|
+
|
|
26
|
+
Alternatively, if not set, Sluggable will dasherize the heading to create the slug.
|
|
27
|
+
|
|
28
|
+
### Considerations
|
|
29
|
+
|
|
30
|
+
In order to avoid a `301` redirect for all sluggable page links on your site, use the `permalink` method in your templates instead of `abspath`.
|
|
31
|
+
|
|
32
|
+
### TODO
|
|
33
|
+
|
|
34
|
+
* Nesta CLI option to create posts
|
|
35
|
+
|
|
36
|
+
## Note on Patches/Pull Requests
|
|
37
|
+
|
|
38
|
+
* Fork the project.
|
|
39
|
+
* Make your feature addition or bug fix.
|
|
40
|
+
* Add tests for it. This is important so I don't break it in a
|
|
41
|
+
future version unintentionally.
|
|
42
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
43
|
+
(if you want to have your own version, that is fine but
|
|
44
|
+
bump version in a commit by itself I can ignore when I pull)
|
|
45
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
46
|
+
|
|
47
|
+
## Copyright
|
|
48
|
+
|
|
49
|
+
Copyright (c) 2011 Wynn Netherland. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Nesta
|
|
2
|
+
module Plugin
|
|
3
|
+
module Sluggable
|
|
4
|
+
module Helpers
|
|
5
|
+
# If your plugin needs any helper methods, add them here...
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
SLUGGED_FORMAT = /^\d+$/
|
|
9
|
+
|
|
10
|
+
def self.resolve_path(path)
|
|
11
|
+
segments = path.split('/')
|
|
12
|
+
path = segments[0..-2].join('/') if segments[-2].to_s.match(SLUGGED_FORMAT)
|
|
13
|
+
|
|
14
|
+
path
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class App
|
|
20
|
+
helpers Nesta::Plugin::Sluggable::Helpers
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
params[:splat] = [ Nesta::Plugin::Sluggable.resolve_path(request.path) ]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
after do
|
|
27
|
+
redirect(@page.permalink, 301) if (@page and !@page.best_path?(request.path))
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Page
|
|
32
|
+
|
|
33
|
+
def best_path?(path)
|
|
34
|
+
path == permalink
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def slug
|
|
38
|
+
return nil unless File.basename(self.filename, File.extname(self.filename)).match(Plugin::Sluggable::SLUGGED_FORMAT)
|
|
39
|
+
|
|
40
|
+
s = self.metadata('slug')
|
|
41
|
+
s = self.heading.to_s.downcase.gsub(/[^a-z1-9]+/, '-').chomp('-') if s.nil?
|
|
42
|
+
|
|
43
|
+
s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def permalink
|
|
47
|
+
p = self.abspath
|
|
48
|
+
p += '/' + self.slug if self.slug
|
|
49
|
+
|
|
50
|
+
p
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "nesta-plugin-sluggable/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "nesta-plugin-sluggable"
|
|
7
|
+
s.version = Nesta::Plugin::Sluggable::VERSION
|
|
8
|
+
s.authors = ["Wynn Netherland"]
|
|
9
|
+
s.email = ["wynn.netherland@gmail.com"]
|
|
10
|
+
s.homepage = ""
|
|
11
|
+
s.summary = %q{Sluggable posts for Nesta}
|
|
12
|
+
s.description = %q{Sluggable posts for Nesta CMS}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "nesta-plugin-sluggable"
|
|
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.11")
|
|
21
|
+
s.add_development_dependency("rake")
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nesta-plugin-sluggable
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Wynn Netherland
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-09-25 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: nesta
|
|
16
|
+
requirement: &70272858836980 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.9.11
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70272858836980
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: rake
|
|
27
|
+
requirement: &70272858836300 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70272858836300
|
|
36
|
+
description: Sluggable posts for Nesta CMS
|
|
37
|
+
email:
|
|
38
|
+
- wynn.netherland@gmail.com
|
|
39
|
+
executables: []
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- .gitignore
|
|
44
|
+
- Gemfile
|
|
45
|
+
- README.mdown
|
|
46
|
+
- Rakefile
|
|
47
|
+
- lib/nesta-plugin-sluggable.rb
|
|
48
|
+
- lib/nesta-plugin-sluggable/init.rb
|
|
49
|
+
- lib/nesta-plugin-sluggable/version.rb
|
|
50
|
+
- nesta-plugin-sluggable.gemspec
|
|
51
|
+
homepage: ''
|
|
52
|
+
licenses: []
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
segments:
|
|
64
|
+
- 0
|
|
65
|
+
hash: -989716529246446269
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ! '>='
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
segments:
|
|
73
|
+
- 0
|
|
74
|
+
hash: -989716529246446269
|
|
75
|
+
requirements: []
|
|
76
|
+
rubyforge_project: nesta-plugin-sluggable
|
|
77
|
+
rubygems_version: 1.8.6
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 3
|
|
80
|
+
summary: Sluggable posts for Nesta
|
|
81
|
+
test_files: []
|