-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro to differentiate between pages on different paths #168
Comments
anyone a solution or workaround? this is a really annoying bug |
I have the same problem! any ideas!?. |
same. |
I created a helper to fulfill my needs, maybe it helps you too. Unfortunately it does not really check the path, which seems not to be possible (we have no parent context), but for my need of detecting blog posts it helped (like
module.exports = function() {
/**
* Handlebars block helper that renders the content inside of it based on the current page.
* @param {string...} pages - One or more pages to check.
* @param (object) options - Handlebars object.
* @example
{{#ifpagewildcard 'over*view'}}<p>over*view</p>{{/ifpagewildcard}}
{{#ifpagewildcard 'ove*iew'}}<p>ove*iew</p>{{/ifpagewildcard}}
{{#ifpagewildcard '*view'}}<p>*view</p>{{/ifpagewildcard}}
{{#ifpagewildcard 'over*'}}<p>over*</p>{{/ifpagewildcard}}
{{#ifpagewildcard '*ervie*'}}<p>*ervie*</p>{{/ifpagewildcard}}
{{#ifpagewildcard '*ervie'}}<p>*ervie NOT SHOWN</p>{{/ifpagewildcard}}
{{#ifpagewildcard 'vervie*'}}<p>vervie* NOT SHOWN</p>{{/ifpagewildcard}}
* @return The content inside the helper if a page matches, or an empty string if not.
*/
const allAsterisks = new RegExp(/\*/, 'g');
var params = Array.prototype.slice.call(arguments);
var pages = params.slice(0, -1);
var options = params[params.length - 1];
var pageName = options.data.root.page;
for (var i in pages) {
const tester = new RegExp('^' + pages[i].replace(allAsterisks, '.*') + '$');
if (tester.test(pageName)) {
return options.fn(this);
}
}
return '';
} |
When there is just one file called
index.html
this works fine:But when there are multiple directories with an
index.html
per directory, this code need to be enhanced (but how?)The request is for some kind of differentiator to indicate the path to the file. The result might be something like this:
The text was updated successfully, but these errors were encountered: