Skip to content

Commit 2f126a7

Browse files
authored
null handling improvements and updates to unsplash URL placeholders (#5)
* Fix null values for description and alt_description * Fix location data fallback to 'Unknown' * Updated placeholder names for unsplash raw photo file. Added new placeholder for a link to the image unsplash.com. * Fix default value for creator name
1 parent 071d4e5 commit 2f126a7

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,43 @@ jobs:
4949
### 👋 Welcome to my GitHub Profile!
5050

5151
----
52-
5352
<div align="center">
54-
<img width="720" src="{{ unsplash-url }}" alt="{{ unsplash-alt-description }}">
53+
54+
## Photo of the day
55+
56+
<a href="{{ unsplash-page-url }}"><img width="720" src="{{ unsplash-raw-url }}" alt="{{ unsplash-alt-description }}"></a>
5557

5658
<em>{{ unsplash-alt-description }}</em>
5759

5860
<em>{{ unsplash-description }}</em>
61+
62+
Photo by [{{ unsplash-name }}]({{ unsplash-portfolio-url }}) on [unsplash.com](https://unsplash.com/) • {{ socials }}
63+
64+
Taken at {{ location }} • {{ google-maps }}
5965

60-
Photo by [{{ unsplash-name }}]({{ unsplash-portfolio-url }}) on [unsplash.com](https://unsplash.com/)
66+
---
67+
68+
<details>
69+
<summary>Photography Details</summary>
70+
71+
| Parameter | Value |
72+
| ------------- | ----- |
73+
| Camera Model | {{ model }} |
74+
| Exposure Time | {{ exposure-time }} |
75+
| Aperture | {{ aperture }} |
76+
| Focal Length | {{ focal-length }} |
77+
| ISO | {{ iso }} |
78+
| Location | {{ location }} ({{ country }}) |
79+
| Coordinates | Latitude {{ latitude }}, Longitude {{ longitude }} |
80+
81+
</details>
82+
6183
</div>
6284

6385
----
6486

6587
☝️ A random image is retrieved and posted to my profile daily via the [BagToad/random-unsplash-action](https://github.com/BagToad/random-unsplash-action) action!
88+
6689
```
6790

6891
# Action Inputs
@@ -84,7 +107,8 @@ More information can be found in [the Unsplash API docs](https://unsplash.com/do
84107

85108
| Placeholder | Description |
86109
| ----------------------- | ------------------------------------------------- |
87-
| `{{ unsplash-url }}` | The URL of the image from Unsplash |
110+
| `{{ unsplash-raw-url }}` | The raw file URL of the image from Unsplash |
111+
| `{{ unsplash-page-url }}` | A link to the photo on unsplash.com |
88112
| `{{ unsplash-alt-description }}` | The alt description of the image from Unsplash |
89113
| `{{ unsplash-description }}` | The description of the image from Unsplash |
90114
| `{{ unsplash-name }}` | The name of the image author from Unsplash |

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ unsplash.photos.getRandom({
4444

4545
// Get data from response
4646
const URL = data.response.urls.regular;
47-
const DESC = data.response.description;
48-
const ALTDESC = data.response.alt_description;
47+
const HTMLURL = data.response.links.html;
48+
const DESC = data.response.description || '';
49+
const ALTDESC = data.response.alt_description || '';
4950

5051
// Social data
51-
const NAME = data.response.user.name;
52+
const NAME = data.response.user.name || 'Unknown';
5253
const PORTFOLIOURL = data.response.user.social.portfolio_url;
5354
const INSTAGRAM = data.response.user.social.instagram_username
5455
? `[Instagram](https://instagram.com/${data.response.user.social.instagram_username})`
@@ -84,15 +85,17 @@ unsplash.photos.getRandom({
8485
const ISO = data.response.exif.iso;
8586

8687
// Location data
87-
const LOCATION = data.response.location.name;
88+
const LOCATION = data.response.location.name || 'Unknown';
8889
const COUNTRY = data.response.location.country;
8990
const LATITUDE = data.response.location.position.latitude;
9091
const LONGITUDE = data.response.location.position.longitude;
9192
const GOOGLEMAPS = LATITUDE && LONGITUDE ? `[Google Maps](https://www.google.com/maps/search/?api=1&query=${LATITUDE},${LONGITUDE})` : '';
9293
const GOOGLEMAPSSTREETVIEW = LATITUDE && LONGITUDE ? `[Google Maps street view](https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${LATITUDE},${LONGITUDE})` : '';
9394

9495
// Replace variables in template
95-
const result = templateFile.replace(/{{ unsplash-url }}/g, URL)
96+
const result = templateFile
97+
.replace(/{{ unsplash-raw-url }}/g, URL)
98+
.replace(/{{ unsplash-page-url }}/g, HTMLURL)
9699
.replace(/{{ unsplash-description }}/g, DESC)
97100
.replace(/{{ unsplash-alt-description }}/g, ALTDESC)
98101
.replace(/{{ unsplash-name }}/g, NAME)

0 commit comments

Comments
 (0)