Skip to content
This repository

Subdirectory option for sites #77

Open
wants to merge 2 commits into from

2 participants

Paul English Marcio Galli aka Taboca
Paul English

This will let a user set a subdirectory option in their config file. This subdirectory will be appended to hrefs in templates.

Marcio Galli aka Taboca

Will this resolve the case I am interested which is a developer

to be able to have his/her blog/page under a nested path? for example

http://www.example.cc/mySUBblog/index.html?

Paul English

Yes, commit 8af714c should help you accomplish that goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
16  lib/blacksmith/common.js
@@ -228,7 +228,7 @@ common.loadSite = function (dir, callback) {
228 228
 // Inline renders the `page-details` metadata section for the given `content`.
229 229
 //
230 230
 common.addDetails = function (content, options) {
231  
-  var href = common.href(options.dir, options.fullpath);
  231
+  var href = common.href(options.dir, options.fullpath, options.subdirectory);
232 232
 
233 233
   //
234 234
   // Setup default `page-details` metadata.
@@ -284,7 +284,7 @@ common.addDetails = function (content, options) {
284 284
 // ['dir-post']
285 285
 // '/dir-post
286 286
 //
287  
-common.href = function (contentDir, fullpath) {
  287
+common.href = function (contentDir, fullpath, subdirectory) {
288 288
   //
289 289
   // Strip the `contentDir`, remove any containing directory,
290 290
   // split apart and trim.
@@ -312,8 +312,18 @@ common.href = function (contentDir, fullpath) {
312 312
     parts.pop();
313 313
   }
314 314
 
  315
+  //
  316
+  // Append a subdirectory to the url if it exists
  317
+  //
  318
+  // ['dir-post']
  319
+  // ['subdirectory', 'dir-post']
  320
+  //
  321
+  if (typeof subdirectory !== "undefined") {
  322
+    parts.unshift(subdirectory);
  323
+  }
  324
+
315 325
   return Array.isArray(parts)
316  
-    ? '/' + parts.join('/')
  326
+    ? "/" + parts.join('/')
317 327
     : parts;
318 328
 };
319 329
 
2  lib/blacksmith/partial.js
@@ -93,6 +93,7 @@ exports.map = function (metadata, map) {
93 93
       if (key === 'source') {
94 94
         keyExp = new RegExp('/' + key + '$');
95 95
         map.where('href').has(keyExp).replace(keyExp, metadata[key]);
  96
+        map.where('src').has(keyExp).replace(keyExp, metadata[key]);
96 97
       }
97 98
       else if (keyType == 'string') {
98 99
         if (/^(http[s]?\:\/\/|\/)/.test(metadata[key])) {
@@ -101,6 +102,7 @@ exports.map = function (metadata, map) {
101 102
           // based on parsed HTML fragment.
102 103
           //
103 104
           map.where('href').is(key).use(key).as('href');
  105
+          map.where('src').is(key).use(key).as('src');
104 106
         }
105 107
         else {
106 108
           // map.where('href')
21  lib/blacksmith/site.js
@@ -95,19 +95,21 @@ Site.prototype.load = function (callback) {
95 95
       }
96 96
     });
97 97
 
98  
-    self.html       = results.html;
99  
-    self.references = results.references || {};
  98
+    self.html         = results.html;
  99
+    self.references   = results.references || {};
  100
+    self.subdirectory = results.options.subdirectory;
100 101
 
101 102
     self.emit('load:end', self.dir);
102 103
 
103 104
     callback(null, {
104  
-      dir:        self.dir,
105  
-      html:       self.html,
106  
-      pages:      self.pages,
107  
-      layout:     self.layout,
108  
-      layouts:    self.layouts,
109  
-      partials:   self.partials,
110  
-      references: self.references
  105
+      dir:          self.dir,
  106
+      html:         self.html,
  107
+      pages:        self.pages,
  108
+      layout:       self.layout,
  109
+      layouts:      self.layouts,
  110
+      partials:     self.partials,
  111
+      references:   self.references,
  112
+      subdirectory: self.subdirectory
111 113
     });
112 114
   });
113 115
 };
@@ -320,6 +322,7 @@ Site.prototype.renderContent = function (dir, callback) {
320 322
                 common.addDetails(rendered[name]._content, {
321 323
                   dir: path.join(self.dir, 'content'),
322 324
                   fullpath: fullpath,
  325
+                  subdirectory: self.subdirectory,
323 326
                   files: supporting,
324 327
                   stats: stats
325 328
                 });
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.