fixed path separator on multi-system
This commit is contained in:
+5
-3
@@ -1,6 +1,8 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const joinUrl = (...paths) => path.join(...paths).replace(/\\/g,'/');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all files path inside a given folder path
|
* Get all files path inside a given folder path
|
||||||
* @param dir
|
* @param dir
|
||||||
@@ -78,7 +80,7 @@ module.exports = (config) => {
|
|||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
paths.forEach((p) => {
|
paths.forEach((p) => {
|
||||||
const article = {
|
const article = {
|
||||||
path: path.join(p[0], p[1], p[2]),
|
path: joinUrl(p[0], p[1], p[2]),
|
||||||
realPath: path.join(config['data_dir'], p[0], p[1], p[2]),
|
realPath: path.join(config['data_dir'], p[0], p[1], p[2]),
|
||||||
year: parseInt(p[0]),
|
year: parseInt(p[0]),
|
||||||
month: parseInt(p[1]),
|
month: parseInt(p[1]),
|
||||||
@@ -91,9 +93,9 @@ module.exports = (config) => {
|
|||||||
if (err)
|
if (err)
|
||||||
return cb(err);
|
return cb(err);
|
||||||
article.title = info.title || config['article']['default_title'];
|
article.title = info.title || config['article']['default_title'];
|
||||||
article.thumbnail = info.thumbnail ? path.join(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
article.thumbnail = info.thumbnail ? joinUrl(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
||||||
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
||||||
article.url = '/' + path.join(article.path, article.escapedTitle) + '/';
|
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
||||||
articles[article.path] = article;
|
articles[article.path] = article;
|
||||||
remaining--;
|
remaining--;
|
||||||
if (remaining === 0)
|
if (remaining === 0)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const utils = require('./test_utils');
|
|||||||
const dataDir = 'test_data';
|
const dataDir = 'test_data';
|
||||||
const testIndex = 'testindex.md';
|
const testIndex = 'testindex.md';
|
||||||
|
|
||||||
|
const joinUrl = (...paths) => path.join(...paths).replace(/\\/g,'/');
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
'test': true,
|
'test': true,
|
||||||
'data_dir': dataDir,
|
'data_dir': dataDir,
|
||||||
@@ -226,8 +228,8 @@ describe('Test article fetching', () => {
|
|||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(dict).toBeDefined();
|
expect(dict).toBeDefined();
|
||||||
expect(Object.keys(dict).length).toBe(1);
|
expect(Object.keys(dict).length).toBe(1);
|
||||||
expect(dict[path.join('2019', '05', '05')]).toEqual({
|
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
|
||||||
path: path.join('2019', '05', '05'),
|
path: joinUrl('2019', '05', '05'),
|
||||||
realPath: dir,
|
realPath: dir,
|
||||||
year: 2019,
|
year: 2019,
|
||||||
month: 5,
|
month: 5,
|
||||||
@@ -236,7 +238,7 @@ describe('Test article fetching', () => {
|
|||||||
title: 'Untitled',
|
title: 'Untitled',
|
||||||
thumbnail: 'default.png',
|
thumbnail: 'default.png',
|
||||||
escapedTitle: 'untitled',
|
escapedTitle: 'untitled',
|
||||||
url: '/' + path.join('2019', '05', '05', 'untitled') + '/',
|
url: '/' + joinUrl('2019', '05', '05', 'untitled') + '/',
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -256,17 +258,17 @@ describe('Test article fetching', () => {
|
|||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(dict).toBeDefined();
|
expect(dict).toBeDefined();
|
||||||
expect(Object.keys(dict).length).toBe(1);
|
expect(Object.keys(dict).length).toBe(1);
|
||||||
expect(dict[path.join('2019', '05', '05')]).toEqual({
|
expect(dict[joinUrl('2019', '05', '05')]).toEqual({
|
||||||
path: path.join('2019', '05', '05'),
|
path: joinUrl('2019', '05', '05'),
|
||||||
realPath: dir,
|
realPath: dir,
|
||||||
year: 2019,
|
year: 2019,
|
||||||
month: 5,
|
month: 5,
|
||||||
day: 5,
|
day: 5,
|
||||||
date: date,
|
date: date,
|
||||||
title: 'Title with : info !',
|
title: 'Title with : info !',
|
||||||
thumbnail: path.join('2019', '05', '05', './thumbnail.jpg'),
|
thumbnail: joinUrl('2019', '05', '05', './thumbnail.jpg'),
|
||||||
escapedTitle: 'title_with___info',
|
escapedTitle: 'title_with___info',
|
||||||
url: '/' + path.join('2019', '05', '05', 'title_with___info') + '/',
|
url: '/' + joinUrl('2019', '05', '05', 'title_with___info') + '/',
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user