Skip to content

Commit

Permalink
getPageByReference
Browse files Browse the repository at this point in the history
- fixed relative path
  • Loading branch information
rodikh committed Oct 2, 2020
1 parent 25d17f9 commit b56faee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/unibit.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ 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;
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 b56faee

Please sign in to comment.