Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ gem "http_parser.rb", "0.8.0", :platforms => [:jruby]

# plugin dependencies
gem "webp-ffi", "0.4.0" if ENV["ENABLE_WEBP_AUTO_CONVERSION"] == "true" || ENV["DRONE"] == "true"
gem "mini_racer", "0.20.0" if ENV["ENABLE_EMBEDDED_V8"] == "true" || ENV["DRONE"] == "true"
gem "terser", "1.2.7"
32 changes: 26 additions & 6 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,6 @@ compress_html:
ignore:
envs: development

head_scripts:
- /assets/js/settings.js
- /assets/js/theme.js
after_footer_scripts:
- /assets/js/plugins/jquery.auto-redirect.js

# jekyll-feed
feed:
collections:
Expand All @@ -330,3 +324,29 @@ feed:
- modpack
- eula
- multiplayer

post_process:
terser:
/assets/js/main.min.js:
- /assets/js/settings.js
- /assets/js/theme.js
- /assets/js/meta.js
- /assets/js/vendor/jquery/jquery-3.6.0.js
- /assets/js/plugins/gumshoe.js
- /assets/js/plugins/jquery.ba-throttle-debounce.js
- /assets/js/plugins/jquery.fitvids.js
- /assets/js/plugins/jquery.greedy-navigation.js
- /assets/js/plugins/jquery.magnific-popup.js
- /assets/js/plugins/smooth-scroll.js
- /assets/js/plugins/jquery.auto-redirect.js
- /assets/js/_main.js
remove_dirs:
- /assets/images/
- /assets/js/plugins/
- /assets/js/vendor/
remove_files:
- /assets/js/meta.js
- /assets/js/_main.js
- /assets/js/theme.js
- /assets/js/settings.js
- /assets/js/main.min.js.map
9 changes: 5 additions & 4 deletions _layouts/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
{{ content }}

{% if page.author or page.contributors or jekyll.environment == 'production' and page.hits %}
<script src="{{ '/assets/js/meta.js' | relative_url }}"></script>
<script>
{%- if page.author %}appendMeta("{{ page.author }}", "fas fa-user-pen");{% endif -%}
{%- for contributor in page.contributors %}appendMeta("{{ contributor }}", "fas fa-user-pen");{% endfor -%}
{%- if jekyll.environment == 'production' and page.hits %}hits({{ page.url | absolute_url | jsonify }});{% endif -%}
window.addEventListener("load", () => {
{%- if page.author %}appendMeta("{{ page.author }}", "fas fa-user-pen");{% endif -%}
{%- for contributor in page.contributors %}appendMeta("{{ contributor }}", "fas fa-user-pen");{% endfor -%}
{%- if jekyll.environment == 'production' and page.hits %}hits({{ page.url | absolute_url | jsonify }});{% endif -%}
});
</script>
{% endif %}
51 changes: 51 additions & 0 deletions _plugins/post_process.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "terser"

ExecJS.runtime = ExecJS::Runtimes::MiniRacer if ExecJS::Runtimes::MiniRacer.available?

Jekyll::Hooks.register :site, :post_write do |site|
config = site.config["post_process"]
next unless config

terser = config["terser"]
if terser.is_a?(Hash)
terser.each do |terser_output, terser_inputs|
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)

terser_codes = []
terser_inputs_all_exist = true
terser_inputs.each do |file|
destination = File.join(site.dest, file)
if File.exist?(destination)
terser_codes << File.read(destination, encoding: "UTF-8")
else
terser_inputs_all_exist = false
break
end
end

if terser_inputs_all_exist
destination = File.join(site.dest, terser_output.to_s)
File.write(destination, Terser.compile(terser_codes.join(";")))
Jekyll.logger.info "Post Process:", "terser #{terser_output}"
end
end
end

remove_files = config["remove_files"]
if remove_files.is_a?(Array)
remove_files.each do |file|
destination = File.join(site.dest, file)
File.delete(destination) if File.exist?(destination)
Jekyll.logger.info "Post Process:", "remove_files #{file}"
end
end

remove_dirs = config["remove_dirs"]
if remove_dirs.is_a?(Array)
remove_dirs.each do |dir|
destination = File.join(site.dest, dir)
FileUtils.rm_rf(destination) if File.directory?(destination)
Jekyll.logger.info "Post Process:", "remove_dirs #{dir}"
end
end
end