middleman-alias 0.0.4 → 0.0.5

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: 9e459db1e42529ea5a80a6edf53cc0460ba042b2
4
- data.tar.gz: 3e2eb036036e5a6a0e25be82e12aef8e20867025
3
+ metadata.gz: 754e56bc3e820823ad8f8350913dad8dc0a21968
4
+ data.tar.gz: 3452f4063590e36fd4560dea70cd7dcd71dd03d5
5
5
  SHA512:
6
- metadata.gz: 99c3e65a144941c371c08124d5890b1b747b0946f606b8bebe70a35b08166668a62ff2067794d963d9f0c690255032e742d62aa6df21a03d251f000f34e08177
7
- data.tar.gz: bf1543cde5edc7025e6b7fb09dd90337547ccce4fc7c2127ef995017511d64b45c937f4f4485b8d54d4e65c70c9389d13c921ea9e51d6fd292abdfefdc8d8129
6
+ metadata.gz: ebdef422e91472f4afd11cf1527076d3a636fff865cb7119316f474b805cfda4111919e3d7da23ae0301e6aa63f11bdec6d72904649b481a0721f2c15f9c784f
7
+ data.tar.gz: a7a761d330a47766c0f875590d9eb394f099801ad9679666c23d201f4f8ac6821d9d7cafdf368bb15f4483d97e462f1290e47ec1acdc152630d2eb460c696856
data/README.md CHANGED
@@ -27,13 +27,6 @@ alias redirect pages are generated.
27
27
  activate :alias
