Skip to content

Commit 4b2b46d

Browse files
committed
Start of wiring up assets folder
1 parent c1d9cc5 commit 4b2b46d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

cli.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ let importer = new Importer();
108108
importer.setOutputFolder(output);
109109
importer.setCacheDuration(cacheduration);
110110
importer.setVerbose(!quiet);
111-
importer.setDraftsFolder("drafts");
112111
importer.setSafeMode(!overwrite);
113112
importer.setDryRun(dryrun);
114113
importer.addSource(type, target);
115114

115+
// TODO wire these up to CLI
116+
importer.setDraftsFolder("drafts");
117+
importer.setAssetsFolder("assets");
118+
116119
let entries = await importer.getEntries({
117120
contentType: format,
118121
});

src/Fetcher.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Fetcher {
4848

4949
#cacheDuration = "0s";
5050
#directoryManager;
51+
#assetsFolder = "assets";
5152

5253
constructor() {
5354
this.fetchedUrls = new Set();
@@ -73,6 +74,10 @@ class Fetcher {
7374
this.safeMode = Boolean(safeMode);
7475
}
7576

77+
setAssetsFolder(folder) {
78+
this.#assetsFolder = folder;
79+
}
80+
7681
getCounts() {
7782
return {
7883
assets: this.counts.assets,
@@ -88,18 +93,18 @@ class Fetcher {
8893
this.#directoryManager = manager;
8994
}
9095

91-
async fetchAsset(url, outputFolder, urlPath = "assets") {
96+
async fetchAsset(url, outputFolder) {
9297
// TODO move this upstream as a Fetch `alias` feature.
9398
return this.fetch(url, {
9499
type: "buffer",
95100
returnType: "response",
96101
},
97102
{
98103
verbose: true,
99-
showErrors: true
104+
showErrors: true,
100105
}).then(result => {
101106
let filename = Fetcher.getFilenameFromSrc(url, result.headers?.["content-type"]);
102-
let assetUrlLocation = path.join(urlPath, filename);
107+
let assetUrlLocation = path.join(this.#assetsFolder, filename);
103108
let fullOutputLocation = path.join(outputFolder, assetUrlLocation);
104109
let urlValue = `/${assetUrlLocation}`;
105110

src/Importer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { Fetcher } from "./Fetcher.js";
88
import { DirectoryManager } from "./DirectoryManager.js";
99
import { MarkdownToHtml } from "./MarkdownToHtml.js";
1010
import { HtmlTransformer } from "./HtmlTransformer.js";
11+
12+
// Data Sources
1113
import { YouTubeUser } from "./DataSource/YouTubeUser.js";
1214
import { Atom } from "./DataSource/Atom.js";
1315
import { Rss } from "./DataSource/Rss.js";
@@ -64,6 +66,10 @@ class Importer {
6466
}
6567
}
6668

69+
setAssetsFolder(folder) {
70+
this.fetcher.setAssetsFolder(folder);
71+
}
72+
6773
getCounts() {
6874
return {
6975
...this.counts,
@@ -171,7 +177,7 @@ class Importer {
171177

172178
let promises = await Promise.allSettled(entries.map(async entry => {
173179
if(Importer.isHtml(entry)) {
174-
entry.content = await this.htmlTransformer.transform(entry.content, entry.url);
180+
entry.content = await this.htmlTransformer.transform(entry.content);
175181

176182
if(options.contentType === "markdown") {
177183
entry.content = await this.markdownService.toMarkdown(entry.content, entry.url);
@@ -186,6 +192,7 @@ class Importer {
186192
}));
187193

188194
return promises.filter(entry => {
195+
// Documents with errors
189196
return entry.status !== "rejected";
190197
}).map(entry => {
191198
return entry.value;

0 commit comments

Comments
 (0)