mirror of
https://gitee.com/huanghongxun/HMCL-docs.git
synced 2026-06-21 12:15:27 +08:00
添加 post_process 插件 (#445)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d7c2569844
commit
17d1ae9f05
2
Gemfile
2
Gemfile
@ -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
_config.yml
32
_config.yml
@ -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:
|
||||
@ -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
|
||||
|
||||
@ -5,10 +5,11 @@ layout: single
|
||||
{{ content }}
|
||||
|
||||
{% if page.author or page.contributors or jekyll.environment == 'production' and page.hits %}
|
||||
<script src="{{ '/assets/js/meta.js' | relative_url }}"></script>
|
||||
<script>
|
||||
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 %}
|
||||
|
||||
@ -46,10 +46,12 @@ layout: single
|
||||
{% endfor %}
|
||||
|
||||
<script>
|
||||
window.addEventListener("load", () => {
|
||||
for (const settingItem of document.getElementsByClassName("setting-item")) {
|
||||
settingItem.addEventListener("change", ({ target }) => settings.set(target.name, target.value));
|
||||
settings.onChange(settingItem.name, (value) => settingItem.type === "radio" && (settingItem.checked = settingItem.value === value));
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>.notice label input { display: inline }</style>
|
||||
|
||||
51
_plugins/post_process.rb
Normal file
51
_plugins/post_process.rb
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user