diff --git a/README.md b/README.md index be926be..bdd3a6c 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ metalsmith There will also be a `tagsUrlSafe` array created that will contain an array of url safe tag names for use in url creation. + There will also be a `tagsCollection` array created that will have an object containing the `urlSlug` and `display` properties of each tag. + You can use `metalsmith-permalink` to customize the permalink of the tag pages as you would do with anything else. It is possible to use `opts.metadataKey` for defining the name of the global tag list. diff --git a/lib/index.js b/lib/index.js index b7d640d..3eab6c3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,6 +19,7 @@ function plugin(opts) { opts.layout = opts.layout || 'partials/tag.hbt'; opts.handle = opts.handle || 'tags'; var handleUrlSafe = opts.handle + 'UrlSafe'; + var handleCollection = opts.handle + 'Collection'; opts.metadataKey = opts.metadataKey || 'tags'; opts.sortBy = opts.sortBy || 'title'; opts.reverse = opts.reverse || false; @@ -98,6 +99,10 @@ function plugin(opts) { // Add url safe version of every tag as well. data[handleUrlSafe] = []; + // Add an object containing the display and + // safe url version of every tag + data[handleCollection] = []; + tagsData.forEach(function(rawTag) { // Trim leading + trailing white space from tag. var tag = String(rawTag).trim(); @@ -108,6 +113,9 @@ function plugin(opts) { // Save url safe formatted tag data. data[handleUrlSafe].push(safeTag(tag)); + // Save url safe formatted and display versions of tag data + data[handleCollection].push({ display: tag, urlSlug: safeTag(tag)}); + // Add each tag to our overall tagList and initialize array if it // doesn't exist. if (!tagList[tag]) { diff --git a/test/index.js b/test/index.js index 7ec39be..dea30ac 100644 --- a/test/index.js +++ b/test/index.js @@ -24,6 +24,7 @@ describe('metalsmith-tags', function() { if (err) return done(err); assert.equal(files['index.html'].tags.toString(),['hello', 'world', 'this is', 'tag'].toString()); assert.equal(files['index.html'].tagsUrlSafe.toString(),['hello', 'world', 'this-is', 'tag'].toString()); + assert.equal(files['index.html'].tagsCollection.toString(),[{ display: 'hello', urlSlug: 'hello'}, { display: 'world', urlSlug: 'world'}, { display: 'this is', urlSlug: 'this-is'}, { display: 'tag', urlSlug: 'tag'}].toString()); done(); }); });