feat(fuc): release navigation latency checks and updated design
This commit is contained in:
1 parent
a5d3cf5cd7
commit
e35b61b3db
5 files changed
+582
-463
No files matched your search
@@ -36,7 +36,7 @@ function load(project) {
|
||||
seenHosts.add(host);
|
||||
return {
|
||||
name: domainToUnicode(host), origin: 'https://' + host + '/', role, access, domainhub, recommended,
|
||||
label: roles.get(role) + (access ? '(' + accessLabels.get(access) + ')' : '') + (recommended ? ' · 推荐' : ''),
|
||||
label: roles.get(role) + (access ? '(' + accessLabels.get(access) + ')' : ''),
|
||||
};
|
||||
});
|
||||
if (records.filter(record => record.recommended).length > 1) throw new Error(project + ' 有多个默认推荐域名');
|
||||
@@ -48,35 +48,44 @@ function escapeHtml(value) {
|
||||
return value.replace(/[&<>"']/g, char => entities[char]);
|
||||
}
|
||||
|
||||
function renderNavigation(project, records) {
|
||||
function renderNavigation(project, records, source) {
|
||||
const recommended = records.find(record => record.recommended);
|
||||
if (!recommended || records.filter(record => record.role === 'navigation').length !== 1) {
|
||||
throw new Error(project + ' 导航需要一个导航域名和一个默认推荐域名');
|
||||
}
|
||||
const panels = records.filter(record => record.role !== 'navigation');
|
||||
const priority = ({ recommended, role, access }) => recommended ? 0
|
||||
: role === 'direct' && access === undefined ? 1 : access === 'suspected_blocked' ? 3 : 2;
|
||||
const priority = ({ recommended, role, access }) => role === 'primary' ? 0
|
||||
: recommended ? 1 : access === 'suspected_blocked' ? 3 : 2;
|
||||
panels.sort((a, b) => priority(a) - priority(b));
|
||||
const options = panels.map(({ origin, name, label, recommended, domainhub }) => {
|
||||
const options = panels.map(({ origin, name, label, recommended, domainhub, role }) => {
|
||||
const code = domainhub ? ' data-domainhub-code="' + escapeHtml(domainhub) + '"' : '';
|
||||
return [
|
||||
' <label class="entry">',
|
||||
' <label class="entry" data-role="' + role + '">',
|
||||
' <input type="radio" name="route" value="' + escapeHtml(origin) + '"' + code + (recommended ? ' checked' : '') + '>',
|
||||
' <span><strong>' + escapeHtml(name) + '</strong><small>' + escapeHtml(label) + '</small></span>',
|
||||
' <span class="entry-info"><strong>' + escapeHtml(name) + '</strong><small>' + escapeHtml(label) + '</small></span>',
|
||||
' <span class="latency">—</span>',
|
||||
' </label>',
|
||||
].join('\n');
|
||||
}).join('\n');
|
||||
// FUC's design and invite behavior are specific to FUC; the catalog is reusable.
|
||||
const template = readFileSync(new URL('./navigation.template.html', import.meta.url), 'utf8');
|
||||
const tokens = { DOMAIN_OPTIONS: options, DEFAULT_NAME: escapeHtml(recommended.name), DEFAULT_ORIGIN: escapeHtml(recommended.origin) };
|
||||
const counts = new Set();
|
||||
const html = template.replace(/\{\{([A-Z_]+)\}\}/g, (_, key) => {
|
||||
if (!Object.hasOwn(tokens, key) || counts.has(key)) throw new Error('无效导航模板标记:' + key);
|
||||
counts.add(key);
|
||||
return tokens[key];
|
||||
});
|
||||
if (counts.size !== Object.keys(tokens).length) throw new Error('导航模板缺少标记');
|
||||
return html.replace('<!doctype html>', '<!doctype html>\n<!-- 由 scripts/project-domains/manage.mjs 生成,请修改域名清单或模板。 -->');
|
||||
function replaceOnce(html, pattern, replacement) {
|
||||
if ([...html.matchAll(pattern)].length !== 1) throw new Error('导航源标记不唯一:' + pattern);
|
||||
return html.replace(pattern, replacement);
|
||||
}
|
||||
|
||||
const preview = replaceOnce(source, /<!-- project-domains:start -->[\s\S]*?<!-- project-domains:end -->/g,
|
||||
() => '<!-- project-domains:start -->\n' + options + '\n <!-- project-domains:end -->');
|
||||
const withDefault = replaceOnce(preview, /(<span id="route-status" role="status">)[^<]*(<\/span>)/g,
|
||||
(_, start, end) => start + '已选择 ' + escapeHtml(recommended.name) + end);
|
||||
|
||||
// The standalone release serves its own logo and does not require the XB theme path.
|
||||
const withLogo = replaceOnce(withDefault, /(id="brand-icon" rel="icon" href=")\.\/native\/images\/brand\/fuc-mark\.svg/g,
|
||||
(_, start) => start + './logo.svg');
|
||||
const withFallback = replaceOnce(withLogo, /(id="enter" class="enter" href=")\/#\/register"/g,
|
||||
(_, start) => start + escapeHtml(recommended.origin) + '#/register"');
|
||||
return {
|
||||
preview: withDefault,
|
||||
standalone: withFallback.replace('<!doctype html>', '<!doctype html>\n<!-- 从 theme/Fuc/assets/connect.html 和项目域名清单生成。 -->'),
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -88,10 +97,19 @@ try {
|
||||
for (const record of load(key)) console.log([key, record.name, record.label, record.domainhub ?? ''].join('\t'));
|
||||
}
|
||||
} else if (['build', 'check'].includes(action) && project === 'fuc' && rest.length === 0) {
|
||||
const html = renderNavigation(project, load(project));
|
||||
const file = new URL('../../public/brand/fuc-navigation/index.html', import.meta.url);
|
||||
if (action === 'build') writeFileSync(file, html);
|
||||
else if (readFileSync(file, 'utf8') !== html) throw new Error('导航页已过期,请重新生成');
|
||||
const source = new URL('../../theme/Fuc/assets/connect.html', import.meta.url);
|
||||
const read = path => readFileSync(new URL('../../' + path, import.meta.url));
|
||||
const { preview, standalone } = renderNavigation(project, load(project), readFileSync(source, 'utf8'));
|
||||
const files = [
|
||||
['theme/Fuc/assets/connect.html', Buffer.from(preview)],
|
||||
['public/brand/fuc-navigation/index.html', Buffer.from(standalone)],
|
||||
['public/brand/fuc-navigation/logo.svg', read('theme/Fuc/assets/native/images/brand/fuc-mark.svg')],
|
||||
['public/brand/fuc-navigation/clipboard.mjs', read('theme/Fuc/assets/clipboard.mjs')],
|
||||
];
|
||||
for (const [path, content] of files) {
|
||||
if (action === 'build') writeFileSync(new URL('../../' + path, import.meta.url), content);
|
||||
else if (!read(path).equals(content)) throw new Error(path + ' 已过期,请重新生成');
|
||||
}
|
||||
} else {
|
||||
throw new Error('用法:manage.mjs list [项目代号] | build fuc | check fuc');
|
||||
}
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<title>福云地址导航</title>
|
||||
<link rel="icon" href="./logo.svg" type="image/svg+xml">
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--page: #f5f3fb;
|
||||
--panel: #fff;
|
||||
--ink: #211b39;
|
||||
--muted: #625a76;
|
||||
--line: #e7e1f2;
|
||||
--accent: #5941bf;
|
||||
--action: #6045ce;
|
||||
--tint: #f0ebff;
|
||||
--glow: #e4dcff;
|
||||
--shadow: rgb(49 31 102 / 9%);
|
||||
font: 16px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
color-scheme: dark;
|
||||
--page: #171426;
|
||||
--panel: #201c34;
|
||||
--ink: #f6f1ff;
|
||||
--muted: #bbb2d0;
|
||||
--line: #38304d;
|
||||
--accent: #c6b7ff;
|
||||
--action: #7256df;
|
||||
--tint: #332851;
|
||||
--glow: #2d214a;
|
||||
--shadow: rgb(0 0 0 / 20%);
|
||||
}
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
color: var(--ink);
|
||||
background: radial-gradient(ellipse at 16% 30%, var(--glow), transparent 50%), var(--page);
|
||||
}
|
||||
|
||||
a { color: inherit; text-decoration: none; }
|
||||
button { color: inherit; font: inherit; cursor: pointer; }
|
||||
:is(a, button):focus-visible,
|
||||
.entry:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 4px; }
|
||||
|
||||
.wrap { width: min(1120px, calc(100% - 64px)); margin-inline: auto; }
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding-block: 26px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 750; }
|
||||
.brand img { width: 38px; height: 38px; object-fit: contain; }
|
||||
.theme {
|
||||
display: grid;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
place-items: center;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
background: var(--panel);
|
||||
}
|
||||
.theme:hover { color: var(--accent); border-color: var(--accent); }
|
||||
.theme svg { width: 19px; height: 19px; }
|
||||
[data-theme="dark"] .theme .moon, [data-theme="light"] .theme .sun { display: none; }
|
||||
|
||||
main {
|
||||
display: grid;
|
||||
grid-template-columns: .86fr 1fr;
|
||||
align-items: center;
|
||||
gap: clamp(28px, 6vw, 80px);
|
||||
min-height: min(680px, calc(100svh - 100px));
|
||||
padding-block: 64px;
|
||||
}
|
||||
|
||||
h1 { margin: 0 0 16px; font-size: clamp(38px, 6.5vw, 70px); line-height: 1.12; letter-spacing: -.045em; }
|
||||
.intro p { max-width: 23em; margin: 0; color: var(--muted); }
|
||||
.copy-control { position: relative; display: inline-block; }
|
||||
.copy-email {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
color: var(--accent);
|
||||
background: none;
|
||||
font-weight: 650;
|
||||
text-decoration: underline dotted;
|
||||
text-underline-offset: 4px;
|
||||
}
|
||||
.copy-email:hover { text-decoration-style: solid; }
|
||||
.copy-feedback {
|
||||
position: absolute;
|
||||
inset-inline-end: 0;
|
||||
inset-block-end: calc(100% + 6px);
|
||||
z-index: 1;
|
||||
width: max-content;
|
||||
max-width: 100%;
|
||||
padding: 3px 8px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
color: var(--accent);
|
||||
background: var(--panel);
|
||||
box-shadow: 0 4px 12px var(--shadow);
|
||||
font-size: 12px;
|
||||
pointer-events: none;
|
||||
}
|
||||
.copy-feedback:empty { opacity: 0; }
|
||||
|
||||
.entries {
|
||||
padding: clamp(16px, 3vw, 28px);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 24px;
|
||||
background: var(--panel);
|
||||
box-shadow: 0 22px 64px var(--shadow);
|
||||
}
|
||||
|
||||
.panel-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.entries h2 { margin: 0 0 14px; font-size: 16px; }
|
||||
.routes { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
|
||||
|
||||
.entry {
|
||||
display: grid;
|
||||
grid-template-columns: 20px minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
min-height: 80px;
|
||||
padding: 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 14px;
|
||||
cursor: pointer;
|
||||
transition: border-color .16s ease, background-color .16s ease;
|
||||
}
|
||||
|
||||
.entry:has(input:checked), .entry:hover { background: var(--tint); border-color: var(--accent); }
|
||||
.entry input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
|
||||
|
||||
.entry strong, .entry small { display: block; }
|
||||
.entry strong { overflow-wrap: anywhere; font-size: 17px; }
|
||||
.entry small { margin-top: 2px; color: var(--muted); font-size: 12px; }
|
||||
|
||||
.panel-footer { min-height: 40px; margin-block: 12px 10px; }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.entry { transition: none; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="wrap">
|
||||
<a class="brand" href="/"><img src="./logo.svg" alt="">福云</a>
|
||||
<button class="theme" type="button" aria-label="切换到浅色">
|
||||
<svg class="sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.4 1.4m11.2 11.2L19 19M5 19l1.4-1.4m11.2-11.2L19 5"/></svg>
|
||||
<svg class="moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M20.9 13.3A9 9 0 0 1 10.7 3.1a9 9 0 1 0 10.2 10.2Z"/></svg>
|
||||
</button>
|
||||
</header>
|
||||
<main class="wrap">
|
||||
<section class="intro" aria-labelledby="page-title">
|
||||
<h1 id="page-title">福云地址导航</h1>
|
||||
<p>务必,请收藏我们的邮箱
|
||||
<span class="copy-control">
|
||||
<button class="copy-email" type="button" aria-label="复制邮箱地址 [email protected]">
|
||||
[email protected]
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true">
|
||||
<path d="M8 8h9l3 3v10H8V8Z M15 8V3H3v13h5"/>
|
||||
</svg>
|
||||
</button>
|
||||
<span class="copy-feedback" role="status"></span>
|
||||
</span>。导航地址被墙时,可发送任意邮件至我们的邮箱,会自动回复最新地址。
|
||||
</p>
|
||||
</section>
|
||||
<section class="entries" aria-labelledby="entry-title">
|
||||
<h2 id="entry-title">访问入口</h2>
|
||||
<fieldset class="routes" aria-labelledby="entry-title">
|
||||
{{DOMAIN_OPTIONS}}
|
||||
</fieldset>
|
||||
<div class="panel-footer">
|
||||
<span id="route-status" role="status">已选择 {{DEFAULT_NAME}}</span>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<a id="enter" class="enter" href="{{DEFAULT_ORIGIN}}#/register">立即进入 →</a>
|
||||
<button class="countdown" type="button">开始 8 秒跳转</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
<script>
|
||||
const theme = document.querySelector('.theme');
|
||||
const routes = document.querySelector('.routes');
|
||||
const status = document.querySelector('#route-status');
|
||||
const enter = document.querySelector('#enter');
|
||||
const countdown = document.querySelector('.countdown');
|
||||
const invite = new URLSearchParams(location.search).get('code');
|
||||
const seconds = 8;
|
||||
let remaining = seconds;
|
||||
let timer;
|
||||
|
||||
function selectRoute() {
|
||||
const selected = routes.querySelector('input:checked');
|
||||
const origin = new URL(selected.value).origin;
|
||||
const code = invite && /^[A-Za-z0-9_-]{1,64}$/.test(invite) ? '?code=' + encodeURIComponent(invite) : '';
|
||||
enter.href = origin + '/#/register' + code;
|
||||
status.textContent = '已选择 ' + selected.closest('label').querySelector('strong').textContent;
|
||||
}
|
||||
|
||||
function pauseCountdown() {
|
||||
clearInterval(timer);
|
||||
timer = undefined;
|
||||
countdown.textContent = remaining === seconds ? '开始 8 秒跳转' : '继续跳转 ' + remaining + ' 秒';
|
||||
}
|
||||
|
||||
theme.addEventListener('click', () => {
|
||||
const dark = document.documentElement.dataset.theme === 'dark';
|
||||
document.documentElement.dataset.theme = dark ? 'light' : 'dark';
|
||||
theme.setAttribute('aria-label', dark ? '切换到深色' : '切换到浅色');
|
||||
});
|
||||
routes.addEventListener('change', () => {
|
||||
remaining = seconds;
|
||||
pauseCountdown();
|
||||
selectRoute();
|
||||
});
|
||||
countdown.addEventListener('click', () => {
|
||||
if (timer !== undefined) {
|
||||
pauseCountdown();
|
||||
return;
|
||||
}
|
||||
countdown.textContent = '暂停跳转 ' + remaining + ' 秒';
|
||||
timer = setInterval(() => {
|
||||
remaining -= 1;
|
||||
if (remaining === 0) {
|
||||
clearInterval(timer);
|
||||
timer = undefined;
|
||||
location.assign(enter.href);
|
||||
} else {
|
||||
countdown.textContent = '暂停跳转 ' + remaining + ' 秒';
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
selectRoute();
|
||||
</script>
|
||||
<script type="module">
|
||||
import { copyText } from './clipboard.mjs';
|
||||
|
||||
const email = document.querySelector('.copy-email');
|
||||
const feedback = document.querySelector('.copy-feedback');
|
||||
let feedbackTimer;
|
||||
email.addEventListener('click', async () => {
|
||||
clearTimeout(feedbackTimer);
|
||||
feedback.textContent = '';
|
||||
try {
|
||||
await copyText(email.textContent.trim());
|
||||
feedback.textContent = '已复制';
|
||||
feedbackTimer = setTimeout(() => { feedback.textContent = ''; }, 1600);
|
||||
} catch {
|
||||
feedback.textContent = '复制失败,请选中邮箱地址手动复制。';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user