Skip to content

Commit

Permalink
Merge pull request #17 from stackbithq/getPageByReference
Browse files Browse the repository at this point in the history
getPageByReference
  • Loading branch information
stackbit-admin committed Oct 21, 2020
2 parents 25d17f9 + 165c850 commit 6a22e40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/unibit.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ module.exports = class Unibit {
}

getPageByFilePath(context, filePath) {
// remove extension
filePath = path.relative(UNIBIT.pagesDir, filePath);
return _.find(context.site.pages, page => {
const pageUrl = _.get(page, 'relPath');
return filePath === pageUrl;
const pageRelPath = _.get(page, 'relPath');
return filePath === pageRelPath;
});
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unibit-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ describe('getData', ()=>{

describe('getPageByFilePath', ()=>{
it('gets a page by path', () => {
let data = unibit.getPageByFilePath(pageContext, 'features/feature1.md');
let data = unibit.getPageByFilePath(pageContext, 'content/features/feature1.md');
expect(data).toBe(feature1Page);
});

it('should not work with urls', () => {
let data = unibit.getPageByFilePath(pageContext, 'features/feature1');
let data = unibit.getPageByFilePath(pageContext, 'content/features/feature1');
expect(data).toBeUndefined();
});
})

0 comments on commit 6a22e40

Please sign in to comment.