Add new icon for snippets less than 31 days old (#104)

This commit is contained in:
atomiks
2018-10-05 14:11:08 +10:00
committed by GitHub
parent a9234afee0
commit 8c397b1348
8 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,7 @@ const pretty = require('pretty')
const caniuseDb = require('caniuse-db/data.json')
const sass = require('node-sass')
const { toKebabCase, createElement, template, dom, getCode } = require('../utils/utils.js')
const { differenceInDays } = require('date-fns')
const SNIPPETS_PATH = './snippets'
const TAGS = [
@ -115,6 +116,21 @@ for (const snippetFile of fs.readdirSync(SNIPPETS_PATH)) {
}</a>`
)
// new icon = less than 31 days old
const date = (snippetData.match(/<!--\s*date:\s*(.+?)-->/) || [, ''])[1]
if (date && differenceInDays(new Date(date), new Date()) < 31) {
snippetEl.prepend(
createElement(
'<img alt="New" draggable="false" class="snippet__new" src="./src/img/new.svg">'
)
)
link.prepend(
createElement(
'<img alt="New" draggable="false" class="sidebar__new" src="./src/img/new.svg">'
)
)
}
// tags
const tags = (snippetData.match(/<!--\s*tags:\s*(.+?)-->/) || [, ''])[1]
.split(/,\s*/)