mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 03:37:15 +08:00
a82530012a
PERF: stop loading highlight js on load To get latest highlight js run bin/rake highlightjs:update
33 lines
748 B
Ruby
33 lines
748 B
Ruby
module HighlightJs
|
|
|
|
def self.languages
|
|
Dir.glob(File.dirname(__FILE__) << "/assets/lang/*.js").map do |path|
|
|
File.basename(path)[0..-4]
|
|
end
|
|
end
|
|
|
|
def self.bundle(langs)
|
|
path = File.dirname(__FILE__) << "/assets/"
|
|
|
|
result = File.read(path + "highlight.js")
|
|
langs.each do |lang|
|
|
begin
|
|
result << "\n" << File.read(path + "lang/#{lang}.js")
|
|
rescue Errno::ENOENT
|
|
# no file, don't care
|
|
end
|
|
end
|
|
|
|
result
|
|
end
|
|
|
|
def self.version(lang_string)
|
|
(@lang_string_cache ||= {})[lang_string] ||=
|
|
Digest::SHA1.hexdigest(bundle lang_string.split("|"))
|
|
end
|
|
|
|
def self.path
|
|
"/highlight-js/#{Discourse.current_hostname}/#{version SiteSetting.highlighted_languages}.js"
|
|
end
|
|
end
|