Skip to content

Commit

Permalink
getPageByReference
Browse files Browse the repository at this point in the history
- PR fixes
- renamed getPageByReference to getPageByFilePath
- removed mock file
  • Loading branch information
rodikh committed Sep 21, 2020
1 parent 112916a commit c5d9e26
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 426 deletions.
10 changes: 5 additions & 5 deletions src/unibit.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ module.exports = class Unibit {
context.getPage = this.getPage.bind(this, context);
context.getPages = this.getPages.bind(this, context);
context.getData = this.getData.bind(this, context);
context.getPageByReference = this.getPageByReference.bind(this, context);
context.getPageByFilePath = this.getPageByFilePath.bind(this, context);
context.paginate = this.paginate.bind(this, context);
context.link = this.link.bind(this, context.site);
context.classNames = this.classNames.bind(this);
Expand Down Expand Up @@ -368,12 +368,12 @@ module.exports = class Unibit {
return _.get(context.site.data, path, null);
}

getPageByReference(context, reference) {
getPageByFilePath(context, filePath) {
// remove extension
reference = reference.replace(/\.md$/, '');
const urlPath = _.trim(filePath, '.md');
return _.find(context.site.pages, page => {
const pageUrl = _.trim(_.get(page, 'url'), '/');
return reference === pageUrl;
const pageUrl = _.trim(_.get(page, 'relPath'), '.md');
return urlPath === pageUrl;
});
}

Expand Down
Loading

0 comments on commit c5d9e26

Please sign in to comment.