mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
Rename /category/xyz
paths to /c/xyz
-- @SamSaffron did most of the
work even though I'm merging the patch!
This commit is contained in:
parent
8bb20f2260
commit
d2ac5a9ac6
@ -9,7 +9,7 @@ export default Em.Component.extend({
|
|||||||
buffer.push("<i class='fa fa-group'></i> ");
|
buffer.push("<i class='fa fa-group'></i> ");
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.push("<a href='" + Discourse.getURL('/category/') + Discourse.Category.slugFor(category) + "'>");
|
buffer.push("<a href='" + Discourse.getURL('/c/') + Discourse.Category.slugFor(category) + "'>");
|
||||||
|
|
||||||
var noLogo = Em.isEmpty(logoUrl);
|
var noLogo = Em.isEmpty(logoUrl);
|
||||||
buffer.push(Handlebars.Utils.escapeExpression(category.get('name')));
|
buffer.push(Handlebars.Utils.escapeExpression(category.get('name')));
|
||||||
|
@ -13,7 +13,7 @@ export default ObjectController.extend({
|
|||||||
showMoreUrl: function(period) {
|
showMoreUrl: function(period) {
|
||||||
var url = '', category = this.get('category');
|
var url = '', category = this.get('category');
|
||||||
if (category) {
|
if (category) {
|
||||||
url = '/category/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l';
|
url = '/c/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l';
|
||||||
}
|
}
|
||||||
url += '/top/' + period;
|
url += '/top/' + period;
|
||||||
return url;
|
return url;
|
||||||
|
@ -151,7 +151,7 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||||||
this.get('model').save().then(function(result) {
|
this.get('model').save().then(function(result) {
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
model.setProperties({slug: result.category.slug, id: result.category.id });
|
model.setProperties({slug: result.category.slug, id: result.category.id });
|
||||||
Discourse.URL.redirectTo("/category/" + Discourse.Category.slugFor(model));
|
Discourse.URL.redirectTo("/c/" + Discourse.Category.slugFor(model));
|
||||||
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
if (error && error.responseText) {
|
if (error && error.responseText) {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
export default {
|
||||||
|
name: 'url-redirects',
|
||||||
|
initialize: function() {
|
||||||
|
|
||||||
|
// URL rewrites (usually due to refactoring)
|
||||||
|
Discourse.URL.rewrite(/^\/category\//, "/c/");
|
||||||
|
Discourse.URL.rewrite(/^\/group\//, "/groups/");
|
||||||
|
}
|
||||||
|
};
|
@ -86,7 +86,7 @@ Discourse.HTML = {
|
|||||||
var name = Em.get(category, 'name'),
|
var name = Em.get(category, 'name'),
|
||||||
description = Em.get(category, 'description'),
|
description = Em.get(category, 'description'),
|
||||||
restricted = Em.get(category, 'read_restricted'),
|
restricted = Em.get(category, 'read_restricted'),
|
||||||
url = Discourse.getURL("/category/") + Discourse.Category.slugFor(category),
|
url = Discourse.getURL("/c/") + Discourse.Category.slugFor(category),
|
||||||
elem = (opts.link === false ? 'span' : 'a'),
|
elem = (opts.link === false ? 'span' : 'a'),
|
||||||
extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''),
|
extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''),
|
||||||
html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" ",
|
html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" ",
|
||||||
|
@ -1,13 +1,6 @@
|
|||||||
/*global LockOn:true*/
|
/*global LockOn:true*/
|
||||||
/**
|
var jumpScheduled = false,
|
||||||
URL related functions.
|
rewrites = [];
|
||||||
|
|
||||||
@class URL
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
|
|
||||||
var jumpScheduled = false;
|
|
||||||
|
|
||||||
Discourse.URL = Em.Object.createWithMixins({
|
Discourse.URL = Em.Object.createWithMixins({
|
||||||
|
|
||||||
@ -102,7 +95,7 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
|
|
||||||
if (Em.isEmpty(path)) { return; }
|
if (Em.isEmpty(path)) { return; }
|
||||||
|
|
||||||
if(Discourse.get("requiresRefresh")){
|
if (Discourse.get('requiresRefresh')) {
|
||||||
document.location.href = path;
|
document.location.href = path;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -140,10 +133,9 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite /groups paths
|
rewrites.forEach(function(rw) {
|
||||||
if (path.indexOf('/group/') === 0) {
|
path = path.replace(rw.regexp, rw.replacement);
|
||||||
path = path.replace('group/', 'groups/');
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (this.navigatedToPost(oldPath, path)) { return; }
|
if (this.navigatedToPost(oldPath, path)) { return; }
|
||||||
// Schedule a DOM cleanup event
|
// Schedule a DOM cleanup event
|
||||||
@ -161,12 +153,10 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
return this.handleURL(path);
|
return this.handleURL(path);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
rewrite: function(regexp, replacement) {
|
||||||
Redirect to a URL.
|
rewrites.push({ regexp: regexp, replacement: replacement });
|
||||||
This has been extracted so it can be tested.
|
},
|
||||||
|
|
||||||
@method redirectTo
|
|
||||||
**/
|
|
||||||
redirectTo: function(url) {
|
redirectTo: function(url) {
|
||||||
window.location = Discourse.getURL(url);
|
window.location = Discourse.getURL(url);
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
}.property('id'),
|
}.property('id'),
|
||||||
|
|
||||||
url: function() {
|
url: function() {
|
||||||
return Discourse.getURL("/category/") + Discourse.Category.slugFor(this);
|
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
|
||||||
}.property('name'),
|
}.property('name'),
|
||||||
|
|
||||||
nameLower: function() {
|
nameLower: function() {
|
||||||
@ -280,7 +280,7 @@ Discourse.Category.reopenClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
reloadById: function(id) {
|
reloadById: function(id) {
|
||||||
return Discourse.ajax("/category/" + id + "/show.json").then(function (result) {
|
return Discourse.ajax("/c/" + id + "/show.json").then(function (result) {
|
||||||
return Discourse.Category.create(result.category);
|
return Discourse.Category.create(result.category);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,13 @@ Discourse.NavItem = Discourse.Model.extend({
|
|||||||
var name = this.get('name');
|
var name = this.get('name');
|
||||||
|
|
||||||
if( name.split('/')[0] === 'category' ) {
|
if( name.split('/')[0] === 'category' ) {
|
||||||
return 'category/' + this.get('categorySlug');
|
return 'c/' + this.get('categorySlug');
|
||||||
} else {
|
} else {
|
||||||
var mode = "",
|
var mode = "",
|
||||||
category = this.get("category");
|
category = this.get("category");
|
||||||
|
|
||||||
if(category){
|
if(category){
|
||||||
mode += "category/";
|
mode += "c/";
|
||||||
mode += Discourse.Category.slugFor(this.get('category'));
|
mode += Discourse.Category.slugFor(this.get('category'));
|
||||||
if (this.get('noSubcategories')) { mode += '/none'; }
|
if (this.get('noSubcategories')) { mode += '/none'; }
|
||||||
mode += "/l/";
|
mode += "/l/";
|
||||||
|
@ -21,36 +21,36 @@ Discourse.Route.buildRoutes(function() {
|
|||||||
|
|
||||||
this.resource('discovery', { path: '/' }, function() {
|
this.resource('discovery', { path: '/' }, function() {
|
||||||
router = this;
|
router = this;
|
||||||
|
|
||||||
// top
|
// top
|
||||||
this.route('top');
|
this.route('top');
|
||||||
this.route('topCategory', { path: '/category/:slug/l/top' });
|
this.route('topCategory', { path: '/c/:slug/l/top' });
|
||||||
this.route('topCategoryNone', { path: '/category/:slug/none/l/top' });
|
this.route('topCategoryNone', { path: '/c/:slug/none/l/top' });
|
||||||
this.route('topCategory', { path: '/category/:parentSlug/:slug/l/top' });
|
this.route('topCategory', { path: '/c/:parentSlug/:slug/l/top' });
|
||||||
|
|
||||||
// top by periods
|
// top by periods
|
||||||
Discourse.Site.currentProp('periods').forEach(function(period) {
|
Discourse.Site.currentProp('periods').forEach(function(period) {
|
||||||
var top = 'top' + period.capitalize();
|
var top = 'top' + period.capitalize();
|
||||||
router.route(top, { path: '/top/' + period });
|
router.route(top, { path: '/top/' + period });
|
||||||
router.route(top + 'Category', { path: '/category/:slug/l/top/' + period });
|
router.route(top + 'Category', { path: '/c/:slug/l/top/' + period });
|
||||||
router.route(top + 'CategoryNone', { path: '/category/:slug/none/l/top/' + period });
|
router.route(top + 'CategoryNone', { path: '/c/:slug/none/l/top/' + period });
|
||||||
router.route(top + 'Category', { path: '/category/:parentSlug/:slug/l/top/' + period });
|
router.route(top + 'Category', { path: '/c/:parentSlug/:slug/l/top/' + period });
|
||||||
});
|
});
|
||||||
|
|
||||||
// filters
|
// filters
|
||||||
Discourse.Site.currentProp('filters').forEach(function(filter) {
|
Discourse.Site.currentProp('filters').forEach(function(filter) {
|
||||||
router.route(filter, { path: '/' + filter });
|
router.route(filter, { path: '/' + filter });
|
||||||
router.route(filter + 'Category', { path: '/category/:slug/l/' + filter });
|
router.route(filter + 'Category', { path: '/c/:slug/l/' + filter });
|
||||||
router.route(filter + 'CategoryNone', { path: '/category/:slug/none/l/' + filter });
|
router.route(filter + 'CategoryNone', { path: '/c/:slug/none/l/' + filter });
|
||||||
router.route(filter + 'Category', { path: '/category/:parentSlug/:slug/l/' + filter });
|
router.route(filter + 'Category', { path: '/c/:parentSlug/:slug/l/' + filter });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.route('categories');
|
this.route('categories');
|
||||||
|
|
||||||
// default filter for a category
|
// default filter for a category
|
||||||
this.route('parentCategory', { path: '/category/:slug' });
|
this.route('parentCategory', { path: '/c/:slug' });
|
||||||
this.route('categoryNone', { path: '/category/:slug/none' });
|
this.route('categoryNone', { path: '/c/:slug/none' });
|
||||||
this.route('category', { path: '/category/:parentSlug/:slug' });
|
this.route('category', { path: '/c/:parentSlug/:slug' });
|
||||||
|
|
||||||
|
|
||||||
// homepage
|
// homepage
|
||||||
this.route(Discourse.Utilities.defaultHomepage(), { path: '/' });
|
this.route(Discourse.Utilities.defaultHomepage(), { path: '/' });
|
||||||
|
@ -22,7 +22,7 @@ export default function(filter, params) {
|
|||||||
|
|
||||||
_setupNavigation: function(model) {
|
_setupNavigation: function(model) {
|
||||||
var noSubcategories = params && !!params.no_subcategories,
|
var noSubcategories = params && !!params.no_subcategories,
|
||||||
filterMode = "category/" + Discourse.Category.slugFor(model) + (noSubcategories ? "/none" : "") + "/l/" + filter;
|
filterMode = "c/" + Discourse.Category.slugFor(model) + (noSubcategories ? "/none" : "") + "/l/" + filter;
|
||||||
|
|
||||||
this.controllerFor('navigation/category').setProperties({
|
this.controllerFor('navigation/category').setProperties({
|
||||||
category: model,
|
category: model,
|
||||||
@ -47,7 +47,7 @@ export default function(filter, params) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_retrieveTopicList: function(model, transition) {
|
_retrieveTopicList: function(model, transition) {
|
||||||
var listFilter = "category/" + Discourse.Category.slugFor(model) + "/l/" + filter,
|
var listFilter = "c/" + Discourse.Category.slugFor(model) + "/l/" + filter,
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
var findOpts = filterQueryParams(transition.queryParams, params),
|
var findOpts = filterQueryParams(transition.queryParams, params),
|
||||||
|
@ -2,9 +2,13 @@ require_dependency 'category_serializer'
|
|||||||
|
|
||||||
class CategoriesController < ApplicationController
|
class CategoriesController < ApplicationController
|
||||||
|
|
||||||
before_filter :ensure_logged_in, except: [:index, :show]
|
before_filter :ensure_logged_in, except: [:index, :show, :redirect]
|
||||||
before_filter :fetch_category, only: [:show, :update, :destroy]
|
before_filter :fetch_category, only: [:show, :update, :destroy]
|
||||||
skip_before_filter :check_xhr, only: [:index]
|
skip_before_filter :check_xhr, only: [:index, :redirect]
|
||||||
|
|
||||||
|
def redirect
|
||||||
|
redirect_to "/c/#{params[:path]}"
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@description = SiteSetting.site_description
|
@description = SiteSetting.site_description
|
||||||
|
@ -319,39 +319,42 @@ Discourse::Application.routes.draw do
|
|||||||
get "popular" => "list#popular_redirect"
|
get "popular" => "list#popular_redirect"
|
||||||
|
|
||||||
resources :categories, :except => :show
|
resources :categories, :except => :show
|
||||||
get "category/:id/show" => "categories#show"
|
|
||||||
post "category/uploads" => "categories#upload"
|
post "category/uploads" => "categories#upload"
|
||||||
post "category/:category_id/move" => "categories#move"
|
post "category/:category_id/move" => "categories#move"
|
||||||
get "category/:category.rss" => "list#category_feed", format: :rss
|
|
||||||
get "category/:parent_category/:category.rss" => "list#category_feed", format: :rss
|
|
||||||
get "category/:category" => "list#category_latest"
|
|
||||||
get "category/:category/none" => "list#category_none_latest"
|
|
||||||
get "category/:parent_category/:category" => "list#parent_category_category_latest"
|
|
||||||
post "category/:category_id/notifications" => "categories#set_notifications"
|
post "category/:category_id/notifications" => "categories#set_notifications"
|
||||||
|
|
||||||
get "top" => "list#top"
|
get "c/:id/show" => "categories#show"
|
||||||
get "category/:category/l/top" => "list#category_top", as: "category_top"
|
get "c/:category.rss" => "list#category_feed", format: :rss
|
||||||
get "category/:category/none/l/top" => "list#category_none_top", as: "category_none_top"
|
get "c/:parent_category/:category.rss" => "list#category_feed", format: :rss
|
||||||
get "category/:parent_category/:category/l/top" => "list#parent_category_category_top", as: "parent_category_category_top"
|
get "c/:category" => "list#category_latest"
|
||||||
|
get "c/:category/none" => "list#category_none_latest"
|
||||||
|
get "c/:parent_category/:category" => "list#parent_category_category_latest"
|
||||||
|
get "c/:category/l/top" => "list#category_top", as: "category_top"
|
||||||
|
get "c/:category/none/l/top" => "list#category_none_top", as: "category_none_top"
|
||||||
|
get "c/:parent_category/:category/l/top" => "list#parent_category_category_top", as: "parent_category_category_top"
|
||||||
|
|
||||||
|
|
||||||
TopTopic.periods.each do |period|
|
TopTopic.periods.each do |period|
|
||||||
get "top/#{period}" => "list#top_#{period}"
|
get "top/#{period}" => "list#top_#{period}"
|
||||||
get "category/:category/l/top/#{period}" => "list#category_top_#{period}", as: "category_top_#{period}"
|
get "c/:category/l/top/#{period}" => "list#category_top_#{period}", as: "category_top_#{period}"
|
||||||
get "category/:category/none/l/top/#{period}" => "list#category_none_top_#{period}", as: "category_none_top_#{period}"
|
get "c/:category/none/l/top/#{period}" => "list#category_none_top_#{period}", as: "category_none_top_#{period}"
|
||||||
get "category/:parent_category/:category/l/top/#{period}" => "list#parent_category_category_top_#{period}", as: "parent_category_category_top_#{period}"
|
get "c/:parent_category/:category/l/top/#{period}" => "list#parent_category_category_top_#{period}", as: "parent_category_category_top_#{period}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Discourse.filters.each do |filter|
|
||||||
|
get "#{filter}" => "list##{filter}"
|
||||||
|
get "c/:category/l/#{filter}" => "list#category_#{filter}", as: "category_#{filter}"
|
||||||
|
get "c/:category/none/l/#{filter}" => "list#category_none_#{filter}", as: "category_none_#{filter}"
|
||||||
|
get "c/:parent_category/:category/l/#{filter}" => "list#parent_category_category_#{filter}", as: "parent_category_category_#{filter}"
|
||||||
|
end
|
||||||
|
|
||||||
|
get "category/*path" => "categories#redirect"
|
||||||
|
|
||||||
Discourse.anonymous_filters.each do |filter|
|
Discourse.anonymous_filters.each do |filter|
|
||||||
get "#{filter}.rss" => "list##{filter}_feed", format: :rss
|
get "#{filter}.rss" => "list##{filter}_feed", format: :rss
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse.filters.each do |filter|
|
get "top" => "list#top"
|
||||||
get "#{filter}" => "list##{filter}"
|
|
||||||
get "category/:category/l/#{filter}" => "list#category_#{filter}", as: "category_#{filter}"
|
|
||||||
get "category/:category/none/l/#{filter}" => "list#category_none_#{filter}", as: "category_none_#{filter}"
|
|
||||||
get "category/:parent_category/:category/l/#{filter}" => "list#parent_category_category_#{filter}", as: "parent_category_category_#{filter}"
|
|
||||||
end
|
|
||||||
|
|
||||||
get "search" => "search#query"
|
get "search" => "search#query"
|
||||||
|
|
||||||
# Topics resource
|
# Topics resource
|
||||||
|
File diff suppressed because one or more lines are too long
@ -7,7 +7,7 @@ test("Visit Discovery Pages", function() {
|
|||||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||||
});
|
});
|
||||||
|
|
||||||
visit("/category/bug");
|
visit("/c/bug");
|
||||||
andThen(function() {
|
andThen(function() {
|
||||||
ok(exists(".topic-list"), "The list of topics was rendered");
|
ok(exists(".topic-list"), "The list of topics was rendered");
|
||||||
ok(exists('.topic-list .topic-list-item'), "has topics");
|
ok(exists('.topic-list .topic-list-item'), "has topics");
|
||||||
|
@ -23,6 +23,6 @@ test('href', function(){
|
|||||||
|
|
||||||
href('latest', '/latest', 'latest');
|
href('latest', '/latest', 'latest');
|
||||||
href('categories', '/categories', 'categories');
|
href('categories', '/categories', 'categories');
|
||||||
href('category/bug', '/category/bug', 'English category name');
|
href('category/bug', '/c/bug', 'English category name');
|
||||||
href('category/确实是这样', '/category/343434-category', 'Chinese category name');
|
href('category/确实是这样', '/c/343434-category', 'Chinese category name');
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user