Skip to content

Commit 6145fd6

Browse files
BagToadSukhpreet-s
andauthored
Add new image data and socials data placeholders (#2)
* Add debug statement and comment to get data from response * Add camera and location data to available placeholders * Create socials string placeholder * refactor socialstring * fixed socialstring reduce function * Fix reduce function parameter order * Refactor SOCIALS array to filter out null values * Update social media links in index.js * Refactor social data variables in index.js * Fix incorrect override of PORTFOLIOURL * Add socials to placeholders in README --------- Co-authored-by: Sukhpreet-s <[email protected]>
1 parent b777b59 commit 6145fd6

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ More information can be found in [the Unsplash API docs](https://unsplash.com/do
8989
| `{{ unsplash-description }}` | The description of the image from Unsplash |
9090
| `{{ unsplash-name }}` | The name of the image author from Unsplash |
9191
| `{{ unsplash-portfolio-url }}` | The portfolio URL of the image author from Unsplash |
92+
| `{{ model }}` | The camera model used to take the photo |
93+
| `{{ exposure-time }}` | The exposure time of the photo |
94+
| `{{ aperture }}` | The aperture of the photo |
95+
| `{{ focal-length }}` | The focal length of the photo |
96+
| `{{ iso }}` | The ISO of the photo |
97+
| `{{ location }}` | The location where the photo was taken |
98+
| `{{ country }}` | The country where the photo was taken |
99+
| `{{ latitude }}` | The latitude of the location where the photo was taken |
100+
| `{{ longitude }}` | The longitude of the location where the photo was taken |
101+
| `{{ socials }}` | A markdown linked string of the creator's socials: "instagram / portfolio / twitter"
92102

93103

94104
# Legal

index.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,72 @@ unsplash.photos.getRandom({
4040
query: QUERY,
4141
})
4242
.then(data => {
43+
core.debug(data)
44+
45+
// Get data from response
4346
const URL = data.response.urls.regular;
4447
const DESC = data.response.description;
4548
const ALTDESC = data.response.alt_description;
49+
50+
// Social data
4651
const NAME = data.response.user.name;
47-
const PORTFOLIOURL = data.response.user.portfolio_url;
52+
const PORTFOLIOURL = data.response.user.social.portfolio_url;
53+
const INSTAGRAM = data.response.user.social.instagram_username
54+
? `[instagram](https://instagram.com/${data.response.user.social.instagram_username})`
55+
: '';
56+
57+
const PORTFOLIO = data.response.user.social.portfolio_url
58+
? `[portfolio](${data.response.user.social.portfolio_url})`
59+
: '';
60+
61+
const TWITTER = data.response.user.social.twitter_username
62+
? `[twitter](https://twitter.com/${data.response.user.social.twitter_username})`
63+
: '';
64+
65+
const PAYPAL = data.response.user.social.paypal_email
66+
? `[paypal](mailto:${data.response.user.social.paypal_email})`
67+
: '';
68+
const SOCIALS = [INSTAGRAM, PORTFOLIO, TWITTER, PAYPAL].filter(Boolean);
69+
70+
// Construct a string that looks like this: "instagram / portfolio / twitter"
71+
let SOCIALSSTRING = SOCIALS.reduce((finalStr, ele, index, arr)=> {
72+
if (index < arr.length - 1) {
73+
return finalStr + ele + " / ";
74+
} else {
75+
return finalStr + ele;
76+
}
77+
}, "");
78+
79+
// Camera/EXIF data
80+
const MODEL = data.response.exif.model;
81+
const EXPOSURETIME = data.response.exif.exposure_time;
82+
const APERTURE = data.response.exif.aperture;
83+
const FOCALLENGTH = data.response.exif.focal_length;
84+
const ISO = data.response.exif.iso;
85+
86+
// Location data
87+
const LOCATION = data.response.location.name;
88+
const COUNTRY = data.response.location.country;
89+
const LATITUDE = data.response.location.position.latitude;
90+
const LONGITUDE = data.response.location.position.longitude;
4891

4992
// Replace variables in template
5093
const result = templateFile.replace(/{{ unsplash-url }}/g, URL)
5194
.replace(/{{ unsplash-description }}/g, DESC)
5295
.replace(/{{ unsplash-alt-description }}/g, ALTDESC)
5396
.replace(/{{ unsplash-name }}/g, NAME)
54-
.replace(/{{ unsplash-portfolio-url }}/g, PORTFOLIOURL);
97+
.replace(/{{ model }}/g, MODEL)
98+
.replace(/{{ exposure-time }}/g, EXPOSURETIME)
99+
.replace(/{{ aperture }}/g, APERTURE)
100+
.replace(/{{ focal-length }}/g, FOCALLENGTH)
101+
.replace(/{{ iso }}/g, ISO)
102+
.replace(/{{ location }}/g, LOCATION)
103+
.replace(/{{ country }}/g, COUNTRY)
104+
.replace(/{{ latitude }}/g, LATITUDE)
105+
.replace(/{{ longitude }}/g, LONGITUDE)
106+
.replace(/{{ unsplash-portfolio-url }}/g, PORTFOLIOURL)
107+
.replace(/{{ socials }}/g, SOCIALSSTRING);
108+
55109
// Write processed template to README.md
56110
try {
57111
fs.writeFileSync('README.md', result);
@@ -66,4 +120,4 @@ unsplash.photos.getRandom({
66120
await exec.exec('git', ['commit', '-m', 'Update README.md with unsplash image data']);
67121
await exec.exec('git', ['push', `https://${GITHUBTOKEN}@github.com/${owner}/${repo}.git`]);
68122
})
69-
.catch(error => console.error(error));
123+
.catch(error => console.error(error));

0 commit comments

Comments
 (0)