DEV: Add unambiguous routes for tags

The trouble with having:

/tags/:tag_id/...

and:

/tags/intersection/*tag_ids

for example, is: what happens if you want a tag called intersection?

Under this new scheme. Routes referring to a single tag are unambiguous
because they are prefixed with:

/tag/:tag_id

Routes referring to the collection of tags still start with:

/tags/

This commit just adds the new routes. It doesn't remove the old ones or
cause the new ones to be used.
This commit is contained in:
Daniel Waterworth 2019-12-13 11:05:23 +00:00
parent dc3c4bdd00
commit 1fb7a6297c
3 changed files with 50 additions and 5 deletions

View File

@ -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 });

View File

@ -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(

View File

@ -840,6 +840,27 @@ Discourse::Application.routes.draw do
get "apple-app-site-association" => "metadata#app_association_ios", format: false
get "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" do
get '/' => 'tags#index'
get '/filter/list' => 'tags#index'
@ -849,6 +870,7 @@ Discourse::Application.routes.draw do
post '/upload' => 'tags#upload'
get '/unused' => 'tags#list_unused'
delete '/unused' => 'tags#destroy_unused'
constraints(tag_id: /[^\/]+?/, format: /json|rss/) do
scope path: '/c/*category_slug_path_with_id' do
Discourse.filters.each do |filter|
@ -864,9 +886,13 @@ Discourse::Application.routes.draw do
get '/: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/) do
get '/: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'