Skip to content

Commit

Permalink
Fix #10
Browse files Browse the repository at this point in the history
Looks for a matching file for the first cell on each line of a CSV then creates a link
  • Loading branch information
connertennery committed Oct 29, 2020
1 parent 97f45bc commit 24b9abb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ const convertRelativePath = (path) => {
return `[[${path.split('/').pop().split('%20').slice(0, -1).join(' ')}]]`;
};

const correctCSVLinks = (content) => {
const correctCSVLinks = (content, csvDirectory) => {
//* ../Relative%20Path/To/File%20Name.md => [[File Name]]
const csvFiles = csvDirectory.map((x) =>
x.name.substring(0, x.name.lastIndexOf(' '))
);
let lines = content.split('\n');
let links = 0;
for (let x = 0; x < lines.length; x++) {
Expand All @@ -134,6 +137,9 @@ const correctCSVLinks = (content) => {
if (cell.includes('.md')) {
cells[y] = convertRelativePath(cell);
links++;
} else if (y === 0 && csvFiles.includes(cell)) {
cells[y] = `[[${cell}]]`;
links++;
}
}
lines[x] = cells.join(',');
Expand Down Expand Up @@ -191,8 +197,15 @@ const fixNotionExport = function (path) {
markdownLinks += correctedFileContents.links;
fs.writeFileSync(file, correctedFileContents.content, 'utf8');
} else if (npath.extname(file) === '.csv') {
const csvDirectory = fs.readdirSync(
directories.find((x) =>
x.includes(file.substring(0, file.lastIndexOf('.')))
),
{ withFileTypes: true }
);
const correctedFileContents = correctCSVLinks(
fs.readFileSync(file, 'utf8')
fs.readFileSync(file, 'utf8'),
csvDirectory
);
const csvConverted = convertCSVToMarkdown(
correctedFileContents.content
Expand Down

1 comment on commit 24b9abb

@connertennery
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused #12

Please sign in to comment.