diff --git a/index.js b/index.js index ae7fe1e..6282629 100644 --- a/index.js +++ b/index.js @@ -47,19 +47,22 @@ module.exports = src => { const $tds = $(tr).find('td'); const getCol = label => fieldCols[label] === undefined ? null : $tds.eq(fieldCols[label]); const getColText = label => getCol(label) && getCol(label).text().trim(); - - const path = getCol('Name').children().eq(0).attr('href'); const name = getColText('Name'); // Ignore 'Parent Directory' row if (name === 'Parent Directory' || !name) return; + let path = getCol('Name').children().eq(0).attr('href'); + if (!path.startsWith('http://') && !path.startsWith('https://')) { + path = join(dir, path); + } + files.push({ type: path.endsWith('/') ? 'directory' : 'file', name: name, - path: join(dir, path), + path: path, lastModified: getCol('Last modified') && new Date(getColText('Last modified')), size: getCol('Size') && bytes(getColText('Size')), description: getColText('Description') diff --git a/test/fixture/apache-index-absolute-and-relative-urls.html b/test/fixture/apache-index-absolute-and-relative-urls.html new file mode 100644 index 0000000..dc5d39f --- /dev/null +++ b/test/fixture/apache-index-absolute-and-relative-urls.html @@ -0,0 +1,48 @@ + +
+Name | +Last modified | +Size | +Description | +
---|---|---|---|
Parent Directory | +|||
subdir-absolute/ | +Wed Jun 30 22:24:50 UTC 2021 | ++ | + |
subdir-relative/ | +Wed Jun 30 22:24:50 UTC 2021 | ++ | + |
subfile-absolute.xml | +Sun Jul 04 16:22:15 UTC 2021 | ++ 25 + | ++ |
subfile-relative.xml | +Sun Jul 04 16:22:15 UTC 2021 | ++ 25 + | ++ |