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:
Robin Ward 2014-10-16 12:15:31 -04:00
parent 8bb20f2260
commit d2ac5a9ac6
15 changed files with 74 additions and 68 deletions

View file

@ -9,7 +9,7 @@ export default Em.Component.extend({
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);
buffer.push(Handlebars.Utils.escapeExpression(category.get('name')));

View file

@ -13,7 +13,7 @@ export default ObjectController.extend({
showMoreUrl: function(period) {
var url = '', category = this.get('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;
return url;

View file

@ -151,7 +151,7 @@ export default ObjectController.extend(ModalFunctionality, {
this.get('model').save().then(function(result) {
self.send('closeModal');
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) {
if (error && error.responseText) {

View file

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

View file

@ -86,7 +86,7 @@ Discourse.HTML = {
var name = Em.get(category, 'name'),
description = Em.get(category, 'description'),
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'),
extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''),
html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" ",

View file

@ -1,13 +1,6 @@
/*global LockOn:true*/
/**
URL related functions.
@class URL
@namespace Discourse
@module Discourse
**/
var jumpScheduled = false;
var jumpScheduled = false,
rewrites = [];
Discourse.URL = Em.Object.createWithMixins({
@ -102,7 +95,7 @@ Discourse.URL = Em.Object.createWithMixins({
if (Em.isEmpty(path)) { return; }
if(Discourse.get("requiresRefresh")){
if (Discourse.get('requiresRefresh')) {
document.location.href = path;
return;
}
@ -140,10 +133,9 @@ Discourse.URL = Em.Object.createWithMixins({
}
}
// Rewrite /groups paths
if (path.indexOf('/group/') === 0) {
path = path.replace('group/', 'groups/');
}
rewrites.forEach(function(rw) {
path = path.replace(rw.regexp, rw.replacement);
});
if (this.navigatedToPost(oldPath, path)) { return; }
// Schedule a DOM cleanup event
@ -161,12 +153,10 @@ Discourse.URL = Em.Object.createWithMixins({
return this.handleURL(path);
},
/**
Redirect to a URL.
This has been extracted so it can be tested.
rewrite: function(regexp, replacement) {
rewrites.push({ regexp: regexp, replacement: replacement });
},
@method redirectTo
**/
redirectTo: function(url) {
window.location = Discourse.getURL(url);
},

View file

@ -26,7 +26,7 @@ Discourse.Category = Discourse.Model.extend({
}.property('id'),
url: function() {
return Discourse.getURL("/category/") + Discourse.Category.slugFor(this);
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
}.property('name'),
nameLower: function() {
@ -280,7 +280,7 @@ Discourse.Category.reopenClass({
},
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);
});
}

View file

@ -37,13 +37,13 @@ Discourse.NavItem = Discourse.Model.extend({
var name = this.get('name');
if( name.split('/')[0] === 'category' ) {
return 'category/' + this.get('categorySlug');
return 'c/' + this.get('categorySlug');
} else {
var mode = "",
category = this.get("category");
if(category){
mode += "category/";
mode += "c/";
mode += Discourse.Category.slugFor(this.get('category'));
if (this.get('noSubcategories')) { mode += '/none'; }
mode += "/l/";

View file

@ -21,36 +21,36 @@ Discourse.Route.buildRoutes(function() {
this.resource('discovery', { path: '/' }, function() {
router = this;
// top
this.route('top');
this.route('topCategory', { path: '/category/:slug/l/top' });
this.route('topCategoryNone', { path: '/category/:slug/none/l/top' });
this.route('topCategory', { path: '/category/:parentSlug/:slug/l/top' });
this.route('topCategory', { path: '/c/:slug/l/top' });
this.route('topCategoryNone', { path: '/c/:slug/none/l/top' });
this.route('topCategory', { path: '/c/:parentSlug/:slug/l/top' });
// top by periods
Discourse.Site.currentProp('periods').forEach(function(period) {
var top = 'top' + period.capitalize();
router.route(top, { path: '/top/' + period });
router.route(top + 'Category', { path: '/category/:slug/l/top/' + period });
router.route(top + 'CategoryNone', { path: '/category/:slug/none/l/top/' + period });
router.route(top + 'Category', { path: '/category/:parentSlug/:slug/l/top/' + period });
router.route(top + 'Category', { path: '/c/:slug/l/top/' + period });
router.route(top + 'CategoryNone', { path: '/c/:slug/none/l/top/' + period });
router.route(top + 'Category', { path: '/c/:parentSlug/:slug/l/top/' + period });
});
// filters
Discourse.Site.currentProp('filters').forEach(function(filter) {
router.route(filter, { path: '/' + filter });
router.route(filter + 'Category', { path: '/category/:slug/l/' + filter });
router.route(filter + 'CategoryNone', { path: '/category/:slug/none/l/' + filter });
router.route(filter + 'Category', { path: '/category/:parentSlug/:slug/l/' + filter });
router.route(filter + 'Category', { path: '/c/:slug/l/' + filter });
router.route(filter + 'CategoryNone', { path: '/c/:slug/none/l/' + filter });
router.route(filter + 'Category', { path: '/c/:parentSlug/:slug/l/' + filter });
});
this.route('categories');
// default filter for a category
this.route('parentCategory', { path: '/category/:slug' });
this.route('categoryNone', { path: '/category/:slug/none' });
this.route('category', { path: '/category/:parentSlug/:slug' });
this.route('parentCategory', { path: '/c/:slug' });
this.route('categoryNone', { path: '/c/:slug/none' });
this.route('category', { path: '/c/:parentSlug/:slug' });
// homepage
this.route(Discourse.Utilities.defaultHomepage(), { path: '/' });

View file

@ -22,7 +22,7 @@ export default function(filter, params) {
_setupNavigation: function(model) {
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({
category: model,
@ -47,7 +47,7 @@ export default function(filter, params) {
},
_retrieveTopicList: function(model, transition) {
var listFilter = "category/" + Discourse.Category.slugFor(model) + "/l/" + filter,
var listFilter = "c/" + Discourse.Category.slugFor(model) + "/l/" + filter,
self = this;
var findOpts = filterQueryParams(transition.queryParams, params),

View file

@ -2,9 +2,13 @@ require_dependency 'category_serializer'
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]
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
@description = SiteSetting.site_description

View file

@ -319,39 +319,42 @@ Discourse::Application.routes.draw do
get "popular" => "list#popular_redirect"
resources :categories, :except => :show
get "category/:id/show" => "categories#show"
post "category/uploads" => "categories#upload"
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"
get "top" => "list#top"
get "category/:category/l/top" => "list#category_top", as: "category_top"
get "category/:category/none/l/top" => "list#category_none_top", as: "category_none_top"
get "category/:parent_category/:category/l/top" => "list#parent_category_category_top", as: "parent_category_category_top"
get "c/:id/show" => "categories#show"
get "c/:category.rss" => "list#category_feed", format: :rss
get "c/:parent_category/:category.rss" => "list#category_feed", format: :rss
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|
get "top/#{period}" => "list#top_#{period}"
get "category/: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 "category/:parent_category/:category/l/top/#{period}" => "list#parent_category_category_top_#{period}", as: "parent_category_category_top_#{period}"
get "c/:category/l/top/#{period}" => "list#category_top_#{period}", as: "category_top_#{period}"
get "c/:category/none/l/top/#{period}" => "list#category_none_top_#{period}", as: "category_none_top_#{period}"
get "c/:parent_category/:category/l/top/#{period}" => "list#parent_category_category_top_#{period}", as: "parent_category_category_top_#{period}"
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|
get "#{filter}.rss" => "list##{filter}_feed", format: :rss
end
Discourse.filters.each do |filter|
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 "top" => "list#top"
get "search" => "search#query"
# Topics resource

File diff suppressed because one or more lines are too long

View file

@ -7,7 +7,7 @@ test("Visit Discovery Pages", function() {
ok(exists('.topic-list .topic-list-item'), "has topics");
});
visit("/category/bug");
visit("/c/bug");
andThen(function() {
ok(exists(".topic-list"), "The list of topics was rendered");
ok(exists('.topic-list .topic-list-item'), "has topics");

View file

@ -23,6 +23,6 @@ test('href', function(){
href('latest', '/latest', 'latest');
href('categories', '/categories', 'categories');
href('category/bug', '/category/bug', 'English category name');
href('category/确实是这样', '/category/343434-category', 'Chinese category name');
href('category/bug', '/c/bug', 'English category name');
href('category/确实是这样', '/c/343434-category', 'Chinese category name');
});