Prepare static site for deployment
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
commit
59ad2d013e
15 files changed
+526
No files matched your search
Vendored
+104
@@ -0,0 +1,104 @@
|
||||
const config = window.getRuyinConfig();
|
||||
|
||||
const icons = {
|
||||
windows: '<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3 5.2 10.7 4v7.4H3V5.2Zm8.7-1.35L21 2.5v8.9h-9.3V3.85ZM3 12.4h7.7V20L3 18.8v-6.4Zm8.7 0H21v9.1l-9.3-1.35V12.4Z"/></svg>',
|
||||
mac: '<svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M17.1 12.5c0-2.6 2.1-3.8 2.2-3.9a4.8 4.8 0 0 0-3.8-2.1c-1.6-.2-3.1 1-3.9 1-.8 0-2-1-3.3-1-1.7 0-3.3 1-4.2 2.5-1.8 3.1-.5 7.7 1.3 10.3.9 1.3 1.9 2.7 3.3 2.6 1.3 0 1.8-.8 3.5-.8 1.6 0 2.1.8 3.5.8 1.5 0 2.4-1.3 3.2-2.6 1-1.5 1.5-3 1.5-3.1-.1 0-3.3-1.3-3.3-3.7ZM14.5 4.8c.7-.9 1.2-2.1 1.1-3.3-1.1.1-2.4.7-3.2 1.6-.7.8-1.3 2-1.1 3.2 1.2.1 2.4-.6 3.2-1.5Z"/></svg>',
|
||||
linux: '<svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12.1 2c-2 0-3 1.7-3.2 3.5-.2 1.6.3 3.1-.5 4.5-.8 1.5-2.7 3.5-2.4 6.2.1 1 .6 1.8 1.3 2.4-.5.6-.6 1.3-.2 1.8.5.7 1.6.7 2.6.1.7.9 1.5 1.5 2.5 1.5s1.8-.5 2.5-1.5c1 .6 2.1.6 2.6-.1.4-.6.3-1.3-.2-1.9.7-.6 1.1-1.4 1.2-2.4.2-2.7-1.7-4.7-2.5-6.2-.8-1.4-.3-2.9-.5-4.5C15.1 3.7 14 2 12.1 2Zm-1.5 4.2c.5 0 .8.5.8 1.1s-.3 1.1-.8 1.1-.8-.5-.8-1.1.4-1.1.8-1.1Zm3 0c.5 0 .8.5.8 1.1s-.3 1.1-.8 1.1-.8-.5-.8-1.1.3-1.1.8-1.1Zm-1.5 2.1c.7 0 1.2.3 1.2.7 0 .5-.5.9-1.2.9s-1.2-.4-1.2-.9c0-.4.5-.7 1.2-.7Z"/></svg>'
|
||||
};
|
||||
|
||||
function escapeHTML(value = "") {
|
||||
return String(value).replace(/[&<>'"]/g, char => ({ "&": "&", "<": "<", ">": ">", "'": "'", '"': """ }[char]));
|
||||
}
|
||||
|
||||
function showToast(message) {
|
||||
const toast = document.querySelector(".toast");
|
||||
if (!toast) return;
|
||||
toast.textContent = message;
|
||||
toast.classList.add("show");
|
||||
clearTimeout(window.__toastTimer);
|
||||
window.__toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
|
||||
}
|
||||
|
||||
function platformKey() {
|
||||
const platform = (navigator.userAgentData?.platform || navigator.platform || "").toLowerCase();
|
||||
if (platform.includes("mac")) return "mac";
|
||||
if (platform.includes("linux")) return "linux";
|
||||
return "windows";
|
||||
}
|
||||
|
||||
function bindDownload(link, data) {
|
||||
link.href = data?.url || "#";
|
||||
if (!data?.url || data.url === "#") {
|
||||
link.addEventListener("click", event => {
|
||||
event.preventDefault();
|
||||
showToast(`${data?.label || "此平台"} 下载链接暂未配置`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function renderHome() {
|
||||
const hero = document.querySelector("[data-home]");
|
||||
if (!hero) return;
|
||||
document.querySelector("[data-headline]").textContent = config.product.headline;
|
||||
document.querySelector("[data-description]").textContent = config.product.description;
|
||||
document.querySelectorAll("[data-version]").forEach(el => el.textContent = config.product.version);
|
||||
|
||||
const enabledDownloads = Object.entries(config.downloads).filter(([, item]) => item.enabled !== false);
|
||||
const detectedKey = platformKey();
|
||||
const selectedKey = config.downloads[detectedKey]?.enabled !== false ? detectedKey : enabledDownloads[0]?.[0];
|
||||
const selected = selectedKey ? config.downloads[selectedKey] : null;
|
||||
const primary = document.querySelector("[data-primary-download]");
|
||||
if (selected) {
|
||||
primary.innerHTML = `${icons[selectedKey]}<span>下载 ${escapeHTML(selected.label)} 版</span>`;
|
||||
bindDownload(primary, selected);
|
||||
} else {
|
||||
primary.innerHTML = "<span>暂无可用下载</span>";
|
||||
primary.removeAttribute("href");
|
||||
primary.classList.add("disabled");
|
||||
primary.setAttribute("aria-disabled", "true");
|
||||
}
|
||||
|
||||
const grid = document.querySelector("[data-download-grid]");
|
||||
grid.innerHTML = enabledDownloads.length ? enabledDownloads.map(([key, item]) => `
|
||||
<article class="download-card">
|
||||
<div class="os-icon">${icons[key]}</div>
|
||||
<h3>${escapeHTML(item.label)}</h3>
|
||||
<p>${escapeHTML(item.meta)} · ${escapeHTML(item.size)}</p>
|
||||
<a class="card-download" data-download-key="${key}" href="${escapeHTML(item.url)}">
|
||||
获取安装包
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 3v13m0 0 5-5m-5 5-5-5M5 21h14"/></svg>
|
||||
</a>
|
||||
</article>`).join("") : '<div class="empty-state">下载通道正在维护中,请稍后再来。</div>';
|
||||
grid.querySelectorAll("[data-download-key]").forEach(link => bindDownload(link, config.downloads[link.dataset.downloadKey]));
|
||||
}
|
||||
|
||||
function renderDocs() {
|
||||
const list = document.querySelector("[data-docs-list]");
|
||||
if (!list) return;
|
||||
const nav = document.querySelector("[data-docs-nav]");
|
||||
if (!config.docs.length) {
|
||||
list.innerHTML = '<div class="empty-state">文档正在整理中。</div>';
|
||||
nav.innerHTML = "";
|
||||
return;
|
||||
}
|
||||
nav.innerHTML = config.docs.map((doc, index) => `<a class="${index === 0 ? "active" : ""}" href="#${escapeHTML(doc.id)}">${escapeHTML(doc.title)}</a>`).join("");
|
||||
list.innerHTML = config.docs.map(doc => `<article class="doc-card" id="${escapeHTML(doc.id)}"><span class="category">${escapeHTML(doc.category)}</span><h2>${escapeHTML(doc.title)}</h2><p class="summary">${escapeHTML(doc.summary)}</p><p class="content">${escapeHTML(doc.content)}</p></article>`).join("");
|
||||
}
|
||||
|
||||
function renderChangelog() {
|
||||
const timeline = document.querySelector("[data-changelog]");
|
||||
if (!timeline) return;
|
||||
if (!config.changelog.length) {
|
||||
timeline.innerHTML = '<div class="empty-state">暂时没有更新记录。</div>';
|
||||
return;
|
||||
}
|
||||
timeline.innerHTML = config.changelog.map(item => `<article class="release"><div class="release-meta"><time>${escapeHTML(item.date)}</time><span class="release-tag">${escapeHTML(item.type)}</span></div><h2>v${escapeHTML(item.version)}</h2><ul>${item.highlights.map(text => `<li>${escapeHTML(text)}</li>`).join("")}</ul></article>`).join("");
|
||||
}
|
||||
|
||||
renderHome();
|
||||
renderDocs();
|
||||
renderChangelog();
|
||||
|
||||
window.addEventListener("storage", event => {
|
||||
if (event.key === window.RUYIN_CONFIG_KEY) location.reload();
|
||||
});
|
||||
Reference in new issue
Block a user