1+ // @ts -check
2+ /// <reference types="node" />
3+
14'use strict' ;
25
36const urlPlaceholders = require ( './placeholders' ) . urlPlaceholders ;
@@ -64,18 +67,16 @@ const generateUrl = function (template, jekyllResource) {
6467 * @param {string } options.template - The String used as template for URL generation,
6568 * or example "/:path/:basename:output_ext", where
6669 * a placeholder is prefixed with a colon.
67- * @param {string } options.: placeholders - A hash containing the placeholders which will be
70+ * @param {Object< string,any> } options.placeholders - A hash containing the placeholders which will be
6871 * replaced when used inside the template. E.g.
6972 * { year: (new Date()).getFullYear() } would replace
7073 * the placeholder ":year" with the current year.
71- * @param {string } options.permalink - If supplied, no URL will be generated from the
74+ * @param {string } [ options.permalink] - If supplied, no URL will be generated from the
7275 * template. Instead, the given permalink will be
7376 * used as URL.
7477 * @see {@link https://github.com/jekyll/jekyll/blob/cc82d442223bdaee36a2aceada64008a0106d82b/lib/jekyll/url.rb|Mimicked Jekyll Code }
7578 */
7679function JekyllUrl ( options ) {
77- options = options || { } ;
78-
7980 this . template = options . template ;
8081 this . placeholders = options . placeholders ;
8182 this . permalink = options . permalink ;
@@ -92,7 +93,7 @@ function JekyllUrl (options) {
9293 * @throws {Error } if the relative URL contains a colon
9394 */
9495JekyllUrl . prototype . toString = function ( ) {
95- const sanitizedUrl = this . sanitize_url ( this . generated_permalink ( ) || this . generated_url ( ) ) ;
96+ const sanitizedUrl = this . sanitize_url ( this . generated_permalink ( ) || this . generated_url ( ) || '' ) ;
9697
9798 if ( sanitizedUrl . includes ( ':' ) ) {
9899 throw new Error ( 'The URL' + sanitizedUrl + 'is invalid because it contains a colon.' ) ;
@@ -131,7 +132,7 @@ JekyllUrl.prototype.generated_url = function () {
131132 */
132133JekyllUrl . prototype . generate_url = function ( template ) {
133134 return Object . keys ( this . placeholders ) . reduce (
134- ( result , token ) => result . split ( ':' + token ) . join ( this . constructor . escape_path ( this . placeholders [ token ] || '' ) ) ,
135+ ( result , token ) => result . split ( ':' + token ) . join ( JekyllUrl . escape_path ( this . placeholders [ token ] || '' ) ) ,
135136 template
136137 ) ;
137138} ;
0 commit comments