Skip to content

Commit 3c083e3

Browse files
authored
更新断点配置
1 parent 06950ec commit 3c083e3

File tree

5 files changed

+212
-6
lines changed

5 files changed

+212
-6
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ gem "http_parser.rb", "0.8.0", :platforms => [:jruby]
3434
# plugin dependencies
3535
gem "nokogiri", "1.18.10"
3636
gem "addressable", "2.8.7"
37+
gem "mini_racer", "0.20.0" if ENV["ENABLE_EMBEDDED_V8"] == "true" || ENV["DRONE"] == "true"
38+
gem "terser", "1.2.7"

_config.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,6 @@ compress_html:
318318
ignore:
319319
envs: development
320320

321-
head_scripts:
322-
- /assets/js/settings.js
323-
- /assets/js/theme.js
324-
after_footer_scripts:
325-
- /assets/js/plugins/jquery.auto-redirect.js
326-
327321
# jekyll-feed
328322
feed:
329323
collections:
@@ -332,3 +326,27 @@ feed:
332326
- modpack
333327
- eula
334328
- multiplayer
329+
330+
post_process:
331+
terser:
332+
/assets/js/main.min.js:
333+
- /assets/js/settings.js
334+
- /assets/js/theme.js
335+
- /assets/js/vendor/jquery/jquery-3.6.0.js
336+
- /assets/js/plugins/gumshoe.js
337+
- /assets/js/plugins/jquery.ba-throttle-debounce.js
338+
- /assets/js/plugins/jquery.fitvids.js
339+
- /assets/js/plugins/jquery.greedy-navigation.js
340+
- /assets/js/plugins/jquery.magnific-popup.js
341+
- /assets/js/plugins/smooth-scroll.js
342+
- /assets/js/plugins/jquery.auto-redirect.js
343+
- /assets/js/_main.js
344+
remove_dirs:
345+
- /assets/images/
346+
- /assets/js/plugins/
347+
- /assets/js/vendor/
348+
remove_files:
349+
- /assets/js/_main.js
350+
- /assets/js/theme.js
351+
- /assets/js/settings.js
352+
- /assets/js/main.min.js.map

_plugins/post_process.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require "terser"
2+
3+
ExecJS.runtime = ExecJS::Runtimes::MiniRacer if ExecJS::Runtimes::MiniRacer.available?
4+
5+
Jekyll::Hooks.register :site, :post_write do |site|
6+
config = site.config["post_process"]
7+
next unless config
8+
9+
terser = config["terser"]
10+
if terser.is_a?(Hash)
11+
terser.each do |terser_output, terser_inputs|
12+
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)
13+
14+
terser_codes = []
15+
terser_inputs_all_exist = true
16+
terser_inputs.each do |file|
17+
destination = File.join(site.dest, file)
18+
if File.exist?(destination)
19+
terser_codes << File.read(destination, encoding: "UTF-8")
20+
else
21+
terser_inputs_all_exist = false
22+
break
23+
end
24+
end
25+
26+
if terser_inputs_all_exist
27+
destination = File.join(site.dest, terser_output.to_s)
28+
File.write(destination, Terser.compile(terser_codes.join(";")))
29+
Jekyll.logger.info "Post Process:", "terser #{terser_output}"
30+
end
31+
end
32+
end
33+
34+
remove_files = config["remove_files"]
35+
if remove_files.is_a?(Array)
36+
remove_files.each do |file|
37+
destination = File.join(site.dest, file)
38+
File.delete(destination) if File.exist?(destination)
39+
Jekyll.logger.info "Post Process:", "remove_files #{file}"
40+
end
41+
end
42+
43+
remove_dirs = config["remove_dirs"]
44+
if remove_dirs.is_a?(Array)
45+
remove_dirs.each do |dir|
46+
destination = File.join(site.dest, dir)
47+
FileUtils.rm_rf(destination) if File.directory?(destination)
48+
Jekyll.logger.info "Post Process:", "remove_dirs #{dir}"
49+
end
50+
end
51+
end

_sass/minimal-mistakes-plus.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
$large: 1200px !default;
2+
$x-large: 1400px !default;
3+
14
@import "minimal-mistakes";
25

