Compare commits

...
This repository has been archived on 2023-07-01. You can view files and clone it, but cannot push or open issues or pull requests.

2 Commits

Author SHA1 Message Date
kibigo! f32ef29808 Removed unnecessary constraint 2017-12-11 00:14:00 -08:00
kibigo! a634d3876f Route flavours ~ URLs 2017-12-10 23:59:04 -08:00
10 changed files with 30 additions and 25 deletions

View File

@ -81,6 +81,7 @@ class ApplicationController < ActionController::Base
end
def pack?(data, pack_name)
return false unless data
if data['pack'].is_a?(Hash) && data['pack'].key?(pack_name)
return true if data['pack'][pack_name].is_a?(String) || data['pack'][pack_name].is_a?(Hash)
end
@ -89,16 +90,17 @@ class ApplicationController < ActionController::Base
def nil_pack(data, pack_name, skin = 'default')
{
common: pack_name == 'common' ? nil : resolve_pack(data['name'] ? Themes.instance.flavour(current_flavour) : Themes.instance.core, 'common', skin),
flavour: data['name'],
common: pack_name == 'common' ? nil : resolve_pack(!data || data['name'] ? Themes.instance.flavour(current_flavour) : Themes.instance.core, 'common', skin),
flavour: data ? data['name'] : nil,
pack: nil,
preload: nil,
skin: nil,
supported_locales: data['locales'],
supported_locales: data ? data['locales'] : nil,
}
end
def resolve_pack(data, pack_name, skin = 'default')
return nil_pack(data, pack_name, skin) unless data
result = pack(data, pack_name, skin)
unless result
if data['name'] && data.key?('fallback')
@ -154,13 +156,14 @@ class ApplicationController < ActionController::Base
end
def current_flavour
return Setting.default_settings['flavour'] unless Themes.instance.flavours.include? current_user&.setting_flavour
current_user.setting_flavour
return params[:use_flavour].to_s if Themes.instance.flavours.include? params[:use_flavour].to_s
return current_user.setting_flavour if Themes.instance.flavours.include? current_user&.setting_flavour
Setting.default_settings['flavour']
end
def current_skin
return 'default' unless Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin
current_user.setting_skin
return current_user.setting_skin if Themes.instance.skins_for(current_flavour).include? current_user&.setting_skin
'default'
end
def cache_collection(raw, klass)

View File

@ -7,6 +7,7 @@ class HomeController < ApplicationController
def index
@body_classes = 'app-body'
redirect_to "/$#{current_flavour}/#{params[:glob] || ''}" unless Themes.instance.flavours.include?(params[:use_flavour].to_s) or request.path.start_with?("/$#{current_flavour}")
end
private
@ -58,7 +59,7 @@ class HomeController < ApplicationController
end
def default_redirect_path
if request.path.start_with?('/web')
if request.path.start_with?('/web') || request.path.match?(/\A\$[\w-]+/)
new_user_session_path
elsif single_user_mode?
short_account_path(Account.first)

View File

@ -57,7 +57,7 @@ export default class Mastodon extends React.PureComponent {
return (
<IntlProvider locale={locale} messages={messages}>
<Provider store={store}>
<BrowserRouter basename='/web'>
<BrowserRouter basename='/$glitch'>
<ScrollContext>
<Route path='/' component={UI} />
</ScrollContext>

View File

@ -17,7 +17,7 @@ const notify = options =>
icon: '/android-chrome-192x192.png',
tag: GROUP_TAG,
data: {
url: (new URL('/web/notifications', self.location)).href,
url: (new URL('/$glitch/notifications', self.location)).href,
count: notifications.length + 1,
message: options.data.message,
},

View File

@ -12,8 +12,8 @@ function main() {
if (window.history && history.replaceState) {
const { pathname, search, hash } = window.location;
const path = pathname + search + hash;
if (!(/^\/web[$/]/).test(path)) {
history.replaceState(null, document.title, `/web${path}`);
if (!(/^\/\$glitch[$/]/).test(path)) {
history.replaceState(null, document.title, `/$glitch${path}`);
}
}

View File

@ -57,7 +57,7 @@ export default class Mastodon extends React.PureComponent {
return (
<IntlProvider locale={locale} messages={messages}>
<Provider store={store}>
<BrowserRouter basename='/web'>
<BrowserRouter basename='/$vanilla'>
<ScrollContext>
<Route path='/' component={UI} />
</ScrollContext>

View File

@ -12,8 +12,8 @@ function main() {
if (window.history && history.replaceState) {
const { pathname, search, hash } = window.location;
const path = pathname + search + hash;
if (!(/^\/web[$/]/).test(path)) {
history.replaceState(null, document.title, `/web${path}`);
if (!(/^\/\$vanilla[$/]/).test(path)) {
history.replaceState(null, document.title, `/$vanilla${path}`);
}
}

View File

@ -102,16 +102,16 @@ const findBestClient = clients => {
const openUrl = url =>
self.clients.matchAll({ type: 'window' }).then(clientList => {
if (clientList.length !== 0) {
const webClients = clientList.filter(client => /\/web\//.test(client.url));
const webClients = clientList.filter(client => /\/\$vanilla\//.test(client.url));
if (webClients.length !== 0) {
const client = findBestClient(webClients);
const { pathname } = new URL(url);
if (pathname.startsWith('/web/')) {
if (pathname.startsWith('/$vanilla/')) {
return client.focus().then(client => client.postMessage({
type: 'navigate',
path: pathname.slice('/web/'.length - 1),
path: pathname.slice('/$vanilla/'.length - 1),
}));
}
} else if ('navigate' in clientList[0]) { // Chrome 42-48 does not support navigate

View File

@ -1054,23 +1054,23 @@ body.admin {
}
}
.column-link[href="/web/timelines/public"] {
.column-link[href="/$vanilla/timelines/public"] {
background-image: url("~images/icon_public.png");
&:hover { background-image: url("~images/icon_public.png"); }
}
.column-link[href="/web/timelines/public/local"] {
.column-link[href="/$vanilla/timelines/public/local"] {
background-image: url("~images/icon_local.png");
&:hover { background-image: url("~images/icon_local.png"); }
}
.column-link[href="/web/pinned"] {
.column-link[href="/$vanilla/pinned"] {
background-image: url("~images/icon_pin.png");
&:hover { background-image: url("~images/icon_pin.png"); }
}
.column-link[href="/web/favourites"] {
.column-link[href="/$vanilla/favourites"] {
background-image: url("~images/icon_likes.png");
&:hover { background-image: url("~images/icon_likes.png"); }
}
.column-link[href="/web/blocks"] {
.column-link[href="/$vanilla/blocks"] {
background-image: url("~images/icon_blocks.png");
&:hover { background-image: url("~images/icon_blocks.png"); }
}

View File

@ -240,7 +240,7 @@ Rails.application.routes.draw do
resources :media, only: [:create, :update]
resources :blocks, only: [:index]
resources :mutes, only: [:index] do
collection do
collection do
get 'details'
end
end
@ -309,7 +309,8 @@ Rails.application.routes.draw do
end
end
get '/web/(*any)', to: 'home#index', as: :web
get '/web/(*glob)', to: 'home#index', as: :web
get "/$:use_flavour/(*glob)", to: 'home#index'
get '/about', to: 'about#show'
get '/about/more', to: 'about#more'