Themed prefetching
This commit is contained in:
parent
b28b405b97
commit
585758a373
|
@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
|
||||||
helper_method :current_account
|
helper_method :current_account
|
||||||
helper_method :current_session
|
helper_method :current_session
|
||||||
helper_method :current_theme
|
helper_method :current_theme
|
||||||
|
helper_method :theme_data
|
||||||
helper_method :single_user_mode?
|
helper_method :single_user_mode?
|
||||||
|
|
||||||
rescue_from ActionController::RoutingError, with: :not_found
|
rescue_from ActionController::RoutingError, with: :not_found
|
||||||
|
@ -88,6 +89,10 @@ class ApplicationController < ActionController::Base
|
||||||
current_user.setting_theme
|
current_user.setting_theme
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def theme_data
|
||||||
|
Themes.instance.get(current_theme)
|
||||||
|
end
|
||||||
|
|
||||||
def cache_collection(raw, klass)
|
def cache_collection(raw, klass)
|
||||||
return raw unless klass.respond_to?(:with_includes)
|
return raw unless klass.respond_to?(:with_includes)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ class HomeController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@body_classes = 'app-body'
|
@body_classes = 'app-body'
|
||||||
@frontend = (params[:frontend] and Rails.configuration.x.available_frontends.include? params[:frontend] + '.js') ? params[:frontend] : 'mastodon'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
# (REQUIRED) Name must be unique across all installed themes.
|
|
||||||
name: default
|
|
||||||
|
|
||||||
# (REQUIRED) The location of the pack file inside `pack_directory`.
|
# (REQUIRED) The location of the pack file inside `pack_directory`.
|
||||||
pack: application.js
|
pack: application.js
|
||||||
|
|
||||||
# (OPTIONAL) The directory which contains the pack file.
|
# (OPTIONAL) The directory which contains the pack file.
|
||||||
# Defaults to the theme directory (`app/javascript/themes/[theme]`).
|
# Defaults to the theme directory (`app/javascript/themes/[theme]`),
|
||||||
|
# but in the case of the vanilla Mastodon theme the pack file is
|
||||||
|
# somewhere else.
|
||||||
pack_directory: app/javascript/packs
|
pack_directory: app/javascript/packs
|
||||||
|
|
||||||
|
# (OPTIONAL) Additional javascript resources to preload, for use with
|
||||||
|
# lazy-loaded components. It is **STRONGLY RECOMMENDED** that you
|
||||||
|
# derive these pathnames from `themes/[your-theme]` to ensure that
|
||||||
|
# they stay unique. (Of course, vanilla doesn't do this ^^;;)
|
||||||
|
preload:
|
||||||
|
- features/getting_started
|
||||||
|
- features/compose
|
||||||
|
- features/home_timeline
|
||||||
|
- features/notifications
|
||||||
|
|
|
@ -10,13 +10,18 @@ class Themes
|
||||||
result = Hash.new
|
result = Hash.new
|
||||||
Dir.glob(Rails.root.join('app', 'javascript', 'themes', '*', 'theme.yml')) do |path|
|
Dir.glob(Rails.root.join('app', 'javascript', 'themes', '*', 'theme.yml')) do |path|
|
||||||
data = YAML.load_file(path)
|
data = YAML.load_file(path)
|
||||||
if data['pack'] && data['name']
|
name = File.basename(File.dirname(path))
|
||||||
result[data['name']] = data
|
if data['pack']
|
||||||
|
result[name] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@conf = result
|
@conf = result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get(name)
|
||||||
|
@conf[name]
|
||||||
|
end
|
||||||
|
|
||||||
def names
|
def names
|
||||||
@conf.keys
|
@conf.keys
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
- content_for :header_tags do
|
- content_for :header_tags do
|
||||||
%link{ href: asset_pack_path('features/getting_started.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
|
- if theme_data['preload']
|
||||||
%link{ href: asset_pack_path('features/compose.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
|
- theme_data['preload'].each do |link|
|
||||||
%link{ href: asset_pack_path('features/home_timeline.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
|
%link{ href: asset_pack_path("#{link}.js"), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
|
||||||
%link{ href: asset_pack_path('features/notifications.js'), crossorigin: 'anonymous', rel: 'preload', as: 'script' }/
|
|
||||||
%meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key}
|
%meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key}
|
||||||
%script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json)
|
%script#initial-state{ type: 'application/json' }!= json_escape(@initial_state_json)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Common configuration for webpacker loaded from config/webpacker.yml
|
// Common configuration for webpacker loaded from config/webpacker.yml
|
||||||
|
|
||||||
const { dirname, join, resolve } = require('path');
|
const { basename, dirname, join, resolve } = require('path');
|
||||||
const { env } = require('process');
|
const { env } = require('process');
|
||||||
const { safeLoad } = require('js-yaml');
|
const { safeLoad } = require('js-yaml');
|
||||||
const { readFileSync } = require('fs');
|
const { readFileSync } = require('fs');
|
||||||
|
@ -18,8 +18,8 @@ for (let i = 0; i < themeFiles.length; i++) {
|
||||||
if (!data.pack_directory) {
|
if (!data.pack_directory) {
|
||||||
data.pack_directory = dirname(themeFile);
|
data.pack_directory = dirname(themeFile);
|
||||||
}
|
}
|
||||||
if (data.name && data.pack) {
|
if (data.pack) {
|
||||||
themes[data.name] = data;
|
themes[basename(dirname(themeFile))] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue