Skip to content

Instantly share code, notes, and snippets.

@Markonis
Created March 18, 2019 09:41
Show Gist options
  • Save Markonis/ad56953c3ae92e96614b61a975f50b6a to your computer and use it in GitHub Desktop.
Save Markonis/ad56953c3ae92e96614b61a975f50b6a to your computer and use it in GitHub Desktop.
import * as m from 'mithril';
import { State } from '../model/state';
import { Photo } from '../model/photo';
import { NestedCSSProperties } from 'typestyle/lib/types';
const UTM = '?utm_source=resplash&utm_medium=referral';
const UNSLPASH_URL = `https://unsplash.com${UTM}`;
const style: NestedCSSProperties = {
position: 'absolute',
top: '2rem',
left: '1rem'
};
function authorLink(photo: Photo) {
let url = `${photo.user.links.html}${UTM}`
let fullName = `${photo.user.first_name} ${photo.user.last_name}`;
return m('a', { href: url, target: '_blank' }, fullName);
}
function unsplashLink() {
return m('a', { href: UNSLPASH_URL, target: '_blank' }, 'Unsplash');
}
export default function unsplashAttribution(state: State) {
if (state.photo)
return m('div', { style },
'Photo by ', authorLink(state.photo), ' on ', unsplashLink());
else
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment