hexo-theme-linen 1.0.51 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/layout/post.ejs +6 -5
- package/package.json +1 -1
- package/scripts/custom.js +333 -0
- package/scripts/lazyload/inject.js +20 -16
- package/source/linen-theme/css/_mediaquery.scss +144 -45
- package/source/linen-theme/css/lazyload.css +20 -16
- package/source/linen-theme/css/linen.scss +1509 -519
- package/source/linen-theme/css/linkcard.scss +70 -52
- package/source/linen-theme/css/vars.scss +66 -35
- package/source/linen-theme/js/linen.js +325 -4
|
@@ -198,11 +198,12 @@ function initAnchorHighlighter({
|
|
|
198
198
|
style.id = "anchor-highlight-style";
|
|
199
199
|
style.textContent = `
|
|
200
200
|
@keyframes anchorFlash {
|
|
201
|
-
0% { background-color: rgba(
|
|
201
|
+
0% { background-color: rgba(168, 69, 46, 0.14); }
|
|
202
202
|
100% { background-color: transparent; }
|
|
203
203
|
}
|
|
204
204
|
.${highlightClass} {
|
|
205
|
-
|
|
205
|
+
border-radius: 3px;
|
|
206
|
+
animation: anchorFlash ${duration}ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
206
207
|
}
|
|
207
208
|
`;
|
|
208
209
|
document.head.appendChild(style);
|
|
@@ -216,7 +217,7 @@ function initAnchorHighlighter({
|
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
initAnchorHighlighter({
|
|
219
|
-
duration:
|
|
220
|
+
duration: 1800,
|
|
220
221
|
});
|
|
221
222
|
|
|
222
223
|
function initImageGridSwitchers() {
|
|
@@ -643,8 +644,328 @@ function initMaskScrollLock() {
|
|
|
643
644
|
);
|
|
644
645
|
}
|
|
645
646
|
|
|
647
|
+
function initTravelRoutes() {
|
|
648
|
+
var contentEl = document.querySelector("#post.travel-post #page-content");
|
|
649
|
+
if (!contentEl) return;
|
|
650
|
+
|
|
651
|
+
var ROUTE_HEADING_RE = /^(?:路线|路线规划|Route|Route Planning)$/i;
|
|
652
|
+
var PALETTE = [
|
|
653
|
+
"#c97a63",
|
|
654
|
+
"#a8452e",
|
|
655
|
+
"#8a9a86",
|
|
656
|
+
"#c4b7a6",
|
|
657
|
+
"#b87d56",
|
|
658
|
+
"#6d8b74",
|
|
659
|
+
"#d49a79",
|
|
660
|
+
"#9c8f84",
|
|
661
|
+
];
|
|
662
|
+
var isEnglish = /^en/i.test(document.documentElement.lang || "");
|
|
663
|
+
|
|
664
|
+
function getHeadingText(heading) {
|
|
665
|
+
var clone = heading.cloneNode(true);
|
|
666
|
+
clone
|
|
667
|
+
.querySelectorAll(".headerlink, .header-anchor")
|
|
668
|
+
.forEach(function (el) {
|
|
669
|
+
el.remove();
|
|
670
|
+
});
|
|
671
|
+
return (clone.textContent || "")
|
|
672
|
+
.replace(/^[#¶\s]+|[#¶\s]+$/g, "")
|
|
673
|
+
.trim();
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function parseZhNum(str) {
|
|
677
|
+
var map = {
|
|
678
|
+
半: 0.5,
|
|
679
|
+
一: 1,
|
|
680
|
+
二: 2,
|
|
681
|
+
两: 2,
|
|
682
|
+
三: 3,
|
|
683
|
+
四: 4,
|
|
684
|
+
五: 5,
|
|
685
|
+
六: 6,
|
|
686
|
+
七: 7,
|
|
687
|
+
八: 8,
|
|
688
|
+
九: 9,
|
|
689
|
+
十: 10,
|
|
690
|
+
};
|
|
691
|
+
if (Object.prototype.hasOwnProperty.call(map, str)) return map[str];
|
|
692
|
+
if (/^十[一二三四五六七八九]$/.test(str)) return 10 + map[str[1]];
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function parseDuration(text) {
|
|
697
|
+
var trimmed = String(text || "").trim();
|
|
698
|
+
if (!trimmed) return null;
|
|
699
|
+
|
|
700
|
+
var compound = trimmed.match(
|
|
701
|
+
/^(\d+(?:\.\d+)?)\s*(日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)$/
|
|
702
|
+
);
|
|
703
|
+
if (compound) {
|
|
704
|
+
var val = Number(compound[1]);
|
|
705
|
+
if (isFinite(val) && val > 0) {
|
|
706
|
+
return {
|
|
707
|
+
label: trimmed,
|
|
708
|
+
weight: val,
|
|
709
|
+
unitKind: "day",
|
|
710
|
+
unitText: compound[2],
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (/^(半日|半天|half\s+day)$/i.test(trimmed)) {
|
|
716
|
+
var isEn = /day/i.test(trimmed);
|
|
717
|
+
return {
|
|
718
|
+
label: trimmed,
|
|
719
|
+
weight: 0.5,
|
|
720
|
+
unitKind: "day",
|
|
721
|
+
unitText: isEn ? "days" : trimmed.slice(-1) === "日" ? "日" : "天",
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
var zhNum = trimmed.match(
|
|
726
|
+
/^(十?[一二两三四五六七八九]|十)\s*(日|天|晚|夜)(半)?$/
|
|
727
|
+
);
|
|
728
|
+
if (zhNum) {
|
|
729
|
+
var base = parseZhNum(zhNum[1]);
|
|
730
|
+
if (base) {
|
|
731
|
+
var unitChar = zhNum[2];
|
|
732
|
+
return {
|
|
733
|
+
label: trimmed,
|
|
734
|
+
weight: base + (zhNum[3] ? 0.5 : 0),
|
|
735
|
+
unitKind: unitChar === "晚" || unitChar === "夜" ? "night" : "day",
|
|
736
|
+
unitText: unitChar,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
var num = trimmed.match(
|
|
742
|
+
/^(\d+(?:\.\d+)?)\s*(日|天|晚|夜|小时|days?|nights?|hours?|hrs?|d|h)$/i
|
|
743
|
+
);
|
|
744
|
+
if (num) {
|
|
745
|
+
var n = Number(num[1]);
|
|
746
|
+
if (isFinite(n) && n > 0) {
|
|
747
|
+
var lower = num[2].toLowerCase();
|
|
748
|
+
var unitKind = "day";
|
|
749
|
+
var unitText = num[2];
|
|
750
|
+
if (lower === "晚" || lower === "夜" || lower.indexOf("night") === 0) {
|
|
751
|
+
unitKind = "night";
|
|
752
|
+
unitText = lower.indexOf("night") === 0 ? "nights" : num[2];
|
|
753
|
+
} else if (
|
|
754
|
+
lower === "小时" ||
|
|
755
|
+
lower.indexOf("hour") === 0 ||
|
|
756
|
+
lower.indexOf("hr") === 0 ||
|
|
757
|
+
lower === "h"
|
|
758
|
+
) {
|
|
759
|
+
unitKind = "hour";
|
|
760
|
+
unitText = lower === "小时" ? "小时" : "hours";
|
|
761
|
+
} else if (lower.indexOf("day") === 0 || lower === "d") {
|
|
762
|
+
unitKind = "day";
|
|
763
|
+
unitText = "days";
|
|
764
|
+
}
|
|
765
|
+
return { label: trimmed, weight: n, unitKind: unitKind, unitText: unitText };
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function parseItem(rawHtml) {
|
|
773
|
+
var content = String(rawHtml || "").trim();
|
|
774
|
+
if (/^<p>[\s\S]*<\/p>$/i.test(content) && !/<\/p>\s*<p>/i.test(content)) {
|
|
775
|
+
content = content.replace(/^<p>|<\/p>$/gi, "").trim();
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
var note = "";
|
|
779
|
+
var duration = null;
|
|
780
|
+
|
|
781
|
+
var paren = content.match(
|
|
782
|
+
/^(.*?)[\s]*(?:(([^()]+))|\(([^()]+)\))\s*$/
|
|
783
|
+
);
|
|
784
|
+
if (paren && paren[1].trim()) {
|
|
785
|
+
var inner = (paren[2] || paren[3] || "").trim();
|
|
786
|
+
var pd = parseDuration(inner);
|
|
787
|
+
if (pd) {
|
|
788
|
+
duration = pd;
|
|
789
|
+
} else {
|
|
790
|
+
note = inner;
|
|
791
|
+
}
|
|
792
|
+
content = paren[1].trim();
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (!duration) {
|
|
796
|
+
var tail = content.match(
|
|
797
|
+
/^(.*?)(?:[\s·•\-—::,,/]+)(\d+(?:\.\d+)?\s*(?:日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)|\d+(?:\.\d+)?\s*(?:日|天|晚|夜|小时|days?|nights?|hours?|hrs?|d|h)|(?:半日|半天|half\s+day)|(?:十?[一二两三四五六七八九]|十)\s*(?:日|天|晚|夜)(?:半)?)\s*$/i
|
|
798
|
+
);
|
|
799
|
+
if (tail && tail[1].trim()) {
|
|
800
|
+
var td = parseDuration(tail[2]);
|
|
801
|
+
if (td) {
|
|
802
|
+
duration = td;
|
|
803
|
+
content = tail[1].trim();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (!duration) {
|
|
809
|
+
var compact = content.match(
|
|
810
|
+
/^(.*?)(\d+(?:\.\d+)?\s*(?:日|天)\s*\d+(?:\.\d+)?\s*(?:晚|夜)|\d+(?:\.\d+)?\s*(?:日|天|晚|夜|小时)|半日|半天)$/
|
|
811
|
+
);
|
|
812
|
+
if (compact && compact[1].trim()) {
|
|
813
|
+
var cd = parseDuration(compact[2]);
|
|
814
|
+
if (cd) {
|
|
815
|
+
duration = cd;
|
|
816
|
+
content = compact[1].trim();
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
var place = content.replace(/[\s·•\-—::,,/]+$/, "").trim();
|
|
822
|
+
if (!place) {
|
|
823
|
+
return { place: rawHtml.trim(), duration: null, note: "" };
|
|
824
|
+
}
|
|
825
|
+
return { place: place, duration: duration, note: note };
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function getCols(count) {
|
|
829
|
+
if (count <= 2) return 2;
|
|
830
|
+
if (count === 3 || count === 5 || count === 6 || count === 9) return 3;
|
|
831
|
+
return 4;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
contentEl.querySelectorAll("h2, h3").forEach(function (heading) {
|
|
835
|
+
if (!ROUTE_HEADING_RE.test(getHeadingText(heading))) return;
|
|
836
|
+
|
|
837
|
+
var next = heading.nextElementSibling;
|
|
838
|
+
while (next && next.id === "gitalk-initiator") {
|
|
839
|
+
next = next.nextElementSibling;
|
|
840
|
+
}
|
|
841
|
+
if (!next || (next.tagName !== "UL" && next.tagName !== "OL")) return;
|
|
842
|
+
if (next.classList.contains("travel-route-grid")) return;
|
|
843
|
+
if (next.querySelector("ul, ol, img, iframe, table, pre, blockquote, figure")) {
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
var lis = Array.prototype.slice.call(next.children).filter(function (el) {
|
|
848
|
+
return el.tagName === "LI";
|
|
849
|
+
});
|
|
850
|
+
if (lis.length < 2) return;
|
|
851
|
+
|
|
852
|
+
var stops = lis.map(function (li) {
|
|
853
|
+
return parseItem(li.innerHTML);
|
|
854
|
+
});
|
|
855
|
+
var withDuration = stops.filter(function (s) {
|
|
856
|
+
return !!s.duration;
|
|
857
|
+
});
|
|
858
|
+
var showBar = withDuration.length >= 2;
|
|
859
|
+
var cols = getCols(stops.length);
|
|
860
|
+
|
|
861
|
+
var block = document.createElement("div");
|
|
862
|
+
block.className = "travel-route-block" + (showBar ? " has-bar" : "");
|
|
863
|
+
block.style.setProperty("--route-cols", String(cols));
|
|
864
|
+
|
|
865
|
+
if (showBar) {
|
|
866
|
+
var unitKinds = new Set(
|
|
867
|
+
withDuration.map(function (s) {
|
|
868
|
+
return s.duration.unitKind;
|
|
869
|
+
})
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
if (
|
|
873
|
+
withDuration.length === stops.length &&
|
|
874
|
+
unitKinds.size === 1 &&
|
|
875
|
+
(unitKinds.has("day") || unitKinds.has("night"))
|
|
876
|
+
) {
|
|
877
|
+
var total = Number(
|
|
878
|
+
withDuration
|
|
879
|
+
.reduce(function (sum, s) {
|
|
880
|
+
return sum + s.duration.weight;
|
|
881
|
+
}, 0)
|
|
882
|
+
.toFixed(2)
|
|
883
|
+
);
|
|
884
|
+
var firstUnit = withDuration[0].duration.unitText;
|
|
885
|
+
var useEn = isEnglish || /^[a-z]+$/i.test(firstUnit);
|
|
886
|
+
var summary = document.createElement("div");
|
|
887
|
+
summary.className = "travel-route-summary";
|
|
888
|
+
summary.textContent = useEn
|
|
889
|
+
? stops.length + " STOPS · " + total + " " + firstUnit.toUpperCase()
|
|
890
|
+
: stops.length + " 站 · 共 " + total + " " + firstUnit;
|
|
891
|
+
block.appendChild(summary);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
var bar = document.createElement("div");
|
|
895
|
+
bar.className = "travel-route-bar";
|
|
896
|
+
bar.setAttribute("aria-hidden", "true");
|
|
897
|
+
stops.forEach(function (stop, idx) {
|
|
898
|
+
if (!stop.duration) return;
|
|
899
|
+
var seg = document.createElement("span");
|
|
900
|
+
var color = PALETTE[idx % PALETTE.length];
|
|
901
|
+
var flexWeight = stop.duration.weight;
|
|
902
|
+
if (unitKinds.size > 1 && stop.duration.unitKind === "hour") {
|
|
903
|
+
flexWeight = Math.max(stop.duration.weight / 24, 0.25);
|
|
904
|
+
}
|
|
905
|
+
seg.className = "travel-route-seg";
|
|
906
|
+
seg.style.flex = String(flexWeight);
|
|
907
|
+
seg.style.setProperty("--stop-color", color);
|
|
908
|
+
var plainPlace = stop.place.replace(/<[^>]*>/g, "").trim();
|
|
909
|
+
seg.title = plainPlace + " · " + stop.duration.label;
|
|
910
|
+
bar.appendChild(seg);
|
|
911
|
+
});
|
|
912
|
+
block.appendChild(bar);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
var grid = document.createElement("ul");
|
|
916
|
+
grid.className = "travel-route-grid";
|
|
917
|
+
stops.forEach(function (stop, idx) {
|
|
918
|
+
var color = PALETTE[idx % PALETTE.length];
|
|
919
|
+
var li = document.createElement("li");
|
|
920
|
+
li.className = "travel-route-item";
|
|
921
|
+
li.style.setProperty("--stop-color", color);
|
|
922
|
+
|
|
923
|
+
var top = document.createElement("div");
|
|
924
|
+
top.className = "travel-route-item-top";
|
|
925
|
+
var idxSpan = document.createElement("span");
|
|
926
|
+
idxSpan.className = "travel-route-index";
|
|
927
|
+
idxSpan.textContent = String(idx + 1).padStart(2, "0");
|
|
928
|
+
var dot = document.createElement("span");
|
|
929
|
+
dot.className = "travel-route-dot";
|
|
930
|
+
dot.setAttribute("aria-hidden", "true");
|
|
931
|
+
top.appendChild(idxSpan);
|
|
932
|
+
top.appendChild(dot);
|
|
933
|
+
|
|
934
|
+
var placeDiv = document.createElement("div");
|
|
935
|
+
placeDiv.className = "travel-route-place";
|
|
936
|
+
placeDiv.innerHTML = stop.place;
|
|
937
|
+
|
|
938
|
+
li.appendChild(top);
|
|
939
|
+
li.appendChild(placeDiv);
|
|
940
|
+
|
|
941
|
+
if (stop.duration) {
|
|
942
|
+
var daysSpan = document.createElement("span");
|
|
943
|
+
daysSpan.className = "travel-route-days";
|
|
944
|
+
daysSpan.textContent = stop.duration.label;
|
|
945
|
+
li.appendChild(daysSpan);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
if (stop.note) {
|
|
949
|
+
var noteSpan = document.createElement("span");
|
|
950
|
+
noteSpan.className = "travel-route-note";
|
|
951
|
+
noteSpan.textContent = stop.note;
|
|
952
|
+
li.appendChild(noteSpan);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
grid.appendChild(li);
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
block.appendChild(grid);
|
|
959
|
+
next.parentNode.replaceChild(block, next);
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
|
|
646
963
|
if (document.readyState === "loading") {
|
|
647
|
-
document.addEventListener("DOMContentLoaded",
|
|
964
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
965
|
+
initMaskScrollLock();
|
|
966
|
+
initTravelRoutes();
|
|
967
|
+
});
|
|
648
968
|
} else {
|
|
649
969
|
initMaskScrollLock();
|
|
970
|
+
initTravelRoutes();
|
|
650
971
|
}
|