@sillsdev/docu-notion 0.14.0-alpha.11 → 0.14.0-alpha.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/README.md +9 -0
- package/dist/MakeImagePersistencePlan.js +25 -22
- package/dist/images.js +8 -5
- package/dist/makeImagePersistencePlan.spec.js +10 -0
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -148,3 +148,12 @@ To map Notion callouts to Docusaurus admonitions, ensure the icon is for the typ
|
|
|
148
148
|
- 🔥➜ danger
|
|
149
149
|
|
|
150
150
|
The default admonition type, if no matching icon is found, is "note".
|
|
151
|
+
|
|
152
|
+
# Known Workarounds
|
|
153
|
+
|
|
154
|
+
### Start a numbered list at a number other than 1
|
|
155
|
+
In Notion, make sure the block is "Text," not "Numbered List".
|
|
156
|
+
- But make sure the number does NOT have a space in front of it. This can/will cause issues with sub-list items.
|
|
157
|
+
- One way to get Notion to let you do this:
|
|
158
|
+
- Create a numbered list item where the text duplicates the number you want. Convert that numbered list item to "Text."
|
|
159
|
+
- i.e. Type "1. 1. Item one." Notion makes the first "1." into a number in a list. When you convert back to "Text," you're left with plain text "1. Item one."
|
|
@@ -29,33 +29,36 @@ const log_1 = require("./log");
|
|
|
29
29
|
const process_1 = require("process");
|
|
30
30
|
function makeImagePersistencePlan(imageSet, imageOutputRootPath, imagePrefix) {
|
|
31
31
|
var _a, _b;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const urlBeforeQuery = imageSet.primaryUrl.split("?")[0];
|
|
40
|
-
const thingToHash = (_b = findLastUuid(urlBeforeQuery)) !== null && _b !== void 0 ? _b : urlBeforeQuery;
|
|
41
|
-
const hash = hashOfString(thingToHash);
|
|
42
|
-
imageSet.outputFileName = `${hash}.${imageSet.fileType.ext}`;
|
|
43
|
-
imageSet.primaryFileOutputPath = Path.posix.join((imageOutputRootPath === null || imageOutputRootPath === void 0 ? void 0 : imageOutputRootPath.length) > 0
|
|
44
|
-
? imageOutputRootPath
|
|
45
|
-
: imageSet.pathToParentDocument, imageSet.outputFileName);
|
|
46
|
-
if (imageOutputRootPath && imageSet.localizedUrls.length) {
|
|
47
|
-
(0, log_1.error)("imageOutputPath was declared, but one or more localizedUrls were found too. If you are going to localize screenshots, then you can't declare an imageOutputPath.");
|
|
32
|
+
const urlBeforeQuery = imageSet.primaryUrl.split("?")[0];
|
|
33
|
+
let imageFileExtension = (_a = imageSet.fileType) === null || _a === void 0 ? void 0 : _a.ext;
|
|
34
|
+
if (!imageFileExtension) {
|
|
35
|
+
// Try to get the extension from the url
|
|
36
|
+
imageFileExtension = urlBeforeQuery.split(".").pop();
|
|
37
|
+
if (!imageFileExtension) {
|
|
38
|
+
(0, log_1.error)(`Something wrong with the filetype extension on the blob we got from ${imageSet.primaryUrl}`);
|
|
48
39
|
(0, process_1.exit)(1);
|
|
49
40
|
}
|
|
50
|
-
imageSet.filePathToUseInMarkdown =
|
|
51
|
-
((imagePrefix === null || imagePrefix === void 0 ? void 0 : imagePrefix.length) > 0 ? imagePrefix : ".") +
|
|
52
|
-
"/" +
|
|
53
|
-
imageSet.outputFileName;
|
|
54
41
|
}
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
// Since most images come from pasting screenshots, there isn't normally a filename. That's fine, we just make a hash of the url
|
|
43
|
+
// Images that are stored by notion come to us with a complex url that changes over time, so we pick out the UUID that doesn't change. Example:
|
|
44
|
+
// https://s3.us-west-2.amazonaws.com/secure.notion-static.com/d1058f46-4d2f-4292-8388-4ad393383439/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220516%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220516T233630Z&X-Amz-Expires=3600&X-Amz-Signature=f215704094fcc884d37073b0b108cf6d1c9da9b7d57a898da38bc30c30b4c4b5&X-Amz-SignedHeaders=host&x-id=GetObject
|
|
45
|
+
// But around Sept 2023, they changed the url to be something like:
|
|
46
|
+
// https://prod-files-secure.s3.us-west-2.amazonaws.com/d9a2b712-cf69-4bd6-9d65-87a4ceeacca2/d1bcdc8c-b065-4e40-9a11-392aabeb220e/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230915%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230915T161258Z&X-Amz-Expires=3600&X-Amz-Signature=28fca48e65fba86d539c3c4b7676fce1fa0857aa194f7b33dd4a468ecca6ab24&X-Amz-SignedHeaders=host&x-id=GetObject
|
|
47
|
+
// The thing we want is the last UUID before the ?
|
|
48
|
+
const thingToHash = (_b = findLastUuid(urlBeforeQuery)) !== null && _b !== void 0 ? _b : urlBeforeQuery;
|
|
49
|
+
const hash = hashOfString(thingToHash);
|
|
50
|
+
imageSet.outputFileName = `${hash}.${imageFileExtension}`;
|
|
51
|
+
imageSet.primaryFileOutputPath = Path.posix.join((imageOutputRootPath === null || imageOutputRootPath === void 0 ? void 0 : imageOutputRootPath.length) > 0
|
|
52
|
+
? imageOutputRootPath
|
|
53
|
+
: imageSet.pathToParentDocument, imageSet.outputFileName);
|
|
54
|
+
if (imageOutputRootPath && imageSet.localizedUrls.length) {
|
|
55
|
+
(0, log_1.error)("imageOutputPath was declared, but one or more localizedUrls were found too. If you are going to localize screenshots, then you can't declare an imageOutputPath.");
|
|
57
56
|
(0, process_1.exit)(1);
|
|
58
57
|
}
|
|
58
|
+
imageSet.filePathToUseInMarkdown =
|
|
59
|
+
((imagePrefix === null || imagePrefix === void 0 ? void 0 : imagePrefix.length) > 0 ? imagePrefix : ".") +
|
|
60
|
+
"/" +
|
|
61
|
+
imageSet.outputFileName;
|
|
59
62
|
}
|
|
60
63
|
exports.makeImagePersistencePlan = makeImagePersistencePlan;
|
|
61
64
|
function findLastUuid(url) {
|
package/dist/images.js
CHANGED
|
@@ -38,7 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
38
|
exports.cleanupOldImages = exports.parseImageBlock = exports.markdownToMDImageTransformer = exports.standardImageTransformer = exports.initImageHandling = void 0;
|
|
39
39
|
const fs = __importStar(require("fs-extra"));
|
|
40
40
|
const file_type_1 = __importDefault(require("file-type"));
|
|
41
|
-
const
|
|
41
|
+
const axios_1 = __importDefault(require("axios"));
|
|
42
42
|
const Path = __importStar(require("path"));
|
|
43
43
|
const MakeImagePersistencePlan_1 = require("./MakeImagePersistencePlan");
|
|
44
44
|
const log_1 = require("./log");
|
|
@@ -131,9 +131,12 @@ function processImageBlock(imageBlock, pathToParentDocument, relativePathToThisP
|
|
|
131
131
|
}
|
|
132
132
|
function readPrimaryImage(imageSet) {
|
|
133
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
// In Mar 2024, we started having a problem getting a particular gif from imgur using
|
|
135
|
+
// node-fetch. Switching to axios resolved it. I don't know why.
|
|
136
|
+
const response = yield axios_1.default.get(imageSet.primaryUrl, {
|
|
137
|
+
responseType: "arraybuffer",
|
|
138
|
+
});
|
|
139
|
+
imageSet.primaryBuffer = Buffer.from(response.data, "utf-8");
|
|
137
140
|
imageSet.fileType = yield file_type_1.default.fromBuffer(imageSet.primaryBuffer);
|
|
138
141
|
});
|
|
139
142
|
}
|
|
@@ -145,7 +148,7 @@ function saveImage(imageSet) {
|
|
|
145
148
|
// if we have a urls for the localized screenshot, download it
|
|
146
149
|
if ((localizedImage === null || localizedImage === void 0 ? void 0 : localizedImage.url.length) > 0) {
|
|
147
150
|
(0, log_1.verbose)(`Retrieving ${localizedImage.iso632Code} version...`);
|
|
148
|
-
const response = yield (
|
|
151
|
+
const response = yield fetch(localizedImage.url);
|
|
149
152
|
const arrayBuffer = yield response.arrayBuffer();
|
|
150
153
|
buffer = Buffer.from(arrayBuffer);
|
|
151
154
|
}
|
|
@@ -28,6 +28,16 @@ test("primary file with defaults for image output path and prefix", () => {
|
|
|
28
28
|
expect(imageSet.primaryFileOutputPath).toBe(`/pathToParentSomewhere/${expectedHash}.png`);
|
|
29
29
|
expect(imageSet.filePathToUseInMarkdown).toBe(`./${expectedHash}.png`);
|
|
30
30
|
});
|
|
31
|
+
test("falls back to getting file extension from url if not in fileType", () => {
|
|
32
|
+
const imageSet = {
|
|
33
|
+
primaryUrl: "https://s3.us-west-2.amazonaws.com/primaryImage.png",
|
|
34
|
+
localizedUrls: [],
|
|
35
|
+
pathToParentDocument: "/pathToParentSomewhere/",
|
|
36
|
+
};
|
|
37
|
+
(0, MakeImagePersistencePlan_1.makeImagePersistencePlan)(imageSet, "", "");
|
|
38
|
+
const expectedHash = (0, MakeImagePersistencePlan_1.hashOfString)("https://s3.us-west-2.amazonaws.com/primaryImage.png");
|
|
39
|
+
expect(imageSet.outputFileName).toBe(`${expectedHash}.png`);
|
|
40
|
+
});
|
|
31
41
|
test("properly extract UUID from old-style notion image url", () => {
|
|
32
42
|
const imageSet = {
|
|
33
43
|
primaryUrl: "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/e1058f46-4d2f-4292-8388-4ad393383439/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220516%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220516T233630Z&X-Amz-Expires=3600&X-Amz-Signature=f215704094fcc884d37073b0b108cf6d1c9da9b7d57a898da38bc30c30b4c4b5&X-Amz-SignedHeaders=host&x-id=GetObject",
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"tsc": "tsc",
|
|
13
13
|
"// test out with a private sample notion db": "",
|
|
14
14
|
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr --log-level debug",
|
|
15
|
-
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level
|
|
15
|
+
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level info --status-tag test",
|
|
16
16
|
"pull-test-css": "npm run ts -- --css-output-directory ./test/css -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
|
|
17
17
|
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
|
|
18
18
|
"// test with a semi-stable/public site:": "",
|
|
@@ -20,26 +20,25 @@
|
|
|
20
20
|
"pull-sample-with-paths": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --img-output-path ./sample_img"
|
|
21
21
|
},
|
|
22
22
|
"//file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
|
|
23
|
-
"//node-fetch@2.6.6file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
|
|
24
23
|
"//chalk@4": "also ESM related problem",
|
|
25
24
|
"//notion-client@4": "also ESM related problem",
|
|
26
25
|
"//note: ts-node": "really is a runtime dependency",
|
|
27
26
|
"dependencies": {
|
|
28
27
|
"@notionhq/client": "2.2.3",
|
|
28
|
+
"axios": "^1.6.8",
|
|
29
29
|
"chalk": "^4.1.2",
|
|
30
30
|
"commander": "^9.2.0",
|
|
31
31
|
"cosmiconfig": "^8.0.0",
|
|
32
32
|
"cosmiconfig-typescript-loader": "^4.3.0",
|
|
33
|
-
"file-type": "16.5.
|
|
33
|
+
"file-type": "16.5.3",
|
|
34
34
|
"fs-extra": "^10.1.0",
|
|
35
35
|
"limiter": "^2.1.0",
|
|
36
36
|
"markdown-table": "^2.0.0",
|
|
37
|
-
"node-fetch": "2.6.6",
|
|
38
37
|
"notion-client": "^4",
|
|
39
38
|
"notion-to-md": "3.1.1",
|
|
40
39
|
"path": "^0.12.7",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
40
|
+
"sanitize-filename": "^1.6.3",
|
|
41
|
+
"ts-node": "^10.2.1"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -91,5 +90,5 @@
|
|
|
91
90
|
"volta": {
|
|
92
91
|
"node": "18.16.0"
|
|
93
92
|
},
|
|
94
|
-
"version": "0.14.0-alpha.
|
|
93
|
+
"version": "0.14.0-alpha.13"
|
|
95
94
|
}
|