mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-02 20:33:42 +00:00
@@ -221,7 +221,7 @@ def write_app_icons(dist, logo):
|
||||
mark = mark.crop(mark.getchannel('A').getbbox())
|
||||
icons = dist / 'icons'
|
||||
icons.mkdir(exist_ok=True)
|
||||
for name, size, scale, background in [('icon-180.png', 180, .84, '#ffffff'), ('icon-192.png', 192, 1, None),
|
||||
for name, size, scale, background in [('favicon-32.png', 32, 1, None), ('icon-180.png', 180, .84, '#ffffff'), ('icon-192.png', 192, 1, None),
|
||||
('icon-512.png', 512, 1, None), ('maskable-512.png', 512, .76, '#ffffff')]:
|
||||
canvas = Image.new('RGBA', (size, size), background or (0, 0, 0, 0))
|
||||
side = round(size * scale)
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
<meta name="theme-color" content="#f3f2ee" media="(prefers-color-scheme: light)">
|
||||
<meta name="theme-color" content="#1a1d1c" media="(prefers-color-scheme: dark)">
|
||||
<title>CS-Notes · CyC2018</title>
|
||||
<link rel="icon" href="/favicon.png">
|
||||
<link rel="icon" href="/icons/favicon-32.png" sizes="32x32">
|
||||
<link rel="icon" href="/icons/icon-192.png" sizes="192x192">
|
||||
<link rel="apple-touch-icon" href="/icons/icon-180.png">
|
||||
<link rel="manifest" href="/manifest.webmanifest">
|
||||
<meta property="og:type" content="website">
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
try { return decodeURIComponent(value); } catch (error) { return value; }
|
||||
}
|
||||
function encodedRoute(path) { return path.split('/').map(encodeURIComponent).join('/'); }
|
||||
// 图片前面的正文不到 1200 字(文首目录不算)时,大概率在首屏内
|
||||
function nearTop(img, root) {
|
||||
var block = img, chars = 0;
|
||||
while (block.parentElement && block.parentElement !== root && block.parentElement.tagName !== 'BODY') block = block.parentElement;
|
||||
for (var node = block.previousElementSibling; node; node = node.previousElementSibling) {
|
||||
var links = node.querySelectorAll('a');
|
||||
if (/^(UL|DETAILS)$/.test(node.tagName) && links.length > 5 &&
|
||||
Array.from(links).every(function (link) { return (link.getAttribute('href') || '').indexOf('?id=') !== -1; })) continue;
|
||||
chars += node.textContent.length;
|
||||
}
|
||||
return chars < 1200;
|
||||
}
|
||||
function configureImages(root, homepage) {
|
||||
if (!root) return;
|
||||
var first = root.querySelector('img');
|
||||
@@ -11,8 +23,10 @@
|
||||
img.loading = 'eager';
|
||||
img.setAttribute('fetchpriority', 'high');
|
||||
} else if (!img.hasAttribute('loading')) {
|
||||
// 文章的第一张图常在首屏内,延迟加载会推迟最大内容绘制,直接加载
|
||||
img.loading = !homepage && img === first ? 'eager' : 'lazy';
|
||||
// 文章的第一张图在开头附近时常在首屏内,延迟加载会推迟最大内容绘制,直接加载并提高下载优先级
|
||||
var top = !homepage && img === first && nearTop(img, root);
|
||||
img.loading = top ? 'eager' : 'lazy';
|
||||
if (top) img.setAttribute('fetchpriority', 'high');
|
||||
}
|
||||
img.decoding = 'async';
|
||||
// 笔记中的配图大多没写说明,读屏软件只能读出文件名;用所在小节的标题作为说明
|
||||
|
||||
Reference in New Issue
Block a user