Ver código fonte

move recipes to module

raylu 1 mês atrás
pai
commit
460ee13cab
7 arquivos alterados com 53 adições e 20 exclusões
  1. 5 3
      dist/recipes.js
  2. 1 1
      dist/recipes.js.map
  3. 3 14
      index.html
  4. 1 1
      package.json
  5. 27 0
      recipes.html
  6. 3 1
      src/recipes.ts
  7. 13 0
      styles.css

+ 5 - 3
dist/main.js → dist/recipes.js

@@ -1,4 +1,4 @@
-// src/main.ts
+// src/recipes.ts
 async function fetchData() {
   const [buildingsResponse, recipesResponse, exchangesResponse] = await Promise.all([
     fetch("https://api.prunplanner.org/data/buildings"),
@@ -75,6 +75,8 @@ function render({ buildings, recipes, prices }) {
     tbody.appendChild(row);
   }
 }
-fetchData().then(render);
+if (document.querySelector("tbody")) {
+  fetchData().then(render);
+}
 
-//# debugId=5C43254EC8D8A7F364756E2164756E21
+//# debugId=AA0BA8B70839899464756E2164756E21

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
dist/recipes.js.map


+ 3 - 14
index.html

@@ -3,24 +3,13 @@
 <head>
 	<meta charset="UTF-8">
 	<meta name="viewport" content="width=device-width, initial-scale=1.0">
-	<title>PrUn calculator</title>
+	<title>PrUn calc</title>
 	<link rel="stylesheet" href="styles.css">
 </head>
 <body>
 	<main>
-		<table>
-			<thead>
-				<tr>
-					<th>recipe</th>
-					<th>daily profit</th>
-					<th>volume</th>
-					<th>traded</th>
-					<th>building cost</th>
-				</tr>
-			</thead>
-			<tbody></tbody>
-		</table>
+		<h1>PrUn Calculator</h1>
+		<a href="recipes.html">recipes</a>
 	</main>
-	<script type="module" src="./dist/main.js"></script>
 </body>
 </html>

+ 1 - 1
package.json

@@ -3,7 +3,7 @@
   "version": "1.0.0",
   "description": "GitHub Pages site with TypeScript",
   "scripts": {
-    "build": "bun build src/main.ts --outdir dist --target browser --sourcemap=external",
+    "build": "bun build src/recipes.ts --outdir dist --target browser --sourcemap=external",
     "typecheck": "tsc --noEmit",
     "serve": "python3 -m http.server 8000"
   },

+ 27 - 0
recipes.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<meta name="viewport" content="width=device-width, initial-scale=1.0">
+	<title>PrUn calc — recipes</title>
+	<link rel="stylesheet" href="styles.css">
+</head>
+<body>
+	<main>
+		<a href="index.html">back</a>
+		<table>
+			<thead>
+				<tr>
+					<th>recipe</th>
+					<th>daily profit</th>
+					<th>volume</th>
+					<th>traded</th>
+					<th>building cost</th>
+				</tr>
+			</thead>
+			<tbody></tbody>
+		</table>
+	</main>
+	<script type="module" src="./dist/recipes.js"></script>
+</body>
+</html>

+ 3 - 1
src/main.ts → src/recipes.ts

@@ -109,4 +109,6 @@ function render({buildings, recipes, prices}: {buildings: Building[], recipes: R
 	}
 }
 
-fetchData().then(render);
+if (document.querySelector('tbody')) {
+	fetchData().then(render);
+}

+ 13 - 0
styles.css

@@ -16,10 +16,23 @@ main {
     background: #111;
 }
 
+h1 {
+    margin: 0 0 1em;
+}
+
+a {
+    color: #0af;
+}
+
 td {
     text-align: right;
     padding: 0.25em 1em;
 }
 td:first-child {
     text-align: inherit;
+    padding-left: 0;
+}
+td:last-child {
+    padding-right: 0;
 }
+

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff