Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a not-found page for broken links #2

Merged
merged 1 commit into from

2 participants

@dohzya
Collaborator

Resolves #1

@guillaumebort guillaumebort merged commit b532bd8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2013
  1. @dohzya

    Add a not-found page for broken links

    dohzya authored
    Resolves #1
This page is out of date. Refresh to see the latest.
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)
Something went wrong with that request. Please try again.