Skip to content

Commit

Permalink
Added page redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Olayvar committed Sep 16, 2014
1 parent bb7d2ba commit 75395a0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .metalsmith/metal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
path = require 'path'
highlightjs = require 'highlight.js'
marked = require 'marked'
marked = require 'marked'
metalsmith = require 'metalsmith'
collections = require 'metalsmith-collections'
excerpts = require 'metalsmith-excerpts'
Expand All @@ -24,6 +24,7 @@ moment = require './plugins/moment'
feed = require './plugins/feed'
filename = require './plugins/filename'
newPage = require './plugins/new-page'
redirects = require './plugins/redirects'
series = require './plugins/series'
snapshot = require './plugins/snapshot'
tags = require './plugins/tags'
Expand Down Expand Up @@ -148,6 +149,8 @@ module.exports = build = (callback=->) ->
collection: 'guide'
output: 'guides'
metadata: template: 'guides.toffee'
# Create our redirects
.use redirects()
.use permalinks()
.use filename()
.use aboutSchema() # Add itemprop='about' to the first para
Expand Down
41 changes: 21 additions & 20 deletions .metalsmith/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"private": true,
"devDependencies": {
"metalsmith": "https://github.com/leeolayvar/metalsmith/tarball/ignores-support",
"metalsmith-markdown": "^0.2.1",
"metalsmith-templates": "^0.5.0",
"metalsmith-collections": "https://github.com/leeolayvar/metalsmith-collections/tarball/fileName",
"async": "^0.9.0",
"cheerio": "^0.17.0",
"clone": "^0.1.15",
"coffee-script": "^1.7.1",
"connect": "^2.14.5",
"gulp": "3.6.2",
"gulp-coffee": "^1.4.3",
"gulp-concat": "^2.3.4",
"gulp-minify-css": "^0.3.7",
"gulp-minify-html": "^0.1.4",
"gulp-sass": "^0.7.1",
"gulp-uglify": "^0.3.1",
"gulp-util": "^2.2.14",
"coffee-script": "^1.7.1",
"toffee": "^0.1.8",
"connect": "^2.14.5",
"metalsmith-permalinks": "^0.3.0",
"clone": "^0.1.15",
"moment": "^2.6.0",
"highlight.js": "^8.0.0",
"js-yaml": "^3.2.2",
"marked": "^0.3.2",
"metalsmith": "https://github.com/leeolayvar/metalsmith/tarball/ignores-support",
"metalsmith-collections": "https://github.com/leeolayvar/metalsmith-collections/tarball/fileName",
"metalsmith-excerpts": "^1.0.0",
"sanitize-html": "^1.1.5",
"gulp-coffee": "^1.4.3",
"metalsmith-ignore": "^0.1.2",
"cheerio": "^0.17.0",
"metalsmith-markdown": "^0.2.1",
"metalsmith-metadata": "0.0.1",
"highlight.js": "^8.0.0",
"async": "^0.9.0",
"marked": "^0.3.2",
"gulp-uglify": "^0.3.1",
"gulp-minify-html": "^0.1.4",
"gulp-minify-css": "^0.3.7",
"gulp-concat": "^2.3.4"
"metalsmith-permalinks": "^0.3.0",
"metalsmith-templates": "^0.5.0",
"moment": "^2.6.0",
"sanitize-html": "^1.1.5",
"toffee": "^0.1.8"
},
"dependencies": {}
}
34 changes: 34 additions & 0 deletions .metalsmith/plugins/redirects.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# # Redirect
#
# A plugin to create pages based off of a template and source json
# file.
#
fs = require 'fs'
yaml = require 'js-yaml'
newPage = require './new-page'




module.exports = (opts={}) ->
opts.redirects ?= '../redirects.yaml'
opts.template ?= 'redirect.toffee'

redirects = yaml.safeLoad fs.readFileSync opts.redirects, 'utf8'

(files, metalsmith, done) ->
redirectKeys = Object.keys redirects
do next = ->
rSource = redirectKeys.pop()
if not rSource? then return done()
rDestination = redirects[rSource]

pageOpts =
output: rSource
metadata:
template: opts.template
source: rSource
destination: rDestination
newPage(pageOpts) files, metalsmith, next

3 changes: 3 additions & 0 deletions .metalsmith/templates/head.toffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
{# if redirect? {:
<meta http-equiv="refresh" content="0; url=#{redirect}">
:} #}

<!-- og meta tags -->
<meta property="og:title" content="Koding - Say goodbye to localhost!"/>
Expand Down
14 changes: 14 additions & 0 deletions .metalsmith/templates/redirect.toffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#{partial 'head.toffee', redirect: destination}
#{partial 'topnav.toffee'}
<section><div id="page-404" class="container">

<div class="content">
<h2>Redirecting</h2>
<p>
The page you requested has been moved. If you think this is in
error, please <a href="mailto:[email protected]" target="_self">Contact Us</a>.
</p>
</div>

</div></section>
#{partial 'footer.toffee'}
Empty file added redirects.yaml
Empty file.

0 comments on commit 75395a0

Please sign in to comment.