Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color option #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Prompts in the terminal will guide you through the options for downloading image
* `How many images (up to 50)?` - The number of images to retrieve. _Defaults to 20_
* `Only featured images?` - Should it only get featured images, curated by Unsplash? _Defaults to `Yes`_
* `What orientation?` - What orientation should the images be? The options are `Mixed`, `Portrait`, `Landscape`, `Squarish`, or `Custom`. `Mixed` will get images regardless of orientation, while `Custom` allows you to choose a specific width and height. _Defaults to `Mixed`_
* `What color?` - What color should the images be? The options are `Any`, `Black and white`, `Black`, `White`, `Yellow`, `Orange`, `Red`, `Purple`, `Magenta`, `Green`, `Teal`, or `Blue`. _Defaults to `Any`_
* `Width?` - For any orientation, choose the width of the returned images. This is required when the `Custom` orientation is selected. _Defaults to blank for original size_
* `Height?` - For `Custom` orientation, specify a height. This option is not displayed if the orientation is not
* `Export the credits for the photos to a .json file?` - Whether to generate the `bulksplash-credits.json` file with all the details about hte photographers. _Defaults to yes_
Expand All @@ -55,6 +56,7 @@ Available options:
* `--w`: the width of the images.
* `--h`: the height of the images.
* `--o`: the orientation of the images ("landscape", "portrait", "squarish")
* `--r`: the color of the images ("black and white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue")
* `--f`: whether you want to download featured images.
* `--j`: whether you want to generate a credits file.
---
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const bulksplash = async (args) => {
options.width = args["w"] && parseInt(args["w"]) > 0 ? parseInt(args["w"]) : null
options.height = args["h"] && parseInt(args["h"]) > 0 ? parseInt(args["h"]) : null
options.orientation = args["o"] && ["landscape", "portrait", "squarish"].includes(args["o"]) ? args["o"] : ""
options.color = args["r"] && ["black and white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue"].includes(args["r"]) ? args["r"] : ""
options.featured = args["f"] ? args["f"] : false
options.saveCredits = args["j"] ? args["j"] : false
} else{
Expand All @@ -145,7 +146,7 @@ const bulksplash = async (args) => {

// console.log(options)

const buildUrl = ({ featured, orientation, search, width, height, amount, random, collection}) => {
const buildUrl = ({ featured, orientation, color, search, width, height, amount, random, collection}) => {
let base;

if(random){
Expand All @@ -160,10 +161,11 @@ const bulksplash = async (args) => {
const a = random ? (amount > 30 ? `&count=30` : `&count=${amount}`) : ""
const p = !random && collection ? (amount > 30 ? `&per_page=30` : `&per_page=${amount}`) : ""
const o = orientation ? `&orientation=${orientation}` : ''
const c = color ? `&color=${color}` : ''
const s = search && random ? `&query=${search}` : ''
const w = width ? `&w=${width}` : ''
const h = height ? `&h=${height}` : ''
return `${base}${a}${p}${o}${f}${w}${h}${s}${clientId}`
return `${base}${a}${p}${o}${c}${f}${w}${h}${s}${clientId}`
}

let url;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bulksplash",
"version": "2.0.2",
"version": "2.1.0",
"description": "A simple command line tool that lets you bulk download images from Unsplash",
"main": "main.js",
"dependencies": {
Expand Down
15 changes: 15 additions & 0 deletions questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DEFAULTS = {
featured: true,
width: 2400,
height: 1600,
color: null
}

const requiredQuestions = {
Expand Down Expand Up @@ -49,6 +50,20 @@ const requiredQuestions = {
return val.toLowerCase()
},
},

color: {
type: 'list',
name: 'color',
message: '🎨 What color?',
choices: ['Any', 'Black and white', 'Black', 'White', 'Yellow', 'Orange', 'Red', 'Purple', 'Magenta', 'Green', 'Teal', 'Blue'],
filter: function(val) {
val = val.toLowerCase().split(' ').join('_')
if(val === 'any')
val = null
return val
},
default: DEFAULTS.color
},
}

const conditionalQuestions = {
Expand Down