Skip to content

Commit 31277ef

Browse files
Fix cross-platform path handling in RSS feed generator
1 parent f5fa1e8 commit 31277ef

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/utils/rss.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const getAllFiles = function (dirPath, arrayOfFiles) {
1919
arrayOfFiles = arrayOfFiles || [];
2020

2121
files.forEach(function (file) {
22-
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
23-
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles);
22+
const fullPath = path.join(dirPath, file);
23+
if (fs.statSync(fullPath).isDirectory()) {
24+
arrayOfFiles = getAllFiles(fullPath, arrayOfFiles);
2425
} else {
25-
arrayOfFiles.push(path.join(dirPath, '/', file));
26+
arrayOfFiles.push(fullPath);
2627
}
2728
});
2829

@@ -51,7 +52,8 @@ exports.generateRssFeed = function () {
5152
if (id !== 'index.md') {
5253
const content = fs.readFileSync(filePath, 'utf-8');
5354
const {data} = matter(content);
54-
const slug = filePath.split('/').slice(-4).join('/').replace('.md', '');
55+
const relativePath = path.relative(dirPath, filePath).replace(/\\/g, '/');
56+
const slug = relativePath.replace(/\.md$/, '');
5557

5658
if (data.title == null || data.title.trim() === '') {
5759
throw new Error(

0 commit comments

Comments
 (0)