Skip to content

Commit 7a8f2d3

Browse files
pierreneterfhemberger
authored andcommitted
Get data from google doc for Announcements (#1332)
* Get data from google doc for Announcements * layouts/announcements.hbs: Use JS standard style * remove yarn.lock * Update in-the-news.hbs * Update announcements.hbs
1 parent 3549310 commit 7a8f2d3

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

build.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,21 @@ function buildLocale (source, locale) {
170170
strftime: require('./scripts/helpers/strftime.js'),
171171
apidocslink: require('./scripts/helpers/apidocslink.js'),
172172
majorapidocslink: require('./scripts/helpers/majorapidocslink.js'),
173-
summary: require('./scripts/helpers/summary.js')
173+
summary: require('./scripts/helpers/summary.js'),
174+
json: function (context) {
175+
return JSON.stringify(context)
176+
},
177+
getListJson: function (context) {
178+
var result = context.map(function (item) {
179+
return {
180+
title: item.title,
181+
date: item.date,
182+
local: true,
183+
path: item.path.replace(/\\/, '/')
184+
}
185+
})
186+
return JSON.stringify(result)
187+
}
174188
}
175189
}))
176190
// Pipes the generated files into their respective subdirectory in the build

layouts/announcements.hbs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,77 @@
1111
{{> navigation key='foundation'}}
1212

1313
<article>
14-
<div class="container no-headline">
15-
14+
<div class="container no-headline" id="announcements-list">
1615
<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>
2517
</ul>
26-
2718
</div>
2819
</article>
29-
3020
</div>
3121
</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+
})
3272
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>
3385
{{> footer }}
3486
</body>
3587
</html>

layouts/in-the-news.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<article>
1616
<div class="container no-headline">
1717
<ul class="news-list">
18+
<li>Loading data...</li>
1819
</ul>
1920
</div>
2021
</article>

0 commit comments

Comments
 (0)