Skip to content

Commit 22f9441

Browse files
authored
Merge pull request #2 from shaunwarman/honor-additional-props
feat: honor additional props in rev manifest file
2 parents 387c8c8 + 4d456c3 commit 22f9441

File tree

7 files changed

+11239
-14
lines changed

7 files changed

+11239
-14
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [Install](#install)
1616
* [Usage](#usage)
1717
* [API](#api)
18+
* [Breaking changes in 2.0](#breaking-changes-in-20)
1819
* [Contributors](#contributors)
1920
* [License](#license)
2021

@@ -55,7 +56,7 @@ app.use((ctx, next) => {
5556
// ...
5657
```
5758

58-
2. Call the `manifest(str)` helper function in your views when you need to include assets (requires a templating engine).
59+
2. Call the `manifest(str, ?prop)` helper function in your views when you need to include assets (requires a templating engine).
5960

6061
> [pug][]:
6162
@@ -65,7 +66,7 @@ app.use((ctx, next) => {
6566
title Foo
6667
body
6768
h1 Foo
68-
script(src=manifest('foo.js'))
69+
script(src=manifest('foo.js', 'path'))
6970
```
7071

7172
> [ejs][]
@@ -77,7 +78,7 @@ app.use((ctx, next) => {
7778
</head>
7879
<body>
7980
<h1>Foo</h1>
80-
<script src="<%= manifest('foo.js'); %>"></script>
81+
<script src="<%= manifest('foo.js', 'path'); %>" integrity="<%= manifest('foo.js', 'integrity') %>"></script>
8182
</body>
8283
</html>
8384
```
@@ -91,7 +92,7 @@ app.use((ctx, next) => {
9192
</head>
9293
<body>
9394
<h1>Foo</h1>
94-
<script src="{{ manifest('foo.js'); }}"></script>
95+
<script src="{{ manifest('foo.js'); }}" integrity="{{ manifest('foo.js', 'integrity'); }}"></script>
9596
</body>
9697
</html>
9798
```
@@ -107,6 +108,11 @@ app.use((ctx, next) => {
107108
* `manifest(str)` - the helper function returned when `manifestRev` is invoked in your app. Returns the string found from a lookup in your `rev-manifest.json` file for the `str` argument passed (e.g. if you type `{{ manifest('foo.js'); }}` in your view, then it returns for the value of the `foo.js` property as defined in your `manifest` file, such as `foo-0775041dd4.js`). If the found is not found, then the input `str` argument is returned.
108109

109110

111+
## Breaking changes in 2.0
112+
113+
* `manifest(str)` is now `manifest(str, prop)` which now accepts a following property within your `rev-manifest.json` file. `prop` is optional and defaults to the path of the rev'd file. For example if you type `{{ manifest('foo.js', 'integrity'); }}` in your view, then it returns for the value of the `foo.js` file `integrity` property as defined in your `manifest` file, such as `sha256-YEWYfCFP9yc5DAF8K5AtLEyFuKZ1MNw+xQPm8g70LYY=`). If the found is not found, then the input `str` argument is returned.
114+
115+
110116
## Contributors
111117

112118
| Name | Website |

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ module.exports = function(opts) {
2121
manifest = require(opts.manifest);
2222
} catch (err) {}
2323

24-
return str => {
24+
return (str, prop = 'path') => {
2525
let output = opts.prepend + str;
2626
try {
2727
if (!PROD) manifest = require(opts.manifest);
28-
output = opts.prepend + (manifest[str] || str);
28+
if (typeof manifest[str] === 'string') {
29+
output = opts.prepend + String(manifest[str] || str);
30+
} else if (typeof manifest[str] === 'object') {
31+
const val = String((manifest[str] && manifest[str][prop]) || str);
32+
output = prop === 'path' ? opts.prepend + val : val;
33+
}
2934
} catch (err) {}
3035

3136
return output;

0 commit comments

Comments
 (0)