Skip to content

Commit

Permalink
change $page.pathname to $page.route; pug matchURL function to matchR…
Browse files Browse the repository at this point in the history
…oute
  • Loading branch information
lunelson committed Feb 28, 2019
1 parent ccc37ce commit 2f89e0c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/compile-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function (srcDir, pubDir, options, depReporter) {

constructor(srcFile) {
super(srcFile);
this.pathname = '/' + relative(pubDir, srcFile).replace(/\.md$/, '.html');
this.route = '/' + relative(pubDir, srcFile).replace(/\.md$/, '.html');
}

source() {
Expand All @@ -45,8 +45,8 @@ module.exports = function (srcDir, pubDir, options, depReporter) {
// stream() {
// try {
// if (!('template' in this)) {
// const { srcFile, pathname } = this;
// this.$page = Object.assign({ pathname }, data);
// const { srcFile, route } = this;
// this.$page = Object.assign({ route }, data);
// this.template = Pug.compile(pugSrc, this.options);

// // only reset depFiles if compilation worked !!
Expand Down
6 changes: 3 additions & 3 deletions lib/compile-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function(srcDir, pubDir, options, depReporter) {

constructor(srcFile) {
super(srcFile);
this.pathname = '/'+relative(pubDir, srcFile).replace(/\.pug$/, '.html');
this.route = '/'+relative(pubDir, srcFile).replace(/\.pug$/, '.html');
this.options = setOptions(this.srcFile, this.depFiles); // includes filters
this.locals = setLocals(this.srcFile, this.depFiles);
}
Expand All @@ -51,10 +51,10 @@ module.exports = function(srcDir, pubDir, options, depReporter) {
stream() {
try {
if (!('template' in this)) {
const { srcFile, pathname } = this;
const { srcFile, route } = this;
const { data, content } = this.source();
pugLogger.debug('re-compiling template');
this.$page = Object.assign({ pathname }, data);
this.$page = Object.assign({ route }, data);
this.template = Pug.compile(content, this.options);

// only reset depFiles if compilation worked !!
Expand Down
4 changes: 2 additions & 2 deletions lib/functions-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ module.exports = function (srcDir, pubDir, options) {
dump(value) {
return JSON.stringify(value, null, 2);
},
matchURL(obj, pattern) {
matchRoute(obj, pattern) {
function doMatch(obj) {
const result = new UrlPattern(`${pattern}(.html)`).match(obj.pathname);
const result = new UrlPattern(`${pattern}(.html)`).match(obj.route);
return result ? Object.assign(obj, result) : result;
}
return Array.isArray(obj) ? _.compact(obj.map(doMatch)) : doMatch(obj);
Expand Down
6 changes: 3 additions & 3 deletions lib/watch-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function pageWatch(pubDir) {

// process ->
pennyLogger.debug(`${fsEvent} $page: ${relFile}`);
const pathname = '/'+relFile.replace(/\.(pug|md)$/, '.html');
if (fsEvent == 'unlink') return delete $pages[pathname];
const route = '/'+relFile.replace(/\.(pug|md)$/, '.html');
if (fsEvent == 'unlink') return delete $pages[route];
const filename = join(pubDir, relFile);

// get the data
Expand All @@ -121,7 +121,7 @@ function pageWatch(pubDir) {
}

// set the data
$pages[pathname] = Object.assign({ pathname }, data);
$pages[route] = Object.assign({ route }, data);

// run the callback
onEvent && onEvent(fsEvent, relFile);
Expand Down

0 comments on commit 2f89e0c

Please sign in to comment.