Sv443 пре 1 година
родитељ
комит
bb744b8ecf
4 измењених фајлова са 31 додато и 21 уклоњено
  1. 5 0
      .vscode/settings.json
  2. 4 4
      README.md
  3. 1 1
      assets/locales.json
  4. 21 16
      src/tools/gen-readme.ts

+ 5 - 0
.vscode/settings.json

@@ -29,6 +29,11 @@
       "color": "white",
       "overviewRulerColor": "#44f",
     },
+    "((<!--\\s*)?#\\{\\{/?[A-Z_-]+\\}\\}(\\s*-->)?)": { // #{{SECTION}} and #{{/SECTION}}
+      "overviewRulerColor": "#2ae",
+      "backgroundColor": "#2ae",
+      "color": "#002",
+    },
     "(#?(DEBUG|DBG)#?)": { // #DEBUG or DEBUG or #DBG or #DBG#
       "backgroundColor": "#ff0",
       "color": "blue",

+ 4 - 4
README.md

@@ -2,11 +2,11 @@
 <!-- #{{HEADER}} -->
 <h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
 
-### Lots of configurable layout and user experience improvements for YouTube Music
-Supported Languages: 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese
-
-[**Features**](#features) • [**Installation**](#installation) • [**Support**](#support) • [**Plugins**](#plugins) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
+### Configurable layout and user experience improvements for YouTube Music
+Supported Languages: 🇩🇪 German, 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese (simpl.)
 <!-- #{{/HEADER}} -->
+[**Features**](#features) • [**Installation**](#installation) • [**Support**](#support) • [**Plugins**](#plugins) • [**Development**](#development) • [**Attributions**](#attributions) • [**Disclaimers**](#disclaimers)
+  
 ---
 
 </div>

+ 1 - 1
assets/locales.json

@@ -57,7 +57,7 @@
   },
   "zh_CN": {
     "name": "中文(简化,中国)",
-    "nameEnglish": "Chinese (smpl.)",
+    "nameEnglish": "Chinese (simpl.)",
     "emoji": "🇨🇳",
     "userscriptDesc": "可配置的布局和YouTube Music的用户体验改进",
     "authors": ["Sv443"]

+ 21 - 16
src/tools/gen-readme.ts

@@ -1,10 +1,16 @@
 import { readFile, writeFile } from "node:fs/promises";
 import { join } from "node:path";
 import { fileURLToPath } from "node:url";
+import locales from "../../assets/locales.json" assert { type: "json" };
+import pkg from "../../package.json" assert { type: "json" };
 
 const readmePath = join(fileURLToPath(import.meta.url), "../../../README.md");
 const readmeSummaryPath = join(fileURLToPath(import.meta.url), "../../../README-summary.md");
 
+const changes = {
+  HEADER: genHeader,
+};
+
 async function run() {
   const readmeFiles = [
     {
@@ -20,11 +26,9 @@ async function run() {
   for(const { path, content } of readmeFiles) {
     console.info(`- Generating '${path}'`);
 
-    const result = await modifyReadme(content.split(/\r?\n/gm), {
-      HEADER: genHeader,
-    });
+    const result = await modifyReadme(content.split(/\r?\n/gm), changes);
 
-    await writeFile(readmePath, result);
+    await writeFile(path, result);
   }
 
   console.log("\n\x1b[32mReadme files generated successfully\x1b[0m\n");
@@ -33,9 +37,10 @@ async function run() {
 }
 
 async function modifyReadme(readmeLines: string[], changes: Record<string, () => Promise<string>>) {
+  const lines = [];
   for(const [name, getContent] of Object.entries(changes)) {
-    const beginRegex = new RegExp(`<!--\\s?#\\{\\{${name.toUpperCase()}\\}\\}\\s?-->`, "gm");
-    const endRegex = new RegExp(`<!--\\s?#\\{\\{/${name.toUpperCase()}\\}\\}\\s?-->`, "gm");
+    const beginRegex = new RegExp(`<!--\\s?#\\{\\{\\s?${name.toUpperCase()}\\s?\\}\\}\\s?-->`, "gm");
+    const endRegex = new RegExp(`<!--\\s?#\\{\\{\\s?/${name.toUpperCase()}\\s?\\}\\}\\s?-->`, "gm");
 
     // find line number that matches beginRegex
     const beginLine = readmeLines.findIndex((line) => beginRegex.test(line));
@@ -49,23 +54,23 @@ async function modifyReadme(readmeLines: string[], changes: Record<string, () =>
 
     // replace the content between the two lines
     const newContent = await getContent();
-    readmeLines = [
-      ...readmeLines.slice(0, beginLine + 1),
-      newContent,
-      ...readmeLines.slice(endLine),
-    ];
+    lines.push(...readmeLines.splice(0, beginLine + 1));
+    lines.push(...newContent.split(/\r?\n/gm));
+    lines.push(...readmeLines.splice(endLine - beginLine - 1));
   }
 
-  return readmeLines.join("\n");
+  return lines.length > 0 ? lines.join("\n") : readmeLines.join("\n");
 }
 
 async function genHeader() {
+  const langStr = Object.values(locales).reduce((acc, { nameEnglish, emoji }, i) => {
+    return `${acc}${i > 0 ? ", " : ""}${emoji} ${nameEnglish}`;
+  }, "");
   return `\
-<h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>BetterYTM</h1>
+<h1><img src="./assets/logo/logo_128.png" width="96" height="96" /><br>${pkg.userscriptName}</h1>
 
-Test
-### Lots of configurable layout and user experience improvements for YouTube Music
-Supported Languages: 🇺🇸 English, 🇩🇪 German, 🇪🇸 Spanish, 🇫🇷 French, 🇮🇳 Hindi, 🇯🇵 Japanese, 🇵🇹 Portuguese, 🇨🇳 Chinese
+### ${pkg.description}
+Supported Languages: ${langStr}\
 `;
 }