build-index.html.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const listDir = require('@sukka/listdir');
  2. const path = require('path');
  3. const fs = require('fs');
  4. const rootPath = path.resolve(__dirname, '../');
  5. (async () => {
  6. const list = await listDir(rootPath, {
  7. ignoreHidden: true,
  8. ignorePattern: /node_modules|Build|.DS_Store|\.(json|html|md|js)|LICENSE/
  9. });
  10. const html = template(list);
  11. await fs.promises.writeFile(path.join(rootPath, 'index.html'), html, 'utf-8');
  12. })();
  13. /**
  14. * @param {string[]} urlList
  15. * @returns {string}
  16. */
  17. function template(urlList) {
  18. const date = new Date();
  19. return `
  20. <!DOCTYPE html>
  21. <html lang="en">
  22. <head>
  23. <meta charset="utf-8">
  24. <title>Surge Ruleset Server | Sukka (@SukkaW)</title>
  25. <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
  26. <link href="https://cdn.skk.moe/favicon.ico" rel="icon" type="image/ico">
  27. <link href="https://cdn.skk.moe/favicon/apple-touch-icon.png" rel="apple-touch-icon" sizes="180x180">
  28. <link href="https://cdn.skk.moe/favicon/android-chrome-192x192.png" rel="icon" type="image/png" sizes="192x192">
  29. <link href="https://cdn.skk.moe/favicon/favicon-32x32.png" rel="icon" type="image/png" sizes="32x32">
  30. <link href="https://cdn.skk.moe/favicon/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16">
  31. <link href="https://cdn.skk.moe/favicon/safari-pinned-tab.svg" rel="mask-icon" color="#fcfcfc">
  32. <meta name="description" content="Sukka 自用的 Surge 规则组">
  33. <meta property="og:title" content="Surge Ruleset | Sukka (@SukkaW)">
  34. <meta property="og:type" content="Website">
  35. <meta property="og:url" content="https://ruleset.skk.moe/">
  36. <meta property="og:image" content="https://cdn.skk.moe/favicon/android-chrome-192x192.png">
  37. <meta property="og:description" content="Sukka 自用的 Surge 规则组">
  38. <meta name="twitter:card" content="summary">
  39. <link rel="canonical" href="https://ruleset.skk.moe/">
  40. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1.5.0/css/pico.min.css">
  41. </head>
  42. <body>
  43. <main class="container">
  44. <h1>Sukka Surge Ruleset Server</h1>
  45. <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>
  46. <p>Last Updated: ${date.toISOString()}</p>
  47. <hr>
  48. <br>
  49. <ul>
  50. ${urlList.sort().map(url => `
  51. <li><a href="${url}" target="_blank">${url}</a></li>
  52. `).join('')}
  53. </ul>
  54. </main>
  55. </body>
  56. </html>
  57. `
  58. }