mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: Allow selection of highlight js languages
PERF: stop loading highlight js on load To get latest highlight js run bin/rake highlightjs:update
This commit is contained in:
26
app/controllers/highlight_js_controller.rb
Normal file
26
app/controllers/highlight_js_controller.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class HighlightJsController < ApplicationController
|
||||
skip_before_filter :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
|
||||
|
||||
def show
|
||||
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
||||
|
||||
current_version = HighlightJs.version(SiteSetting.highlighted_languages)
|
||||
|
||||
if current_version != params[:version]
|
||||
return redirect_to path(HighlightJs.path)
|
||||
end
|
||||
|
||||
# note, this can be slightly optimised by caching the bundled file, it cuts down on N reads
|
||||
# our nginx config caches this so in practical terms it does not really matter and keeps
|
||||
# code simpler
|
||||
highlight_js = HighlightJs.bundle(SiteSetting.highlighted_languages.split("|"))
|
||||
|
||||
response.headers["Last-Modified"] = 10.years.ago.httpdate
|
||||
response.headers["Content-Length"] = highlight_js.bytesize.to_s
|
||||
expires_in 1.year, public: true
|
||||
|
||||
render text: highlight_js, disposition: nil, content_type: 'application/javascript'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user