Skip to content

Commit 049642c

Browse files
authored
Merge pull request #146 from bluecadet/fix/json-media
fix json media url, and update get-urls
2 parents fc10c76 + c203bda commit 049642c

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.changeset/shy-pears-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bluecadet/launchpad-content": patch
3+
---
4+
5+
Fix json content source media URL scraping

packages/content/lib/content-sources/json-source.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class JsonSource extends ContentSource {
5454
*/
5555
async _downloadJsons() {
5656
const result = new ContentResult();
57-
5857
for (const [path, url] of Object.entries(this.config.files)) {
5958
this.logger.debug(`Downloading json ${chalk.blue(url)}`);
6059
const response = await got(url);
@@ -74,7 +73,7 @@ class JsonSource extends ContentSource {
7473
for (const dataFile of result.dataFiles) {
7574
this.logger.debug(`Scraping for media files in ${chalk.blue(dataFile.localPath)}...`);
7675
const mediaUrls = JsonUtils.getUrls(dataFile.content, undefined, this.config.mediaPattern);
77-
this.logger.debug(`Found ${chalk.blue(mediaUrls.size)} media files in ${chalk.blue(dataFile.localPath)}`);
76+
this.logger.debug(`Found ${chalk.blue(mediaUrls.size.toString())} media files in ${chalk.blue(dataFile.localPath)}`);
7877
result.addMediaDownloads([...mediaUrls].map(url => new MediaDownload({ url })));
7978
}
8079
return result;

packages/content/lib/utils/json-utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class JsonUtils {
2222
}
2323

2424
const possibleUrls = getUrls(JSON.stringify(json), config);
25+
2526
for (const url of possibleUrls) {
2627
if (include && (include instanceof RegExp) && !url.match(include)) {
2728
continue; // url doesn't match include
@@ -35,15 +36,17 @@ class JsonUtils {
3536
}
3637

3738
/**
38-
* @param {any} [userSettings]
39+
* @param {import('get-urls').Options} [userSettings]
40+
* @returns {import('get-urls').Options}
3941
*/
4042
static getUrlOptions(userSettings) {
4143
return {
4244
...{
4345
stripAuthentication: false,
4446
stripWWW: false,
4547
removeTrailingSlash: false,
46-
sortQueryParameters: false
48+
sortQueryParameters: false,
49+
requireSchemeOrWww: true
4750
},
4851
...userSettings
4952
};

packages/content/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"contentful": "^9.0.0",
4646
"filenamify": "^5.1.1",
4747
"fs-extra": "^10.0.0",
48-
"get-urls": "^10.0.0",
48+
"get-urls": "^12.1.0",
4949
"got": "^12.3.0",
5050
"jsonpath": "^1.1.1",
5151
"markdown-it": "^12.2.0",
@@ -60,6 +60,7 @@
6060
"devDependencies": {
6161
"@types/cli-progress": "^3.11.0",
6262
"@types/jsonpath": "^0.2.0",
63+
"@types/markdown-it": "^12.2.0",
6364
"@types/progress-stream": "^2.0.2",
6465
"@types/qs": "^6.9.7",
6566
"@types/rimraf": "^4.0.5",

0 commit comments

Comments
 (0)