|
11 | 11 | {{> navigation key='foundation'}} |
12 | 12 |
|
13 | 13 | <article> |
14 | | - <div class="container no-headline"> |
15 | | - |
| 14 | + <div class="container no-headline" id="announcements-list"> |
16 | 15 | <ul class="news-list"> |
17 | | - {{#each collections.blogAnnounce}} |
18 | | - {{#if title}} |
19 | | - <li> |
20 | | - <time datetime="{{ date }}">{{ strftime date }}</time> |
21 | | - <a href="/{{../site.locale}}/{{ path }}/">{{ title }}</a> |
22 | | - </li> |
23 | | - {{/if}} |
24 | | - {{/each}} |
| 16 | + <li>Loading data...</li> |
25 | 17 | </ul> |
26 | | - |
27 | 18 | </div> |
28 | 19 | </article> |
29 | | - |
30 | 20 | </div> |
31 | 21 | </div> |
| 22 | + <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.4.2/tabletop.min.js"></script> |
| 23 | + <script type="text/javascript"> |
| 24 | + var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/1xwQ6ciZLADL43My_XBIWLVRuDMl8cx_omYd1FRkBZ58/pubhtml' |
| 25 | + var mdList = {{{getListJson collections.blogAnnounce}}} |
| 26 | + var siteLocal = '/{{site.locale}}/' |
| 27 | +
|
| 28 | + window.onload = function () { |
| 29 | + /* global Tabletop */ |
| 30 | + Tabletop.init( |
| 31 | + { |
| 32 | + key: publicSpreadsheetUrl, |
| 33 | + callback: showInfo, |
| 34 | + simpleSheet: true |
| 35 | + } |
| 36 | + ) |
| 37 | +
|
| 38 | + function pad (str) { return ('0' + str).substr(-2) } |
| 39 | +
|
| 40 | + function parseDate (date) { |
| 41 | + try { |
| 42 | + var parsedDate = date.split('.') |
| 43 | + return new Date('20' + parsedDate[2], parsedDate[0] - 1, parsedDate[1]) |
| 44 | + } catch (_) { |
| 45 | + return date |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + function formatDate (date) { |
| 50 | + return date === 'Invalid Date' ? '' : date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) |
| 51 | + } |
| 52 | +
|
| 53 | + function showInfo (data, tabletop) { |
| 54 | + data.reverse() |
| 55 | + var html = '' |
| 56 | + var list = document.getElementsByClassName('news-list') |
| 57 | + var docList = [] |
| 58 | +
|
| 59 | + data.forEach(function (row) { |
| 60 | + docList.push({ |
| 61 | + path: row.Link, |
| 62 | + title: row.Title, |
| 63 | + local: false, |
| 64 | + date: parseDate(row.Date) |
| 65 | + }) |
| 66 | + }) |
| 67 | +
|
| 68 | + var allList = mdList.concat(docList) |
| 69 | + allList.sort(function (a, b) { |
| 70 | + return new Date(b.date).getTime() - new Date(a.date).getTime() |
| 71 | + }) |
32 | 72 |
|
| 73 | + allList.forEach(function (row) { |
| 74 | + if (row && row.date) { |
| 75 | + html += '<li><time datetime="' + row.date + '">' + formatDate(new Date(row.date)) + '</time>' |
| 76 | + html += '<a href="' |
| 77 | + html += (row.local) ? siteLocal + row.path : row.path |
| 78 | + html += '">' + row.title + '</a></li>' |
| 79 | + } |
| 80 | + }) |
| 81 | + if (list && list[0]) list[0].innerHTML = html |
| 82 | + } |
| 83 | + } |
| 84 | + </script> |
33 | 85 | {{> footer }} |
34 | 86 | </body> |
35 | 87 | </html> |
0 commit comments