mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: continues to rewrite to TS
This commit is contained in:
77
Build/build-public.ts
Normal file
77
Build/build-public.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import listDir from '@sukka/listdir';
|
||||
import path from 'path';
|
||||
import fsp from 'fs/promises'
|
||||
import { task } from './lib/trace-runner';
|
||||
|
||||
const rootPath = path.resolve(__dirname, '../');
|
||||
const publicPath = path.resolve(__dirname, '../public');
|
||||
|
||||
const folderAndFilesToBeDeployed = [
|
||||
'Assets',
|
||||
'List',
|
||||
'Clash',
|
||||
'Modules',
|
||||
'Script',
|
||||
'LICENSE'
|
||||
];
|
||||
|
||||
export const buildPublicHtml = task(__filename, async () => {
|
||||
await fsp.mkdir(publicPath, { recursive: true });
|
||||
await Promise.all(folderAndFilesToBeDeployed.map(dir => fsp.cp(
|
||||
path.resolve(rootPath, dir),
|
||||
path.resolve(publicPath, dir),
|
||||
{ force: true, recursive: true }
|
||||
)));
|
||||
|
||||
const list = await listDir(publicPath, {
|
||||
ignoreHidden: true,
|
||||
ignorePattern: /node_modules|Build|.DS_Store|\.(json|html|md|js)|LICENSE/
|
||||
});
|
||||
|
||||
const html = template(list);
|
||||
|
||||
return Bun.write(path.join(publicPath, 'index.html'), html);
|
||||
});
|
||||
|
||||
if (import.meta.main) {
|
||||
buildPublicHtml();
|
||||
}
|
||||
|
||||
function template(urlList: string[]) {
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Surge Ruleset Server | Sukka (@SukkaW)</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
||||
<link href="https://cdn.skk.moe/favicon.ico" rel="icon" type="image/ico">
|
||||
<link href="https://cdn.skk.moe/favicon/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180">
|
||||
<link href="https://cdn.skk.moe/favicon/android-chrome-192x192.png" rel="icon" type="image/png" sizes="192x192">
|
||||
<link href="https://cdn.skk.moe/favicon/favicon-32x32.png" rel="icon" type="image/png" sizes="32x32">
|
||||
<link href="https://cdn.skk.moe/favicon/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16">
|
||||
<meta name="description" content="Sukka 自用的 Surge 规则组">
|
||||
<meta property="og:title" content="Surge Ruleset | Sukka (@SukkaW)">
|
||||
<meta property="og:type" content="Website">
|
||||
<meta property="og:url" content="https://ruleset.skk.moe/">
|
||||
<meta property="og:image" content="https://cdn.skk.moe/favicon/android-chrome-192x192.png">
|
||||
<meta property="og:description" content="Sukka 自用的 Surge 规则组">
|
||||
<meta name="twitter:card" content="summary">
|
||||
<link rel="canonical" href="https://ruleset.skk.moe/">
|
||||
<link rel="stylesheet" href="https://cdn.staticfile.org/picocss/1.5.0/pico.slim.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Sukka Surge Ruleset Server</h1>
|
||||
<p>Made by <a href="https://skk.moe">Sukka</a> | <a href="https://github.com/SukkaW/Surge/">Source @ GitHub</a> | Licensed under <a href="https://github.com/SukkaW/Surge/blob/master/LICENSE" target="_blank">AGPL-3.0</a></p>
|
||||
<p>Last Build: ${new Date().toISOString()}</p>
|
||||
<hr>
|
||||
<br>
|
||||
<ul>
|
||||
${urlList.sort().map(url => `<li><a href="${url}" target="_blank">${url}</a></li>`).join('')}
|
||||
</ul>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
Reference in New Issue
Block a user