Files: 90f1fa10f4cf1eadad9cd3539872fd71cc183030 / components / post-link.js
1128 bytesRaw
1 | import Link from 'next/link'; |
2 | import ta from 'time-ago'; |
3 | import { |
4 | string, |
5 | bool |
6 | } from 'prop-types'; |
7 | |
8 | const PostLink = ({ href, date, lang, download, filename, children }) => { |
9 | const link = ( |
10 | <div className="post"> |
11 | { |
12 | date && ( |
13 | <span className="post-date">{ |
14 | `${ta.ago(date)} (${date})` |
15 | }</span> |
16 | ) |
17 | } |
18 | <a href={ href } title={ children } { ...(download && { download: filename }) } className="post-title"> |
19 | { |
20 | lang && `(${lang}) ` |
21 | } |
22 | { children } |
23 | </a> |
24 | |
25 | <style jsx global>{` |
26 | .post-date { |
27 | color: #757575; |
28 | display: block; |
29 | font-size: 16px; |
30 | margin-bottom: 2px; |
31 | } |
32 | .post-title { |
33 | font-size: 17px; |
34 | } |
35 | `}</style> |
36 | </div> |
37 | ); |
38 | |
39 | if (download) { |
40 | return link; |
41 | } |
42 | |
43 | return ( |
44 | <Link href={ href }> |
45 | { link } |
46 | </Link> |
47 | ); |
48 | }; |
49 | |
50 | PostLink.propTypes = { |
51 | href: string.isRequired, |
52 | date: string, |
53 | lang: string, |
54 | download: bool, |
55 | filename: string |
56 | }; |
57 | |
58 | PostLink.defaultProps = { |
59 | download: false |
60 | }; |
61 | |
62 | export default PostLink; |
Built with git-ssb-web