Merge pull request #9 from jrbenito/pass-headers-nt3rp
Pass headers to s3-sync to be able to set metadata in objects
This commit is contained in:
17
README.md
17
README.md
@@ -21,11 +21,28 @@ deploy:
|
|||||||
aws_secret: <AWS secret key> // Optional, if the environment variable `AWS_SECRET_ACCESS_KEY` is set
|
aws_secret: <AWS secret key> // Optional, if the environment variable `AWS_SECRET_ACCESS_KEY` is set
|
||||||
concurrency: <number of connections> // Optional
|
concurrency: <number of connections> // Optional
|
||||||
region: <region> // Optional, see https://github.com/LearnBoost/knox#region
|
region: <region> // Optional, see https://github.com/LearnBoost/knox#region
|
||||||
|
headers: <headers in JSON format> // pass any headers to S3, usefull for metadata cache setting of Hexo assets
|
||||||
|
```
|
||||||
|
#### Example: header Cache-Control
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
deploy:
|
||||||
|
type: s3-cloudfront
|
||||||
|
bucket: my-site-bucket
|
||||||
|
cf_distribution: mydistributionid
|
||||||
|
headers: {CacheControl: 'max-age=604800, public'}
|
||||||
|
```
|
||||||
|
|
||||||
|
This will set "Cache-Control" header in every file deployed to max-age 1 week. This solves "Leverage browser caching" on most page speed analyzers. For custom metadata use:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
headers: {Metadata : { x-amz-meta-mykey: "my value" }}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
- Josh Strange ([joshstrange](https://github.com/joshstrange); original implementation)
|
- Josh Strange ([joshstrange](https://github.com/joshstrange); original implementation)
|
||||||
|
- Josenivaldo Benito Jr. ([JrBenito](https://github.com/jrbenito))
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var s3 = require('s3');
|
var s3 = require('s3');
|
||||||
var chalk = require('chalk');
|
var chalk = require('chalk');
|
||||||
|
var xtend = require('xtend');
|
||||||
|
|
||||||
module.exports = function(args) {
|
module.exports = function(args) {
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ module.exports = function(args) {
|
|||||||
var publicDir = this.config.public_dir;
|
var publicDir = this.config.public_dir;
|
||||||
var log = this.log;
|
var log = this.log;
|
||||||
|
|
||||||
|
var customHeaders = args.headers || {};
|
||||||
|
|
||||||
if (!args.bucket || !config.s3Options.accessKeyId || !config.s3Options.secretAccessKey) {
|
if (!args.bucket || !config.s3Options.accessKeyId || !config.s3Options.secretAccessKey) {
|
||||||
var help = '';
|
var help = '';
|
||||||
|
|
||||||
@@ -27,8 +30,9 @@ module.exports = function(args) {
|
|||||||
help += ' [aws_key]: <aws_key> # Optional, if provided as environment variable\n';
|
help += ' [aws_key]: <aws_key> # Optional, if provided as environment variable\n';
|
||||||
help += ' [aws_secret]: <aws_secret> # Optional, if provided as environment variable\n';
|
help += ' [aws_secret]: <aws_secret> # Optional, if provided as environment variable\n';
|
||||||
help += ' [concurrency]: <concurrency>\n';
|
help += ' [concurrency]: <concurrency>\n';
|
||||||
help += ' [region]: <region> # See https://github.com/LearnBoost/knox#region\n\n',
|
help += ' [region]: <region> # See https://github.com/LearnBoost/knox#region\n',
|
||||||
help += 'For more help, you can check the docs: ' + chalk.underline('https://github.com/nt3rp/hexo-deployer-s3');
|
help += ' [headers]: <JSON headers> # Optional, see README.md file\n\n';
|
||||||
|
help += 'For more help, you can check the docs: ' + chalk.underline('https://github.com/nt3rp/hexo-deployer-s3');
|
||||||
|
|
||||||
console.log(help);
|
console.log(help);
|
||||||
return;
|
return;
|
||||||
@@ -37,9 +41,9 @@ module.exports = function(args) {
|
|||||||
var params = {
|
var params = {
|
||||||
localDir: publicDir,
|
localDir: publicDir,
|
||||||
deleteRemoved: true,
|
deleteRemoved: true,
|
||||||
s3Params: {
|
s3Params: xtend({
|
||||||
Bucket: args.bucket
|
Bucket: args.bucket
|
||||||
}
|
},customHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
var uploader = client.uploadDir(params);
|
var uploader = client.uploadDir(params);
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Jack Guy",
|
"name": "Jack Guy",
|
||||||
"email": "jack@thatguyjackguy.com"
|
"email": "jack@thatguyjackguy.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Josenivaldo Benito Jr.",
|
||||||
|
"email": "jrbenito@benito.qsl.br"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -32,6 +36,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^1.1.1",
|
"chalk": "^1.1.1",
|
||||||
"s3": "^4.4.0"
|
"s3": "^4.4.0",
|
||||||
|
"xtend": "^4.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user