A platform for community discussion. Free, open, simple.
DEV: Add unambiguous routes for tags
Daniel Waterworth1fb7a6297c7b
diff --git a/app/assets/javascripts/discourse/pre-initializers/dynamic-route-builders.js.es6 b/app/assets/javascripts/discourse/pre-initializers/dynamic-route-builders.js.es6index 26ac79cd02b..9c96d01e429 100644--- a/app/assets/javascripts/discourse/pre-initializers/dynamic-route-builders.js.es6+++ b/app/assets/javascripts/discourse/pre-initializers/dynamic-route-builders.js.es6@@ -103,10 +103,15 @@ export default {});app["TagsShowParentCategoryRoute"] = TagsShowRoute.extend();+ app["TagShowRoute"] = TagsShowRoute;+site.get("filters").forEach(function(filter) {app["TagsShow" + filter.capitalize() + "Route"] = TagsShowRoute.extend({navMode: filter});+ app["TagShow" + filter.capitalize() + "Route"] = TagsShowRoute.extend({+ navMode: filter+ });app["TagsShowCategory" + filter.capitalize() + "Route"] = TagsShowRoute.extend({ navMode: filter });diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6index 3dc0d5787ab..42d8f57f5c7 100644--- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6+++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6@@ -209,8 +209,17 @@ export default function() {this.route("full-page-search", { path: "/search" });- this.route("tags", { resetNamespace: true }, function() {+ this.route("tag", { resetNamespace: true }, function() {this.route("show", { path: "/:tag_id" });++ Site.currentProp("filters").forEach(filter => {+ this.route("show" + filter.capitalize(), {+ path: "/:tag_id/l/" + filter+ });+ });+ });++ this.route("tags", { resetNamespace: true }, function() {this.route("showCategory", {path: "/c/*category_slug_path_with_id/:tag_id"});@@ -219,9 +228,6 @@ export default function() {});Site.currentProp("filters").forEach(filter => {- this.route("show" + filter.capitalize(), {- path: "/:tag_id/l/" + filter- });this.route("showCategory" + filter.capitalize(), {path: "/c/*category_slug_path_with_id/:tag_id/l/" + filter});@@ -232,6 +238,14 @@ export default function() {this.route("intersection", {path: "intersection/:tag_id/*additional_tags"});++ // legacy routes+ this.route("show", { path: "/:tag_id" });+ Site.currentProp("filters").forEach(filter => {+ this.route("show" + filter.capitalize(), {+ path: "/:tag_id/l/" + filter+ });+ });});this.route(diff --git a/config/routes.rb b/config/routes.rbindex 60a82ae4760..21e536ce9c6 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -840,6 +840,27 @@ Discourse::Application.routes.draw doget "apple-app-site-association" => "metadata#app_association_ios", format: falseget "opensearch" => "metadata#opensearch", constraints: { format: :xml }+ scope '/tag/:tag_id' do+ constraints format: :json do+ get '/' => 'tags#show'+ get '/info' => 'tags#info'+ get '/notifications' => 'tags#notifications'+ put '/notifications' => 'tags#update_notifications'+ put '/' => 'tags#update'+ delete '/' => 'tags#destroy'+ post '/synonyms' => 'tags#create_synonyms'+ delete '/synonyms/:synonym_id' => 'tags#destroy_synonym'++ Discourse.filters.each do |filter|+ get "/l/#{filter}" => "tags#show_#{filter}"+ end+ end++ constraints format: :rss do+ get '/' => 'tags#tag_feed'+ end+ end+scope "/tags" doget '/' => 'tags#index'get '/filter/list' => 'tags#index'@@ -849,6 +870,7 @@ Discourse::Application.routes.draw dopost '/upload' => 'tags#upload'get '/unused' => 'tags#list_unused'delete '/unused' => 'tags#destroy_unused'+constraints(tag_id: /[^\/]+?/, format: /json|rss/) doscope path: '/c/*category_slug_path_with_id' doDiscourse.filters.each do |filter|@@ -864,9 +886,13 @@ Discourse::Application.routes.draw doget '/:tag_id' => 'tags#show', as: 'tag_category_show'end+ get '/intersection/:tag_id/*additional_tag_ids' => 'tags#show', as: 'tag_intersection'+ end++ # legacy routes+ constraints(tag_id: /[^\/]+?/, format: /json|rss/) doget '/:tag_id.rss' => 'tags#tag_feed'get '/:tag_id' => 'tags#show', as: 'tag_show'- get '/intersection/:tag_id/*additional_tag_ids' => 'tags#show', as: 'tag_intersection'get '/:tag_id/info' => 'tags#info'get '/:tag_id/notifications' => 'tags#notifications'put '/:tag_id/notifications' => 'tags#update_notifications'