Skip to content

Commit

Permalink
null handling improvements and updates to unsplash URL placeholders (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BagToad authored Jan 24, 2024
1 parent 071d4e5 commit 2f126a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,43 @@ jobs:
### 👋 Welcome to my GitHub Profile!

----

<div align="center">
<img width="720" src="{{ unsplash-url }}" alt="{{ unsplash-alt-description }}">

## Photo of the day

<a href="{{ unsplash-page-url }}"><img width="720" src="{{ unsplash-raw-url }}" alt="{{ unsplash-alt-description }}"></a>

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

<em>{{ unsplash-description }}</em>

Photo by [{{ unsplash-name }}]({{ unsplash-portfolio-url }}) on [unsplash.com](https://unsplash.com/) • {{ socials }}

Taken at {{ location }} • {{ google-maps }}

Photo by [{{ unsplash-name }}]({{ unsplash-portfolio-url }}) on [unsplash.com](https://unsplash.com/)
---

<details>
<summary>Photography Details</summary>

| Parameter | Value |
| ------------- | ----- |
| Camera Model | {{ model }} |
| Exposure Time | {{ exposure-time }} |
| Aperture | {{ aperture }} |
| Focal Length | {{ focal-length }} |
| ISO | {{ iso }} |
| Location | {{ location }} ({{ country }}) |
| Coordinates | Latitude {{ latitude }}, Longitude {{ longitude }} |

</details>

</div>

----

☝️ 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!

```

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

| Placeholder | Description |
| ----------------------- | ------------------------------------------------- |
| `{{ unsplash-url }}` | The URL of the image from Unsplash |
| `{{ unsplash-raw-url }}` | The raw file URL of the image from Unsplash |
| `{{ unsplash-page-url }}` | A link to the photo on unsplash.com |
| `{{ unsplash-alt-description }}` | The alt description of the image from Unsplash |
| `{{ unsplash-description }}` | The description of the image from Unsplash |
| `{{ unsplash-name }}` | The name of the image author from Unsplash |
Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ unsplash.photos.getRandom({

// Get data from response
const URL = data.response.urls.regular;
const DESC = data.response.description;
const ALTDESC = data.response.alt_description;
const HTMLURL = data.response.links.html;
const DESC = data.response.description || '';
const ALTDESC = data.response.alt_description || '';

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

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

// Replace variables in template
const result = templateFile.replace(/{{ unsplash-url }}/g, URL)
const result = templateFile
.replace(/{{ unsplash-raw-url }}/g, URL)
.replace(/{{ unsplash-page-url }}/g, HTMLURL)
.replace(/{{ unsplash-description }}/g, DESC)
.replace(/{{ unsplash-alt-description }}/g, ALTDESC)
.replace(/{{ unsplash-name }}/g, NAME)
Expand Down

0 comments on commit 2f126a7

Please sign in to comment.