Skip to content

Commit

Permalink
Add path property to generated pages
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Jun 27, 2020
1 parent 33926a1 commit 7673595
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"github": {
"release": true,
"releaseName": "metalsmith-taxonomy ${version}",
"tokenRef": "GITHUB_TOKEN",
"releaseNotes": true
"tokenRef": "GITHUB_TOKEN"
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [0.2.1](https://github.com/webketje/metalsmith-taxonomy/compare/0.2.0...0.2.1)

> 12 June 2020
- Release 0.2.1 [`975ea70`](https://github.com/webketje/metalsmith-taxonomy/commit/975ea701aff532db837c274e1fdfc7d9a022bb19)

#### [0.2.0](https://github.com/webketje/metalsmith-taxonomy/compare/0.1.3...0.2.0)

> 12 June 2020
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Metalsmith plugin that organizes files into taxonomy trees in global metadata an
[![metalsmith: plugin][metalsmith-badge]][metalsmith-url]
[![npm: version][npm-badge]][npm-url]
[![travis: build][ci-badge]][ci-url]
[[!code coverage]][codecov-url]
[![code coverage][codecov-badge]][codecov-url]
[![license: LGPL-3.0][license-badge]][license-url]

## Features
Expand Down Expand Up @@ -149,6 +149,7 @@ All the file objects have an empty string `contents` property and a page `type`
| Property | Type | Description |
| :----------- | :----------------- | :------------------------------------------------------------------------------------------------------ |
| `type` | `'taxonomy:index'` | Page type |
| `path` | `string` | Destination path of the page |
| `namespace` | `null\|string` | Namespace passed in taxonomy set |
| `taxonomies` | `object` | Copy of the object at `metadata.taxonomies[namespace]` (or `metadata.taxonomies` if `namespace===null`) |
Expand All @@ -157,6 +158,7 @@ All the file objects have an empty string `contents` property and a page `type`
| Property | Type | Description |
| :----------- | :-------------------- | :------------------------------------------------------------------------------------------------------ |
| `type` | `'taxonomy:taxonomy'` | Page type |
| `path` | `string` | Destination path of the page |
| `namespace` | `null\|string` | Namespace passed in taxonomy set |
| `taxonomy` | `string` | Name of the current taxonomy |
| `terms` | `array` | Array with the terms found for the current taxonomy |
Expand All @@ -167,6 +169,7 @@ All the file objects have an empty string `contents` property and a page `type`
| Property | Type | Description |
| :----------- | :---------------- | :------------------------------------------------------------------------------------------------------ |
| `type` | `'taxonomy:term'` | Page type |
| `path` | `string` | Destination path of the page |
| `namespace` | `null\|string` | Namespace passed in taxonomy set |
| `taxonomy` | `string` | Name of the current taxonomy |
| `terms` | `array` | Array with the terms found for the current taxonomy |
Expand Down
12 changes: 8 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var page = {
contents: Buffer.from(''),
type: 'taxonomy:index',
namespace: context.namespace,
taxonomies: context.taxonomies
taxonomies: context.taxonomies,
path: context.path
};
},
taxonomy: function (context) {
Expand Down Expand Up @@ -98,12 +99,14 @@ function taxonomies(taxonomySets) {
};

if (pages && pages.includes('taxonomy')) {
files[rule.taxonomypath(taxonomyName)] = page.taxonomy(pageContext);
const key = rule.taxonomypath(taxonomyName);
files[key] = page.taxonomy(Object.assign({ path: key }, pageContext ));
}

if (pages && pages.includes('term')) {
Object.keys(namespace[taxonomyName]).forEach(function (term) {
files[rule.termpath(term, taxonomyName)] = page.term(Object.assign({ term: term }, pageContext));
const key = rule.termpath(term, taxonomyName);
files[key] = page.term(Object.assign({ term: term, path: key }, pageContext));
});
}

Expand All @@ -116,7 +119,8 @@ function taxonomies(taxonomySets) {
});

if (pages && pages.includes('index')) {
files[rule.indexpath()] = page.index(pageContext);
const key = rule.indexpath();
files[key] = page.index(Object.assign({ path: key }, pageContext));
}
});

Expand Down
9 changes: 9 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test.spec('metalsmith-taxonomy', function () {
var metadata = {};
var categories = [];
var taxonomies = {};
var files = {};

test.before(function (done) {
Metalsmith(__dirname)
Expand All @@ -69,6 +70,7 @@ test.spec('metalsmith-taxonomy', function () {
}
})
)
.use((fileObjects) => files = fileObjects)
.process(function (err) {
if (err) throw err;
metadata = this.metadata();
Expand Down Expand Up @@ -113,6 +115,13 @@ test.spec('metalsmith-taxonomy', function () {

test(validity).equals(true);
});

test('Index, taxonomy & term pages get a path property identical to their key in the files object', function() {
var generatedPages = key => !!files[key].type;
var paths = Object.keys(files).filter(generatedPages).map(key => key === files[key].path);

test(paths.indexOf(false)).equals(-1);
});
});

test.spec('Multiple taxonomies', function () {
Expand Down

0 comments on commit 7673595

Please sign in to comment.