diff --git a/assets/javascripts/templates/pages/news_tmpl.coffee.erb b/assets/javascripts/templates/pages/news_tmpl.coffee.erb index f6760a61..18f829e2 100644 --- a/assets/javascripts/templates/pages/news_tmpl.coffee.erb +++ b/assets/javascripts/templates/pages/news_tmpl.coffee.erb @@ -1,36 +1,46 @@ -#= depend_on news.json - -app.templates.newsPage = -> - """

Changelog

-

- For the latest news, follow @DevDocs.
- For development updates, follow the project on GitHub. -

#{app.templates.newsList app.news}
""" - -app.templates.newsList = (news, options = {}) -> - year = new Date().getUTCFullYear() - result = '' - - for value in news - date = new Date(value[0]) - if options.years isnt false and year isnt date.getUTCFullYear() - year = date.getUTCFullYear() - result += """

#{year}

""" - result += newsItem(date, value[1..]) - - result - -MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] - -newsItem = (date, news) -> - date = """#{MONTHS[date.getUTCMonth()]} #{date.getUTCDate()}""" - result = '' - - for text, i in news - text = text.split "\n" - title = """#{text.shift()}""" - result += """
#{if i is 0 then date else ''} #{title} #{text.join '
'}
""" - - result +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md + */ +//= depend_on news.json + +app.templates.newsPage = () => `

Changelog

+

+For the latest news, follow @DevDocs.
+For development updates, follow the project on GitHub. +

${app.templates.newsList(app.news)}
`; + +app.templates.newsList = function(news, options = {}) { + let year = new Date().getUTCFullYear(); + let result = ''; + + for (let value of news) { + const date = new Date(value[0]); + if ((options.years !== false) && (year !== date.getUTCFullYear())) { + year = date.getUTCFullYear(); + result += `

${year}

`; + } + result += newsItem(date, value.slice(1)); + } + + return result; +}; + +const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; + +var newsItem = function(date, news) { + date = `${MONTHS[date.getUTCMonth()]} ${date.getUTCDate()}`; + let result = ''; + + for (let i = 0; i < news.length; i++) { + let text = news[i]; + text = text.split("\n"); + const title = `${text.shift()}`; + result += `
${i === 0 ? date : ''} ${title} ${text.join('
')}
`; + } + + return result; +}; app.news = <%= App.news.to_json %>