Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get data from google doc for Announcements #1332

Merged
merged 6 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,21 @@ function buildLocale (source, locale) {
strftime: require('./scripts/helpers/strftime.js'),
apidocslink: require('./scripts/helpers/apidocslink.js'),
majorapidocslink: require('./scripts/helpers/majorapidocslink.js'),
summary: require('./scripts/helpers/summary.js')
summary: require('./scripts/helpers/summary.js'),
json: function (context) {
return JSON.stringify(context)
},
getListJson: function (context) {
var result = context.map(function (item) {
return {
title: item.title,
date: item.date,
local: true,
path: item.path.replace(/\\/, '/')
}
})
return JSON.stringify(result)
}
}
}))
// Pipes the generated files into their respective subdirectory in the build
Expand Down
76 changes: 64 additions & 12 deletions layouts/announcements.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,77 @@
{{> navigation key='foundation'}}

<article>
<div class="container no-headline">

<div class="container no-headline" id="announcements-list">
<ul class="news-list">
{{#each collections.blogAnnounce}}
{{#if title}}
<li>
<time datetime="{{ date }}">{{ strftime date }}</time>
<a href="/{{../site.locale}}/{{ path }}/">{{ title }}</a>
</li>
{{/if}}
{{/each}}
<li>Loading data...</li>
</ul>

</div>
</article>

</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.4.2/tabletop.min.js"></script>
<script type="text/javascript">
var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/1xwQ6ciZLADL43My_XBIWLVRuDMl8cx_omYd1FRkBZ58/pubhtml'
var mdList = {{{getListJson collections.blogAnnounce}}}
var siteLocal = '/{{site.locale}}/'

window.onload = function () {
/* global Tabletop */
Tabletop.init(
{
key: publicSpreadsheetUrl,
callback: showInfo,
simpleSheet: true
}
)

function pad (str) { return ('0' + str).substr(-2) }

function parseDate (date) {
try {
var parsedDate = date.split('.')
return new Date('20' + parsedDate[2], parsedDate[0] - 1, parsedDate[1])
} catch (_) {
return date
}
}

function formatDate (date) {
return date === 'Invalid Date' ? '' : date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate())
}

function showInfo (data, tabletop) {
data.reverse()
var html = ''
var list = document.getElementsByClassName('news-list')
var docList = []

data.forEach(function (row) {
docList.push({
path: row.Link,
title: row.Title,
local: false,
date: parseDate(row.Date)
})
})

var allList = mdList.concat(docList)
allList.sort(function (a, b) {
return new Date(b.date).getTime() - new Date(a.date).getTime()
})

allList.forEach(function (row) {
if (row && row.date) {
html += '<li><time datetime="' + row.date + '">' + formatDate(new Date(row.date)) + '</time>'
html += '<a href="'
html += (row.local) ? siteLocal + row.path : row.path
html += '">' + row.title + '</a></li>'
}
})
if (list && list[0]) list[0].innerHTML = html
}
}
</script>
{{> footer }}
</body>
</html>
1 change: 1 addition & 0 deletions layouts/in-the-news.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<article>
<div class="container no-headline">
<ul class="news-list">
<li>Loading data...</li>
</ul>
</div>
</article>
Expand Down