Files: 05da29162cd94001b87a1366246df608c8a7fa4d / components / post-link.js
1076 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, 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 } 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 | }; |
56 | |
57 | PostLink.defaultProps = { |
58 | download: false |
59 | }; |
60 | |
61 | export default PostLink; |
Built with git-ssb-web