Skip to content

Commit

Permalink
Start of wiring up assets folder
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 13, 2024
1 parent c1d9cc5 commit 4b2b46d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ let importer = new Importer();
importer.setOutputFolder(output);
importer.setCacheDuration(cacheduration);
importer.setVerbose(!quiet);
importer.setDraftsFolder("drafts");
importer.setSafeMode(!overwrite);
importer.setDryRun(dryrun);
importer.addSource(type, target);

// TODO wire these up to CLI
importer.setDraftsFolder("drafts");
importer.setAssetsFolder("assets");

let entries = await importer.getEntries({
contentType: format,
});
Expand Down
11 changes: 8 additions & 3 deletions src/Fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Fetcher {

#cacheDuration = "0s";
#directoryManager;
#assetsFolder = "assets";

constructor() {
this.fetchedUrls = new Set();
Expand All @@ -73,6 +74,10 @@ class Fetcher {
this.safeMode = Boolean(safeMode);
}

setAssetsFolder(folder) {
this.#assetsFolder = folder;
}

getCounts() {
return {
assets: this.counts.assets,
Expand All @@ -88,18 +93,18 @@ class Fetcher {
this.#directoryManager = manager;
}

async fetchAsset(url, outputFolder, urlPath = "assets") {
async fetchAsset(url, outputFolder) {
// TODO move this upstream as a Fetch `alias` feature.
return this.fetch(url, {
type: "buffer",
returnType: "response",
},
{
verbose: true,
showErrors: true
showErrors: true,
}).then(result => {
let filename = Fetcher.getFilenameFromSrc(url, result.headers?.["content-type"]);
let assetUrlLocation = path.join(urlPath, filename);
let assetUrlLocation = path.join(this.#assetsFolder, filename);
let fullOutputLocation = path.join(outputFolder, assetUrlLocation);
let urlValue = `/${assetUrlLocation}`;

Expand Down
9 changes: 8 additions & 1 deletion src/Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Fetcher } from "./Fetcher.js";
import { DirectoryManager } from "./DirectoryManager.js";
import { MarkdownToHtml } from "./MarkdownToHtml.js";
import { HtmlTransformer } from "./HtmlTransformer.js";

// Data Sources
import { YouTubeUser } from "./DataSource/YouTubeUser.js";
import { Atom } from "./DataSource/Atom.js";
import { Rss } from "./DataSource/Rss.js";
Expand Down Expand Up @@ -64,6 +66,10 @@ class Importer {
}
}

setAssetsFolder(folder) {
this.fetcher.setAssetsFolder(folder);
}

getCounts() {
return {
...this.counts,
Expand Down Expand Up @@ -171,7 +177,7 @@ class Importer {

let promises = await Promise.allSettled(entries.map(async entry => {
if(Importer.isHtml(entry)) {
entry.content = await this.htmlTransformer.transform(entry.content, entry.url);
entry.content = await this.htmlTransformer.transform(entry.content);

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

return promises.filter(entry => {
// Documents with errors
return entry.status !== "rejected";
}).map(entry => {
return entry.value;
Expand Down

0 comments on commit 4b2b46d

Please sign in to comment.