28
28
  ```
29
29
 
30
- Then you need to generate the template that will handle the aliases.
31
- You only need to do this one time.
32
-
33
- ```
34
- middleman alias_template
35
- ```
36
-
37
30
  Then you can add an `alias` to the frontmatter for a page or post and
38
31
  middleman-alias will generate a SEO friendly redirect page at that
39
32
  location.
@@ -50,6 +43,17 @@ alias : /old-foo.html
50
43
  Now someone can visit your middleman site at `/old-foo.html` and they'll
51
44
  be redirected to `/foo.html`.
52
45
 
46
+ If you end an alias with a `/` that alias will be treated as a virtual
47
+ directory.
48
+
49
+ ```
50
+ title : "A post about foo"
51
+ alias : /old-foo/
52
+ ```
53
+
54
+ The example above will result in a redirect file being generated at
55
+ `/old-foo/index.html`, which will be accessible to browsers at `/old-foo/`.
56
+
53
57
  ## Contributing
54
58
 
55
59
  1. Fork it ( http://github.com/<my-github-username>/middleman-alias/fork )
@@ -1,5 +1,6 @@
1
1
  Feature: Virtual directories
2
- Given a fixture app "alias-app"
3
- When I go to "/posts/2010/01/01/virtual-test/"
4
- Then I should see "You are being redirected"
2
+ Scenario: Aliases that end with a slash should be treated as a virtual directory
3
+ Given the Server is running at "alias-app"
4
+ When I go to "/posts/2010/01/01/virtual-test/"
5
+ Then I should see "You are being redirected"
5
6
 
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Virtual"
3
+ alias: posts/2010/01/01/virtual-test/
4
+ ---
5
+
6
+ This is a test for virtual directories.
@@ -1,6 +1,5 @@
1
1
  require 'middleman-core'
2
2
  require "middleman-alias/version"
3
- require "middleman-alias/commands"
4
3
 
5
4
  ::Middleman::Extensions.register(:alias) do
6
5
  require 'middleman-alias/extension'
@@ -0,0 +1,51 @@
1
+ module Middleman
2
+ module Sitemap
3
+ class AliasResource < ::Middleman::Sitemap::Resource
4
+
5
+ attr_accessor :output
6
+
7
+ def initialize(store, path, alias_path)
8
+ @alias_path = alias_path
9
+ super(store, path)
10
+ end
11
+
12
+ def template?
13
+ false
14
+ end
15
+
16
+ def render(*args, &block)
17
+ %[
18
+ <html>
19
+ <head>
20
+ <meta http-equiv=refresh content="0; url=#{@alias_path}" />
21
+ <meta name="robots" content="noindex,follow" />
22
+ <meta http-equiv="cache-control" content="no-cache" />
23
+ </head>
24
+ <body>
25
+ <a href="#{@alias_path}">You are being redirected.</a>
26
+ </body>
27
+ </html>
28
+ ]
29
+ end
30
+
31
+ def binary?
32
+ false
33
+ end
34
+
35
+ def raw_data
36
+ {}
37
+ end
38
+
39
+ def ignored?
40
+ false
41
+ end
42
+
43
+ def metadata
44
+ @local_metadata.dup
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ end
51
+
@@ -1,4 +1,5 @@
1
1
  require 'middleman-core'
2
+ require 'middleman-alias/alias-resource'
2
3
 
3
4
  module Middleman
4
5
  class AliasExtension < Middleman::Extension
@@ -10,14 +11,15 @@ module Middleman
10
11
  resources.each do |resource|
11
12
  if resource.data["alias"]
12
13
  alias_url = resource.data["alias"]
13
- alias_url += "/index.html" if alias_url.match(/\/$/)
14
- Sitemap::Resource.new(@app.sitemap, alias_url).tap do |p|
15
- p.proxy_to("alias.html")
16
- p.add_metadata locals: {
17
- destination: resource.url
18
- }
19
- resources.push p
20
- end
14
+ alias_url += "index.html" if alias_url.match(/\/$/)
15
+ resources.push Middleman::Sitemap::AliasResource.new(@app.sitemap, alias_url, resource.url)
16
+ #Sitemap::Resource.new(@app.sitemap, alias_url).tap do |p|
17
+ #p.proxy_to("alias.html")
18
+ #p.add_metadata locals: {
19
+ #destination: resource.url
20
+ #}
21
+ #resources.push p
22
+ #end
21
23
  end
22
24
  end
23
25
  resources
@@ -1,3 +1,3 @@
1
1
  module MiddlemanAlias
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-alias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Green
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -93,19 +93,17 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - features/alias.feature
96
- - features/generator_cli.feature
97
96
  - features/support/env.rb
98
97
  - features/virtual-directory.feature
99
98
  - fixtures/alias-app/config.rb
100
- - fixtures/alias-app/source/alias.html.erb
101
99
  - fixtures/alias-app/source/bar.html.erb
102
100
  - fixtures/alias-app/source/layout.html.erb
101
+ - fixtures/alias-app/source/virtual.html.erb
103
102
  - fixtures/empty-alias-app/config.rb
104
103
  - fixtures/empty-alias-app/source/.gitkeep
105
104
  - lib/middleman-alias.rb
106
- - lib/middleman-alias/commands.rb
105
+ - lib/middleman-alias/alias-resource.rb
107
106
  - lib/middleman-alias/extension.rb
108
- - lib/middleman-alias/template/source/alias.html.erb
109
107
  - lib/middleman-alias/version.rb
110
108
  - lib/middleman_extension.rb
111
109
  - middleman-alias.gemspec
@@ -135,6 +133,5 @@ specification_version: 4
135
133
  summary: Redirects for Middleman that are friendly to the Googles.
136
134
  test_files:
137
135
  - features/alias.feature
138
- - features/generator_cli.feature
139
136
  - features/support/env.rb
140
137
  - features/virtual-directory.feature
@@ -1,7 +0,0 @@
1
- Feature: Template generator CLI command
2
- Scenario: Create a new alias template with the command line
3
- Given a fixture app "empty-alias-app"
4
- And I run `middleman alias_template`
5
- Then the exit status should be 0
6
- Then the following files should exist:
7
- | source/alias.html.erb |
@@ -1,3 +0,0 @@
1
- <meta http-equiv="refresh" content="0; url=<%= destination %>">
2
- <link rel="canonical" href="<%= destination %>" />
3
- <%= link_to "You are being redirected.", destination %>
@@ -1,33 +0,0 @@
1
- require 'middleman-core/cli'
2
-
3
- module Middleman
4
- module Cli
5
- # This class provides an "article" command for the middleman CLI.
6
- class AliasGenerator < Thor
7
- include Thor::Actions
8
-
9
- check_unknown_options!
10
-
11
- namespace :alias_template
12
-
13
- def self.source_root
14
- ENV['MM_ROOT']
15
- end
16
-
17
- # Tell Thor to exit with a nonzero exit code on failure
18
- def self.exit_on_failure?
19
- true
20
- end
21
-
22
- desc "alias_template", "Create a new template to handle alias redirects"
23
-
24
- def alias_template
25
- source_root = ENV['MM_ROOT']
26
- template_sub_path = "source/alias.html.erb"
27
- template_filename = "#{source_root}/#{template_sub_path}"
28
- FileUtils.cp "#{File.dirname(__FILE__)}/template/source/alias.html.erb", template_filename
29
- puts "Alias template generated in #{template_sub_path}"
30
- end
31
- end
32
- end
33
- end
@@ -1,4 +0,0 @@
1
- <meta http-equiv="refresh" content="0; url=<%= destination %>">
2
- <link rel="canonical" href="<%= destination %>" />
3
- <%= link_to "You are being redirected.", destination %>
4
-