Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from dohzya/master

Add a not-found page for broken links
  • Loading branch information...
commit b532bd8f04e43bc63df6f8ad45e214ebe79a2b97 2 parents ae1531e + 8afbb3d
@guillaumebort guillaumebort authored
View
9 app/controllers/Application.scala
@@ -15,10 +15,15 @@ object Application extends Controller {
// -- Resolve links to documents
def linkResolver(api: Api, ref: Option[String])(implicit request: RequestHeader) = DocumentLinkResolver(api) {
case (Fragment.DocumentLink(id, docType, tags, slug, false), maybeBookmarked) => routes.Application.detail(id, slug, ref).absoluteURL()
+ case (link@Fragment.DocumentLink(_, _, _, _, true), _) => routes.Application.brokenLink(ref).absoluteURL()
}
// -- Page not found
- def PageNotFound(implicit ctx: Prismic.Context) = NotFound("Page not found")
+ def PageNotFound(implicit ctx: Prismic.Context) = NotFound(views.html.pageNotFound())
+
+ def brokenLink(ref: Option[String]) = Prismic.action(ref) { implicit request =>
+ Future.successful(PageNotFound)
+ }
// -- Home page
def index(ref: Option[String]) = Prismic.action(ref) { implicit request =>
@@ -50,4 +55,4 @@ object Application extends Controller {
}
}
-}
+}
View
19 app/views/pageNotFound.scala.html
@@ -0,0 +1,19 @@
+@()(implicit ctx: Prismic.Context)
+
+@main("Document not found") {
+
+ <section>
+ <h1>Page not found</h1>
+ </section>
+
+ <section>
+ <p>
+ We can't seem to find what you are looking for.
+ </p>
+
+ <p>
+ <a href="@routes.Application.index(ref = ctx.maybeRef)">Go to the home page</a>
+ </p>
+ </section>
+
+}
View
2  conf/routes
@@ -16,5 +16,7 @@ GET /signin controllers.Prismic.signin
GET /auth_callback controllers.Prismic.callback(code: Option[String], redirect_uri: Option[String])
POST /signout controllers.Prismic.signout()
+GET /not-found controllers.Application.brokenLink(ref: Option[String] ?= None)
+
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
Please sign in to comment.
Something went wrong with that request. Please try again.