36
blockquote {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
GreedyNav.js - https://github.com/lukejacksonn/GreedyNav
3+
Licensed under the MIT license - http://opensource.org/licenses/MIT
4+
Copyright (c) 2015 Luke Jackson http://lukejacksonn.com
5+
*/
6+
7+
$(function() {
8+
9+
var $btn = $("nav.greedy-nav .greedy-nav__toggle");
10+
var $vlinks = $("nav.greedy-nav .visible-links");
11+
var $hlinks = $("nav.greedy-nav .hidden-links");
12+
var $nav = $("nav.greedy-nav");
13+
var $logo = $('nav.greedy-nav .site-logo');
14+
var $logoImg = $('nav.greedy-nav .site-logo img');
15+
var $title = $("nav.greedy-nav .site-title");
16+
var $search = $('nav.greedy-nav button.search__toggle');
17+
18+
var numOfItems, totalSpace, closingTime, breakWidths;
19+
20+
// This function measures both hidden and visible links and sets the navbar breakpoints
21+
// This is called the first time the script runs and everytime the "check()" function detects a change of window width that reached a different CSS width breakpoint, which affects the size of navbar Items
22+
// Please note that "CSS width breakpoints" (which are only 4) !== "navbar breakpoints" (which are as many as the number of items on the navbar)
23+
function measureLinks(){
24+
numOfItems = 0;
25+
totalSpace = 0;
26+
closingTime = 1000;
27+
breakWidths = [];
28+
29+
// Adds the width of a navItem in order to create breakpoints for the navbar
30+
function addWidth(i, w) {
31+
totalSpace += w;
32+
numOfItems += 1;
33+
breakWidths.push(totalSpace);
34+
}
35+
36+
// Measures the width of hidden links by making a temporary clone of them and positioning under visible links
37+
function hiddenWidth(obj){
38+
var clone = obj.clone();
39+
clone.css("visibility","hidden");
40+
$vlinks.append(clone);
41+
addWidth(0, clone.outerWidth());
42+
clone.remove();
43+
}
44+
// Measure both visible and hidden links widths
45+
$vlinks.children().outerWidth(addWidth);
46+
$hlinks.children().each(function(){hiddenWidth($(this))});
47+
}
48+
// Get initial state
49+
measureLinks();
50+
51+
var winWidth = $( window ).width();
52+
// Set the last measured CSS width breakpoint: 0: < 768px, 1: < 1200px, 2: < 1400px, 3: >= 1400px.
53+
var lastBreakpoint = winWidth < 768 ? 0 : winWidth < 1200 ? 1 : winWidth < 1400 ? 2 : 3;
54+
55+
var availableSpace, numOfVisibleItems, requiredSpace, timer;
56+
57+
function check() {
58+
59+
winWidth = $( window ).width();
60+
// Set the current CSS width breakpoint: 0: <768px, 1: < 1200px, 2: < 1400px, 3: >= 1400px.
61+
var curBreakpoint = winWidth < 768 ? 0 : winWidth < 1200 ? 1 : winWidth < 1400 ? 2 : 3;
62+
// If current breakpoint is different from last measured breakpoint, measureLinks again
63+
if(curBreakpoint !== lastBreakpoint) measureLinks();
64+
// Set the last measured CSS width breakpoint with the current breakpoint
65+
lastBreakpoint = curBreakpoint;
66+
67+
// Get instant state
68+
numOfVisibleItems = $vlinks.children().length;
69+
// Decrease the width of visible elements from the nav innerWidth to find out the available space for navItems
70+
availableSpace = /* nav */ $nav.innerWidth()
71+
- /* logo */ ($logo.length !== 0 ? $logo.outerWidth(true) : 0)
72+
- /* title */ $title.outerWidth(true)
73+
- /* search */ ($search.length !== 0 ? $search.outerWidth(true) : 0)
74+
- /* toggle */ (numOfVisibleItems !== breakWidths.length ? $btn.outerWidth(true) : 0);
75+
requiredSpace = breakWidths[numOfVisibleItems - 1];
76+
77+
// There is not enought space
78+
if (requiredSpace > availableSpace) {
79+
$vlinks.children().last().prependTo($hlinks);
80+
numOfVisibleItems -= 1;
81+
check();
82+
// There is more than enough space. If only one element is hidden, add the toggle width to the available space
83+
} else if (availableSpace + (numOfVisibleItems === breakWidths.length - 1?$btn.outerWidth(true):0) > breakWidths[numOfVisibleItems]) {
84+
$hlinks.children().first().appendTo($vlinks);
85+
numOfVisibleItems += 1;
86+
check();
87+
}
88+
// Update the button accordingly
89+
$btn.attr("count", numOfItems - numOfVisibleItems);
90+
if (numOfVisibleItems === numOfItems) {
91+
$btn.addClass('hidden');
92+
} else $btn.removeClass('hidden');
93+
}
94+
95+
// Window listeners
96+
$(window).resize(function() {
97+
check();
98+
});
99+
100+
$btn.on('click', function() {
101+
$hlinks.toggleClass('hidden');
102+
$(this).toggleClass('close');
103+
clearTimeout(timer);
104+
});
105+
106+
$hlinks.on("click", function () {
107+
// Hide the hidden links & remove the overlay when one is clicked.
108+
$hlinks.addClass("hidden");
109+
$btn.removeClass("close");
110+
}).on('mouseleave', function() {
111+
// Mouse has left, start the timer
112+
timer = setTimeout(function() {
113+
$hlinks.addClass('hidden');
114+
$('.greedy-nav__toggle').removeClass('close');
115+
}, closingTime);
116+
}).on('mouseenter', function() {
117+
// Mouse is back, cancel the timer
118+
clearTimeout(timer);
119+
})
120+
121+
// check if page has a logo
122+
if($logoImg.length !== 0){
123+
// check if logo is not loaded
124+
if(!($logoImg[0].complete || $logoImg[0].naturalWidth !== 0)){
125+
// if logo is not loaded wait for logo to load or fail to check
126+
$logoImg.one("load error", check);
127+
// if logo is already loaded just check
128+
} else check();
129+
// if page does not have a logo just check
130+
} else check();
131+
132+
});

0 commit comments

Comments
 (0)