You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/templates/pages/news_tmpl.coffee.erb

40 lines
1.6 KiB

#= depend_on news.json
app.templates.newsPage = ->
""" <h1 class="_lined-heading">Changelog</h1>
<p class="_note">
For the latest news, follow <a href="https://twitter.com/DevDocs">@DevDocs</a>.<br>
For development updates, follow the project on <a href="https://github.com/freeCodeCamp/devdocs">GitHub</a>.
<div class="_news">#{app.templates.newsList app.news}</div> """
app.templates.newsList = (news, options = {}) ->
year = new Date().getUTCFullYear()
result = ''
for value in news
date = new Date(value.date)
if options.years isnt false and year isnt date.getUTCFullYear()
year = date.getUTCFullYear()
result += """<h2 class="_block-heading">#{year}</h2>"""
result += newsItem(date, value)
result
MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
newsItem = (date, news) ->
date = """<span class="_news-date">#{MONTHS[date.getUTCMonth()]} #{date.getUTCDate()}</span>"""
text = if news.text then news.text.split "\n" else []
if news.added
links = (linkForSlug n for n in news.added)
text.push """New #{if links.length > 1 then 'documentations' else 'documentation'}: #{links.join ', '}"""
title = """<span class="_news-title">#{text.shift()}</span>"""
result = """<div class="_news-row">#{date} #{title} #{text.join '<br>'}</div>"""
result
linkForSlug = (slug) ->
doc = app.docs.findBySlug(slug) or app.disabledDocs.findBySlug(slug)
if doc then """<a href="/#{slug}/">#{doc.name}</a>""" else ""
app.news = <%= App.news.to_json %>