rewrites.coffee 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. moved = (from, to) ->
  2. { from: from, to: '_show/moved', query: {loc: to} }
  3. movedPattern = (from, to) ->
  4. { from: from, to: '_show/moved_pattern', query: {loc: to} }
  5. module.exports = [
  6. # Static files from the root
  7. { from: '/static/*', to: 'static/*' }
  8. # Dynamic site rendering used with a virtual host like:
  9. # www.somesite.com = /kleks/_design/site/_rewrite/render/www.somesite.com
  10. {
  11. from: '/render/:site',
  12. to: '_list/home/docs_for_home',
  13. query: {
  14. startkey: [':site', {}],
  15. endkey: [':site'],
  16. descending: 'true'
  17. }
  18. }
  19. # Some routes to static files needed under the dynamic site path
  20. { from: '/render/:site/static/*', to: 'static/*' }
  21. { from: '/render/:site/modules.js', to: 'modules.js' }
  22. { from: '/render/:site/duality.js', to: 'duality.js' }
  23. # Collection page - list of docs
  24. {
  25. from: '/render/:site/collection/:slug',
  26. to: '_list/collection/docs_by_collection',
  27. query: {
  28. startkey: [':site', ':slug', {}],
  29. endkey: [':site', ':slug'],
  30. descending: 'true',
  31. include_docs: 'true'
  32. }
  33. }
  34. # Collection JSON view - list of docs ONLY
  35. # {
  36. # from: '/render/:site/json/collection/:slug',
  37. # to: '_view/docs_by_collection',
  38. # query: {
  39. # startkey: [':site', ':slug', 'doc', {}],
  40. # endkey: [':site', ':slug', 'doc'],
  41. # descending: 'true',
  42. # include_docs: 'true'
  43. # }
  44. # }
  45. # Collection JSON view - all related rows
  46. {
  47. from: '/render/:site/json/collection/:slug',
  48. to: '_view/docs_by_collection',
  49. query: {
  50. startkey: [':site', ':slug', {}],
  51. endkey: [':site', ':slug'],
  52. descending: 'true',
  53. include_docs: 'true'
  54. }
  55. }
  56. # Collection's Sponsor JSON view - sponsor ONLY
  57. # {
  58. # from: '/render/:site/json/collection-sponsor/:slug',
  59. # to: '_view/docs_by_collection',
  60. # query: {
  61. # key: [':site', ':slug', 'sponsor', {}],
  62. # include_docs: 'true'
  63. # }
  64. # }
  65. # Search JSON endpoint
  66. {
  67. from: '/render/:site/json/search',
  68. to: '_search/site_docs'
  69. }
  70. # Essay content page
  71. {
  72. from: '/render/:site/essay/:slug',
  73. to: '_list/doc/docs_by_slug',
  74. query: {
  75. startkey: [':site', 'essay', ':slug'],
  76. endkey: [':site', 'essay', ':slug', {}],
  77. include_docs: 'true'
  78. }
  79. }
  80. # Scene content page
  81. {
  82. from: '/render/:site/scene/:slug',
  83. to: '_list/doc/docs_by_slug',
  84. query: {
  85. startkey: [':site', 'scene', ':slug'],
  86. endkey: [':site', 'scene', ':slug', {}],
  87. include_docs: 'true'
  88. }
  89. }
  90. # Video content page
  91. {
  92. from: '/render/:site/video/:slug',
  93. to: '_list/doc/docs_by_slug',
  94. query: {
  95. startkey: [':site', 'video', ':slug'],
  96. endkey: [':site', 'video', ':slug', {}],
  97. include_docs: 'true'
  98. }
  99. }
  100. # Profile content page
  101. {
  102. from: '/render/:site/profile/:slug',
  103. to: '_list/doc/docs_by_slug',
  104. query: {
  105. startkey: [':site', 'profile', ':slug'],
  106. endkey: [':site', 'profile', ':slug', {}],
  107. include_docs: 'true'
  108. }
  109. }
  110. # All docs list for site sorted by `updated_at`
  111. {
  112. from: '/render/:site/docs',
  113. to: '_list/docs/docs_by_date',
  114. query: {
  115. startkey: [':site', {}],
  116. endkey: [':site'],
  117. descending: 'true',
  118. include_docs: 'true'
  119. }
  120. }
  121. # RSS Feed of all docs sorted by `published_at`
  122. {
  123. from: '/render/:site/feed',
  124. to: '_list/rssfeed/docs_for_feeds',
  125. query: {
  126. startkey: [':site', {}],
  127. endkey: [':site'],
  128. descending: 'true',
  129. include_docs: 'true',
  130. limit: '11'
  131. }
  132. }
  133. # Sitemap.xml file of all docs sorted by `updated_at`
  134. {
  135. from: '/render/:site/sitemap.xml',
  136. to: '_list/sitemap/docs_for_sitemaps',
  137. query: {
  138. startkey: [':site', {}, {}],
  139. endkey: [':site', null],
  140. descending: 'true'
  141. }
  142. }
  143. # File attachments paths
  144. { from: '/file/:id/:filename', to: '../../:id/:filename' }
  145. { from: '/render/:site/file/:id/:filename', to: '../../:id/:filename' }
  146. # Redirected old URLs using a pattern
  147. movedPattern '/render/:site/posts/:id/:slug', '/:type/:slug'
  148. # Redirect some direct paths
  149. # moved '/render/:site/some-old-path', '/some-new-path'
  150. # `redirect` type - from a slug to a URL
  151. # doc id must be like `r/www.example.com/some-path`
  152. {
  153. from: '/render/:site/*',
  154. to: '_show/redirect/r/:site/*'
  155. }
  156. # 404 not found
  157. { from: '/not-found', to: '_show/not_found' }
  158. # Catch all route
  159. { from: '*', to: '_show/not_found' }
  160. ]