@rr0/cms 0.1.11 → 0.1.13
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/dist/book/index.d.ts +0 -1
- package/dist/book/index.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/dist/WordFinder.d.ts +0 -1
- package/dist/WordFinder.js +0 -89
- package/dist/book/BookImport.d.ts +0 -1
- package/dist/book/BookImport.js +0 -27
package/dist/book/index.d.ts
CHANGED
package/dist/book/index.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
package/dist/WordFinder.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/WordFinder.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ConsoleLogger, HtmlFileContents } from "ssg-api";
|
|
2
|
-
import { CLI } from "./util/index.js";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import { TimeContext } from "./time/index.js";
|
|
5
|
-
import { RR0SsgContextImpl } from "./RR0SsgContext.js";
|
|
6
|
-
import { glob } from "glob";
|
|
7
|
-
import path from "path";
|
|
8
|
-
import { CSVFileReader } from "./CSVFileReader.js";
|
|
9
|
-
const logger = new ConsoleLogger("wordfinder");
|
|
10
|
-
const args = new CLI().getArgs();
|
|
11
|
-
const inputPattern = args.contents;
|
|
12
|
-
const dictionaryFile = args.dict;
|
|
13
|
-
class Dictionary {
|
|
14
|
-
constructor(logger) {
|
|
15
|
-
this.logger = logger;
|
|
16
|
-
this.words = [];
|
|
17
|
-
}
|
|
18
|
-
async read(fileName) {
|
|
19
|
-
logger.debug("Reading", fileName);
|
|
20
|
-
const columns = [];
|
|
21
|
-
const readStream = fs.createReadStream(fileName);
|
|
22
|
-
const csvSeparator = ",";
|
|
23
|
-
const reader = new CSVFileReader(readStream, logger, columns, csvSeparator, (data) => data["&"]);
|
|
24
|
-
this.words = ["&"].concat(await reader.read());
|
|
25
|
-
return this.words;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const outDir = "out";
|
|
29
|
-
const config = {
|
|
30
|
-
getOutputPath(context) {
|
|
31
|
-
return path.join(outDir, context.file.name);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const timeContext = new TimeContext();
|
|
35
|
-
const context = new RR0SsgContextImpl("fr", timeContext, config);
|
|
36
|
-
glob(inputPattern).then(async (inputFiles) => {
|
|
37
|
-
const dictionary = new Dictionary(logger);
|
|
38
|
-
const dictWords = await dictionary.read(dictionaryFile);
|
|
39
|
-
logger.debug("Looking for files", inputPattern);
|
|
40
|
-
for (const inputFile of inputFiles) {
|
|
41
|
-
const file = HtmlFileContents.read(inputFile);
|
|
42
|
-
const contents = file.contents;
|
|
43
|
-
let pos;
|
|
44
|
-
let errorToFix;
|
|
45
|
-
const separators = " ;:.,!?()[]/+=";
|
|
46
|
-
const badChar = "�";
|
|
47
|
-
do {
|
|
48
|
-
pos = contents.indexOf(badChar);
|
|
49
|
-
errorToFix = pos >= 0;
|
|
50
|
-
let fileWordStart = pos;
|
|
51
|
-
if (errorToFix) {
|
|
52
|
-
while (fileWordStart > 0 && !separators.includes(contents.charAt(fileWordStart))) {
|
|
53
|
-
fileWordStart--;
|
|
54
|
-
}
|
|
55
|
-
let fileWordEnd = fileWordStart + 1;
|
|
56
|
-
while (!separators.includes(contents.charAt(fileWordEnd))) {
|
|
57
|
-
fileWordEnd++;
|
|
58
|
-
}
|
|
59
|
-
const wordToFix = contents.substring(fileWordStart, fileWordEnd);
|
|
60
|
-
context.log("Fixing", wordToFix);
|
|
61
|
-
let dictWordIndex = 0;
|
|
62
|
-
let score;
|
|
63
|
-
do {
|
|
64
|
-
const dictWord = dictWords[dictWordIndex];
|
|
65
|
-
let matchStart = 0;
|
|
66
|
-
score = 0;
|
|
67
|
-
for (let i = 0; i < dictWord.length; i++, matchStart++) {
|
|
68
|
-
const dictWordChar = dictWord.charAt(i);
|
|
69
|
-
const fileWordChar = contents.charAt(pos + matchStart);
|
|
70
|
-
if (fileWordChar === badChar) {
|
|
71
|
-
score += 5;
|
|
72
|
-
}
|
|
73
|
-
else if (fileWordChar === dictWordChar) {
|
|
74
|
-
score += 10;
|
|
75
|
-
}
|
|
76
|
-
else if (separators.includes(fileWordChar)) {
|
|
77
|
-
context.log("Found word", dictWord);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
context.debug("Not word", dictWord);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
dictWordIndex++;
|
|
85
|
-
} while (score < 10 && dictWordIndex < dictWords.length);
|
|
86
|
-
}
|
|
87
|
-
} while (errorToFix);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/book/BookImport.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ConsoleLogger } from "ssg-api";
|
|
2
|
-
import { CLI } from "../util/cli/CLI.js";
|
|
3
|
-
import { BookService } from "./BookService.js";
|
|
4
|
-
import { PeopleService } from "../people/PeopleService.js";
|
|
5
|
-
import { AllDataService } from "../data/AllDataService.js";
|
|
6
|
-
import { PeopleFactory } from "../people/PeopleFactory.js";
|
|
7
|
-
import { RR0EventFactory } from "../event/RR0EventFactory.js";
|
|
8
|
-
import { TypedDataFactory } from "../data/TypedDataFactory.js";
|
|
9
|
-
import path from "path";
|
|
10
|
-
const logger = new ConsoleLogger("rr0-books");
|
|
11
|
-
const args = new CLI().getArgs();
|
|
12
|
-
const fileName = args.import;
|
|
13
|
-
const dry = args.dry === "true";
|
|
14
|
-
const peopleFactory = new PeopleFactory(new RR0EventFactory());
|
|
15
|
-
const eventFactory = new RR0EventFactory();
|
|
16
|
-
const bookFactory = new TypedDataFactory(eventFactory, "book");
|
|
17
|
-
const dataService = new AllDataService([bookFactory, peopleFactory]);
|
|
18
|
-
const outDir = "out";
|
|
19
|
-
const config = {
|
|
20
|
-
getOutputPath(context) {
|
|
21
|
-
return path.join(outDir, context.file.name);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const books = new BookService(logger, dry, new PeopleService(dataService, peopleFactory), config);
|
|
25
|
-
books.import(fileName).then((result) => {
|
|
26
|
-
logger.log("Wrote", result.length, "books");
|
|
27
|
-
});
|