Skip to content

Commit

Permalink
Fix missing markdown file extensions bug (defaulted to html)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 20, 2024
1 parent 5954f33 commit 7fc638f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/DataSource/Rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class Rss extends DataSource {
}

getUniqueIdFromEntry(entry) {
// let id = entry.link || entry.guid["#text"];
let id = entry.guid["#text"];
return `${DataSource.UUID_PREFIX}::${Rss.TYPE}::${id}`;
return `${DataSource.UUID_PREFIX}::${Rss.TYPE}::${entry.guid["#text"]}`;
}

getHtmlFromMediaEntry(mediaSources) {
Expand Down
19 changes: 10 additions & 9 deletions src/Importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { WordPressApi } from "./DataSource/WordPressApi.js";
import { BlueskyUser } from "./DataSource/BlueskyUser.js";
import { FediverseUser } from "./DataSource/FediverseUser.js";


const require = createRequire(import.meta.url);
const pkg = require("../package.json");

Expand Down Expand Up @@ -190,7 +189,7 @@ class Importer {
}

static isHtml(entry) {
// TODO add a CLI option for --importContentType?
// TODO add a CLI override for --importContentType?
// TODO add another path to guess if content is HTML https://mimesniff.spec.whatwg.org/#identifying-a-resource-with-an-unknown-mime-type
return entry.contentType === "html";
}
Expand All @@ -199,7 +198,12 @@ class Importer {
let entries = [];
for(let source of this.sources) {
for(let entry of await source.getEntries()) {
entry.filePath = this.getFilePath(entry);
let contentType = entry.contentType;
if(Importer.isHtml(entry) && options.contentType === "markdown") {
contentType = "markdown";
}

entry.filePath = this.getFilePath(entry, contentType);

entries.push(entry);
}
Expand All @@ -215,13 +219,10 @@ class Importer {

if(options.contentType === "markdown") {
entry.content = await this.markdownService.toMarkdown(entry.content, entry.url);
entry.contentType = "markdown";
}
}

if(options.contentType) {
entry.contentType = options.contentType;
}

return entry;
}));

Expand All @@ -245,7 +246,7 @@ class Importer {
});
}

getFilePath(entry) {
getFilePath(entry, contentType) {
let { url } = entry;

let source = entry.source;
Expand Down Expand Up @@ -284,7 +285,7 @@ class Importer {
}

let pathname = path.join(".", ...subdirs, path.normalize(fallbackPath));
let extension = entry.contentType === "markdown" ? ".md" : ".html";
let extension = contentType === "markdown" ? ".md" : ".html";

if(pathname.endsWith("/")) {
return `${pathname.slice(0, -1)}${extension}`;
Expand Down

0 comments on commit 7fc638f

Please sign in to comment.