Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Install](#install)
* [Usage](#usage)
* [API](#api)
* [Breaking changes in 2.0](#breaking-changes-in-20)
* [Contributors](#contributors)
* [License](#license)

Expand Down Expand Up @@ -55,7 +56,7 @@ app.use((ctx, next) => {
// ...
```

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

> [pug][]:

Expand All @@ -65,7 +66,7 @@ app.use((ctx, next) => {
title Foo
body
h1 Foo
script(src=manifest('foo.js'))
script(src=manifest('foo.js', 'path'))
```

> [ejs][]
Expand All @@ -77,7 +78,7 @@ app.use((ctx, next) => {
</head>
<body>
<h1>Foo</h1>
<script src="<%= manifest('foo.js'); %>"></script>
<script src="<%= manifest('foo.js', 'path'); %>" integrity="<%= manifest('foo.js', 'integrity') %>"></script>
</body>
</html>
```
Expand All @@ -91,7 +92,7 @@ app.use((ctx, next) => {
</head>
<body>
<h1>Foo</h1>
<script src="{{ manifest('foo.js'); }}"></script>
<script src="{{ manifest('foo.js'); }}" integrity="{{ manifest('foo.js', 'integrity'); }}"></script>
</body>
</html>
```
Expand All @@ -107,6 +108,11 @@ app.use((ctx, next) => {
* `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.


## Breaking changes in 2.0

* `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.


## Contributors

| Name | Website |
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ module.exports = function(opts) {
manifest = require(opts.manifest);
} catch (err) {}

return str => {
return (str, prop = 'path') => {
let output = opts.prepend + str;
try {
if (!PROD) manifest = require(opts.manifest);
output = opts.prepend + (manifest[str] || str);
if (typeof manifest[str] === 'string') {
output = opts.prepend + String(manifest[str] || str);
} else if (typeof manifest[str] === 'object') {
const val = String((manifest[str] && manifest[str][prop]) || str);
output = prop === 'path' ? opts.prepend + val : val;
}
} catch (err) {}

return output;
Expand Down
Loading