@weborigami/origami 0.0.67-beta.2 → 0.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.68",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"typescript": "5.6.2"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@weborigami/async-tree": "0.0.
|
|
21
|
-
"@weborigami/language": "0.0.
|
|
22
|
-
"@weborigami/types": "0.0.
|
|
20
|
+
"@weborigami/async-tree": "0.0.68",
|
|
21
|
+
"@weborigami/language": "0.0.68",
|
|
22
|
+
"@weborigami/types": "0.0.68",
|
|
23
23
|
"exif-parser": "0.1.12",
|
|
24
24
|
"graphviz-wasm": "3.0.2",
|
|
25
25
|
"highlight.js": "11.10.0",
|
package/src/builtins/@crawl.js
CHANGED
|
@@ -63,13 +63,14 @@ export default async function crawl(treelike, baseHref) {
|
|
|
63
63
|
// Cache the value
|
|
64
64
|
if (value) {
|
|
65
65
|
addValueToObject(cache, keys, value);
|
|
66
|
-
} else if (keys) {
|
|
67
|
-
// A missing robots.txt isn't an error; anything else missing is.
|
|
68
|
-
const path = keys.join("/");
|
|
69
|
-
if (path !== "robots.txt") {
|
|
70
|
-
errors.push(path);
|
|
71
|
-
}
|
|
72
66
|
}
|
|
67
|
+
// else if (keys) {
|
|
68
|
+
// // A missing robots.txt isn't an error; anything else missing is.
|
|
69
|
+
// const path = keys.join("/");
|
|
70
|
+
// if (path !== "robots.txt") {
|
|
71
|
+
// errors.push(path);
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
73
74
|
|
|
74
75
|
// Add indirect resource functions to the resource tree. When requested,
|
|
75
76
|
// these functions will obtain the resource from the original site.
|
|
@@ -151,6 +152,11 @@ async function* crawlPaths(tree, baseUrl) {
|
|
|
151
152
|
// setting its entry in the dictionary to null.
|
|
152
153
|
const promisesForPaths = {};
|
|
153
154
|
|
|
155
|
+
// Keep track of which resources refer to which paths.
|
|
156
|
+
const mapResourceToPaths = {};
|
|
157
|
+
|
|
158
|
+
let errorPaths = [];
|
|
159
|
+
|
|
154
160
|
// Seed the promise dictionary with robots.txt and the root path.
|
|
155
161
|
const initialPaths = ["/robots.txt", "/"];
|
|
156
162
|
initialPaths.forEach((path) => {
|
|
@@ -174,6 +180,9 @@ async function* crawlPaths(tree, baseUrl) {
|
|
|
174
180
|
// Mark the promise for that result as resolved.
|
|
175
181
|
promisesForPaths[result.path] = null;
|
|
176
182
|
|
|
183
|
+
// Add the crawlable paths to the map.
|
|
184
|
+
mapResourceToPaths[result.path] = result.crawlablePaths;
|
|
185
|
+
|
|
177
186
|
// Add promises for crawlable paths in the result.
|
|
178
187
|
result.crawlablePaths.forEach((path) => {
|
|
179
188
|
// Only add a promise for this path if we don't already have one.
|
|
@@ -182,8 +191,35 @@ async function* crawlPaths(tree, baseUrl) {
|
|
|
182
191
|
}
|
|
183
192
|
});
|
|
184
193
|
|
|
194
|
+
// If there was no value, add this to the errors.
|
|
195
|
+
// A missing robots.txt isn't an error; anything else missing is.
|
|
196
|
+
if (result.value === null && result.path !== "/robots.txt") {
|
|
197
|
+
errorPaths.push(result.path);
|
|
198
|
+
}
|
|
199
|
+
|
|
185
200
|
yield result;
|
|
186
201
|
}
|
|
202
|
+
|
|
203
|
+
if (errorPaths.length > 0) {
|
|
204
|
+
// Create a map of the resources that refer to each error.
|
|
205
|
+
const errorsMap = {};
|
|
206
|
+
for (const resource in mapResourceToPaths) {
|
|
207
|
+
const paths = mapResourceToPaths[resource];
|
|
208
|
+
for (const path of paths) {
|
|
209
|
+
if (errorPaths.includes(path)) {
|
|
210
|
+
errorsMap[resource] ??= [];
|
|
211
|
+
errorsMap[resource].push(path);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const errorsJson = JSON.stringify(errorsMap, null, 2);
|
|
216
|
+
yield {
|
|
217
|
+
keys: ["crawl-errors.json"],
|
|
218
|
+
path: "crawl-errors.json",
|
|
219
|
+
resourcePaths: [],
|
|
220
|
+
value: errorsJson,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
187
223
|
}
|
|
188
224
|
|
|
189
225
|
// Filter the paths to those that are local to the site.
|
|
@@ -470,7 +506,12 @@ async function processPath(tree, path, baseUrl) {
|
|
|
470
506
|
}
|
|
471
507
|
|
|
472
508
|
// Convert path to keys
|
|
473
|
-
|
|
509
|
+
let keys = keysFromPath(path);
|
|
510
|
+
|
|
511
|
+
// Paths (including those created by the filterPaths function above) will have
|
|
512
|
+
// spaces, etc., escaped. In general, these need to be unescaped so we can
|
|
513
|
+
// find them in the tree.
|
|
514
|
+
keys = keys.map(decodeURIComponent);
|
|
474
515
|
|
|
475
516
|
// Traverse tree to get value.
|
|
476
517
|
let value = await Tree.traverse(tree, ...keys);
|
package/src/builtins/@shuffle.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
default as ShuffleTransform,
|
|
3
|
+
shuffle,
|
|
4
|
+
} from "../common/ShuffleTransform.js";
|
|
2
5
|
import { transformObject } from "../common/utilities.js";
|
|
3
6
|
import getTreeArgument from "../misc/getTreeArgument.js";
|
|
4
7
|
|
|
@@ -11,10 +14,21 @@ import getTreeArgument from "../misc/getTreeArgument.js";
|
|
|
11
14
|
* @this {AsyncTree|null}
|
|
12
15
|
* @param {Treelike} [treelike]
|
|
13
16
|
*/
|
|
14
|
-
export default async function
|
|
17
|
+
export default async function shuffleTree(treelike) {
|
|
18
|
+
// Special case: If the treelike is an array, shuffle it directly. Otherwise
|
|
19
|
+
// we'll end up shuffling the array's indexes, and if this is directly
|
|
20
|
+
// displayed by the ori CLI, this will end up creating a plain object. Even
|
|
21
|
+
// though this object will be created with the keys in the correct shuffled
|
|
22
|
+
// order, a JS object will always return numeric keys in numeric order --
|
|
23
|
+
// undoing the shuffle.
|
|
24
|
+
if (Array.isArray(treelike)) {
|
|
25
|
+
const array = treelike.slice();
|
|
26
|
+
shuffle(array);
|
|
27
|
+
return array;
|
|
28
|
+
}
|
|
15
29
|
const tree = await getTreeArgument(this, arguments, treelike, "@shuffle");
|
|
16
30
|
return transformObject(ShuffleTransform, tree);
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
shuffleTree.usage = `@shuffle <tree>\tReturn a new tree with the original's keys shuffled`;
|
|
34
|
+
shuffleTree.documentation = "https://weborigami.org/cli/builtins.html#shuffle";
|
|
@@ -18,7 +18,7 @@ export default function ShuffleTransform(Base) {
|
|
|
18
18
|
*
|
|
19
19
|
* Performs a Fisher-Yates shuffle. From http://sedition.com/perl/javascript-fy.html
|
|
20
20
|
*/
|
|
21
|
-
function shuffle(array) {
|
|
21
|
+
export function shuffle(array) {
|
|
22
22
|
let i = array.length;
|
|
23
23
|
while (--i >= 0) {
|
|
24
24
|
const j = Math.floor(Math.random() * (i + 1));
|