Skip to content

Commit 95c14e4

Browse files
committed
getPageByReference
- PR fixes
1 parent c5d9e26 commit 95c14e4

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

src/unibit.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,9 @@ module.exports = class Unibit {
370370

371371
getPageByFilePath(context, filePath) {
372372
// remove extension
373-
const urlPath = _.trim(filePath, '.md');
374373
return _.find(context.site.pages, page => {
375-
const pageUrl = _.trim(_.get(page, 'relPath'), '.md');
376-
return urlPath === pageUrl;
374+
const pageUrl = _.get(page, 'relPath');
375+
return filePath === pageUrl;
377376
});
378377
}
379378

tests/unibit-functions.test.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,16 @@ const Unibit = require('../src/unibit');
22
const unibit = new Unibit();
33

44
const aboutPage = {
5-
"absPath": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content/about.md",
65
"relPath": "about.md",
7-
"absDir": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content",
8-
"relDir": "",
96
"url": "about/",
10-
"basename": "about.md",
11-
"filename": "about"
127
}
138
const feature1Page = {
14-
"absPath": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content/features/feature1.md",
159
"relPath": "features/feature1.md",
16-
"absDir": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content/features",
17-
"relDir": "features",
1810
"url": "features/feature1/",
19-
"basename": "feature1.md",
20-
"filename": "feature1"
2111
};
2212
const feature2Page = {
23-
"absPath": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content/features/feature2.md",
2413
"relPath": "features/feature2.md",
25-
"absDir": "/Users/rodik/Work/Stackbit/project-repos/unibit/sample/unibit-universal/content/features",
26-
"relDir": "features",
2714
"url": "features/feature2/",
28-
"basename": "feature2.md",
29-
"filename": "feature2"
3015
};
3116

3217
const linksSSGData = [
@@ -62,6 +47,16 @@ describe('getPage', ()=>{
6247
it('gets a page by url', () => {
6348
let page = unibit.getPage(pageContext, 'about');
6449
expect(page).toBe(aboutPage);
50+
51+
page = unibit.getPage(pageContext, '/about');
52+
expect(page).toBe(aboutPage);
53+
54+
page = unibit.getPage(pageContext, '/about/');
55+
expect(page).toBe(aboutPage);
56+
57+
page = unibit.getPage(pageContext, 'about/');
58+
expect(page).toBe(aboutPage);
59+
6560
});
6661
it('should not work with file paths', () => {
6762
let page = unibit.getPage(pageContext, 'about.md');
@@ -101,8 +96,8 @@ describe('getPageByFilePath', ()=>{
10196
expect(data).toBe(feature1Page);
10297
});
10398

104-
it('gets a page by url', () => {
99+
it('should not work with urls', () => {
105100
let data = unibit.getPageByFilePath(pageContext, 'features/feature1');
106-
expect(data).toBe(feature1Page);
101+
expect(data).toBeUndefined();
107102
});
108103
})

0 commit comments

Comments
 (0)