git ssb

0+

Dominic / weather



Commit 7538828ea2f1694c9e4e6f1d065f859360a1b4bc

render tides, and link to archives

Dominic Tarr committed on 1/9/2016, 6:12:04 AM
Parent: 9acabd88b8682ddfd3065792011536c9cd7a54bb

Files changed

server.jschanged
server.jsView
@@ -17,37 +17,49 @@
1717 return '<div id=content>'+marked(md(data))+'</div>'
1818 }
1919
2020 function capitalize (n) {
21- return n[0].toUpperCase() + n.substring(1)
21 + return n[0].toUpperCase() + n.substring(1).toLowerCase()
2222 }
2323 function log (e) {
2424 console.log(e)
2525 return e
2626 }
27 +
2728 function sections (text) {
2829 return log(text.split(/([\w\s]+):/).map(function (e, i) {
2930 if(!(i%2)) return e + '\n\n'
3031 if(/\s/.test(e.trim())) return '### ' + e
3132 else return '#### ' + e
3233 })).join('\n')
3334 }
3435
36 +function renderTides(tides) {
37 + return tides.map(function (e) {
38 + return '### ' + capitalize(e.location) + '\n' +
39 + e.tides.map(function (tide) {
40 + return '* ' + tide.height + 'm at ' + tide.time
41 + }).join('\n')
42 + }).join('\n\n')
43 +}
44 +
3545 function get(key, format, res, next) {
3646 db.sublevel('raw').get(key, function (err, value) {
3747 if(err) return next(err)
3848 res.end(render(value, format, function (e) {
3949 return [
4050 '# ' + capitalize(value.name),
41- 'issued at: ' + value.issued,
51 + 'issued at: [' + value.issued +'](/ls/'+value.name+')',
4252 '## Situation',
4353 e.situation,
4454 '## Forecast',
4555 sections(e.forecast),
4656 '## Outlook',
4757 sections(e.outlook),
4858 '## Swell',
49- e.swell
59 + e.swell,
60 + '## Tides',
61 + renderTides(e.tides)
5062 ].join('\n')
5163 }))
5264 })
5365 }

Built with git-ssb-web