Skip to content

Commit

Permalink
ooh boy
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Jul 11, 2020
1 parent 2ec322f commit 9623140
Show file tree
Hide file tree
Showing 10 changed files with 14,057 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.vercel
.env
node_modules
.DS_STORE
24 changes: 24 additions & 0 deletions api/now-playing.ts
@@ -0,0 +1,24 @@
import { NowRequest, NowResponse } from "@vercel/node";
import { nowPlaying } from "../utils/spotify";
import { renderToString } from 'react-dom/server';
import { Player, None } from '../components/NowPlaying';


export default async function (req: NowRequest, res: NowResponse) {
res.setHeader('Content-Type', 'image/svg+xml');

const { item } = await nowPlaying();

if (!item) {
const text = renderToString(None({}));
return res.status(200).send(text);
}

const track = item.name;
const { images } = item.album;
const cover = images[images.length - 1];
const artist = item.artists.map(({ name }) => name).join(', ');
const text = renderToString(Player({ cover, artist, track }));

return res.status(200).send(text);
}
40 changes: 40 additions & 0 deletions components/NowPlaying.tsx
@@ -0,0 +1,40 @@
import React from "react";
import Svg from './Svg';
import Text from "./Text";

export interface Props {
cover: string;
track: string;
artist: string;
}

export const None: React.FC = () => {
return (
<Svg
width="350"
height="200"
>
<Text family="mono" size="small">No tunes...</Text>
</Svg>
);
}

export const Player: React.FC<Props> = ({ track, artist }) => {
return (
<Svg width="500" height="200">
<div style={{ display: "flex", flexDirection: "column" }}>
<Text family="mono" weight="bold">
Now Playing
</Text>
<div style={{ display: "flex" }}>
<Text size="small">
{track}{' '}
</Text>
<Text size="small">
{artist}
</Text>
</div>
</div>
</Svg>
);
};
27 changes: 27 additions & 0 deletions components/Svg.tsx
@@ -0,0 +1,27 @@
import React from 'react';

const Svg = ({ width, height, children }) => {
return (
<svg
fill="none"
width={width}
height={height}
viewBox={`0 0 ${width} ${height}`}
xmlns="http://www.w3.org/2000/svg"
>
<foreignObject width={width} height={height}>
<div {...{ xmlns: "http://www.w3.org/1999/xhtml" }}>
<style>{`
* {
margin: 0;
box-sizing: border-box;
}
`}</style>
{ children }
</div>
</foreignObject>
</svg>
);
}

export default Svg;
42 changes: 42 additions & 0 deletions components/Text.tsx
@@ -0,0 +1,42 @@
import React from 'react';

const sizes = {
default: 14,
small: 12
}

const colors = {
default: "#24292e",
"gray-light": "#e1e4e8",
"gray": '#586069',
"gray-dark": "#24292e",
};


const families = {
default: "-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji",
mono: "SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace",
};

const weights = {
default: 400,
bold: 600,
};

const Text: React.FC<any> = ({ children = '', weight = 'default', family = 'default', color = 'default', size = 'default', ...props }) => {

return (
<p
style={{
fontSize: `${sizes[size]}px`,
lineHeight: 1.5,
fontFamily: families[family],
color: colors[color],
fontWeight: weights[weight]
}}>
{children}
</p>
);
};

export default Text;
30 changes: 0 additions & 30 deletions hey.svg

This file was deleted.

0 comments on commit 9623140

Please sign in to comment.