diff options
| author | Vojta Jina | 2011-06-06 23:03:04 +0200 | 
|---|---|---|
| committer | Igor Minar | 2011-06-06 23:10:30 -0700 | 
| commit | 4cdce2d30b0f78c9bae4f9fd8751583c6ccca610 (patch) | |
| tree | 538e5e447534eb0c450d08cd3d6fc74a5fc5e086 /docs/src/templates/docs.js | |
| parent | 48e69ed4d1e672ec849344e9bf3ad1dbdd68f21a (diff) | |
| download | angular.js-4cdce2d30b0f78c9bae4f9fd8751583c6ccca610.tar.bz2 | |
Docs: Error 404 page with simple suggestion for new links
Diffstat (limited to 'docs/src/templates/docs.js')
| -rw-r--r-- | docs/src/templates/docs.js | 25 | 
1 files changed, 24 insertions, 1 deletions
| diff --git a/docs/src/templates/docs.js b/docs/src/templates/docs.js index b6da7b97..99ca0599 100644 --- a/docs/src/templates/docs.js +++ b/docs/src/templates/docs.js @@ -15,7 +15,7 @@ function DocsController($location, $browser, $window) {        self.sectionId = parts[1];        self.partialId = parts[2] || 'index';        self.pages = angular.Array.filter(NG_PAGES, {section:self.sectionId}); -      self.partialTitle = (angular.Array.filter(self.pages, function(doc){return doc.id == self.partialId;})[0]||{}).name; +      self.partialTitle = (angular.Array.filter(self.pages, function(doc){return doc.id == self.partialId;})[0]||{}).name || 'Error: Page Not Found!';      }    }); @@ -84,3 +84,26 @@ function TutorialInstructionsCtrl($cookieStore) {      $cookieStore.put('selEnv', id);    };  } + +/** + * Display 404 page and suggest new link if possible + */ +angular.service('$xhr.error', function($location) { +  function suggestLink(wrongLink) { +    var link = wrongLink.replace(/^!\/?/, ''); + +    if (link.match(/^angular/)) return 'api/' + link; +    else if (link.match(/^cookbook/)) return link.replace('cookbook.', 'cookbook/'); +  } + +  return function(request, response) { +    var suggestion = suggestLink($location.hashPath), +        HTML_404 = '<h1>Error: Page Not Found</h1>' + +                   '<p>Sorry this page has not been found.</p>'; + +    if (suggestion) +      HTML_404 += '<p>Looks like you are using an old link. Please update your bookmark to: <a href="#!/' + suggestion + '">' + suggestion + '</a></p>'; + +    request.callback(200, HTML_404); +  }; +}); | 
