Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/unibit.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ module.exports = class Unibit {
const urlPathParts = _.split(urlPath, '/');
return _.filter(context.site.pages, page => {
// find all pages that have same prefix as folder path, but not the root page of that folder, e.g.: {urlPath}/index.html
let pageUrl = _.trim(_.get(page, 'url'), '/');
let pageUrl = _.trim(_.get(page, 'url'), path.sep);
pageUrl = prettyUrl(pageUrl);
const pageUrlParts = _.split(pageUrl, '/');
const pageUrlParts = _.split(pageUrl, path.sep);
Comment on lines +355 to +357
Copy link
Member

Choose a reason for hiding this comment

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

Here we are handling page URL paths. URLs always use forward slash disregards to the underlying system /.
On windows system, the path.sep will be \ so the logic will not work for URL paths

Copy link
Author

Choose a reason for hiding this comment

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

Here the path.sep is not about URL but rather about file routing/parsing.

On windows system, the page.url value prints \\blog\\author\\dianne-ameter.

  • When we try to remove the leading and trailing / character(s) with _.trim, nothing happens :
    • pageUrl contains \\blog\\author\\dianne-ameter instead of blog\\author\\dianne-ameter.
  • Then we split the url parts by the hardcoded /, so we get :
    • pageUrlParts = [ '\\blog\\author\\dianne-ameter' ] instead of ['blog', 'author', 'dianne-ameter'].

This causes the blog page to not list any blog posts and all subdirectory routes are skipped/broken.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting,
Then I guess the root cause of this bug is somewhere before the execution of this code.
The page.url should never have OS specific separators and should always have standard URL forward slash - /.
Maybe the code that constructs the original url property?

return pageUrlParts.length > urlPathParts.length && _.isEqual(pageUrlParts.slice(0, urlPathParts.length), urlPathParts);
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const _ = require('lodash');
const yaml = require('js-yaml');
const toml = require('@iarna/toml');

const { EOL } = require('os');

module.exports = {
forEachPromise,
Expand Down Expand Up @@ -107,20 +107,20 @@ function parseMarkdownWithFrontMatter(string) {
let frontMatterTypes = [
{
type: 'yaml',
startDelimiter: '---\n',
endDelimiter: '\n---',
startDelimiter: `---${EOL}`,
endDelimiter: `${EOL}---`,
parse: (string) => yaml.safeLoad(string, {schema: yaml.JSON_SCHEMA})
},
{
type: 'toml',
startDelimiter: '+++\n',
endDelimiter: '\n+++',
startDelimiter: `+++${EOL}`,
endDelimiter: `${EOL}+++`,
parse: (string) => toml.parse(string)
},
{
type: 'json',
startDelimiter: '{\n',
endDelimiter: '\n}',
startDelimiter: `{${EOL}`,
endDelimiter: `${EOL}}`,
parse: (string) => JSON.parse(string)
}
];
Expand Down