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

6
package-lock.json generated
View File

@ -2558,6 +2558,12 @@
"assert-plus": "^1.0.0" "assert-plus": "^1.0.0"
} }
}, },
"date-fns": {
"version": "1.29.0",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz",
"integrity": "sha512-lbTXWZ6M20cWH8N9S6afb0SBm6tMk+uUg6z3MqHPKE9atmsY3kJkTm8vKe93izJ2B2+q5MV990sM2CHgtAZaOw==",
"dev": true
},
"date-now": { "date-now": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",

View File

@ -21,6 +21,7 @@
"babel-preset-env": "^1.6.1", "babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.24.1", "babel-preset-stage-2": "^6.24.1",
"caniuse-db": "^1.0.30000813", "caniuse-db": "^1.0.30000813",
"date-fns": "^1.29.0",
"jsdom": "^11.6.2", "jsdom": "^11.6.2",
"marked": "^0.3.16", "marked": "^0.3.16",
"node-sass": "^4.9.3", "node-sass": "^4.9.3",

View File

@ -5,6 +5,7 @@ const pretty = require('pretty')
const caniuseDb = require('caniuse-db/data.json') const caniuseDb = require('caniuse-db/data.json')
const sass = require('node-sass') const sass = require('node-sass')
const { toKebabCase, createElement, template, dom, getCode } = require('../utils/utils.js') const { toKebabCase, createElement, template, dom, getCode } = require('../utils/utils.js')
const { differenceInDays } = require('date-fns')
const SNIPPETS_PATH = './snippets' const SNIPPETS_PATH = './snippets'
const TAGS = [ const TAGS = [
@ -115,6 +116,21 @@ for (const snippetFile of fs.readdirSync(SNIPPETS_PATH)) {
}</a>` }</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 // tags
const tags = (snippetData.match(/<!--\s*tags:\s*(.+?)-->/) || [, ''])[1] const tags = (snippetData.match(/<!--\s*tags:\s*(.+?)-->/) || [, ''])[1]
.split(/,\s*/) .split(/,\s*/)

View File

@ -51,3 +51,4 @@ The parent must have a viewport height. `flex-grow: 1` could be applied to the f
- https://caniuse.com/#feat=flexbox - https://caniuse.com/#feat=flexbox
<!-- tags: layout --> <!-- tags: layout -->
<!-- date: 2018-09-30 -->

View File

@ -69,3 +69,4 @@ This effect is styling only the `<label>` element to look like a toggle switch,
- https://caniuse.com/#feat=transforms2d - https://caniuse.com/#feat=transforms2d
<!-- tags: visual, interactivity --> <!-- tags: visual, interactivity -->
<!-- date: 2018-10-03 -->

View File

@ -71,6 +71,12 @@
color: #e3f5ff; color: #e3f5ff;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
} }
&__new {
width: 1.25rem;
vertical-align: middle;
margin-right: 0.25rem;
}
} }
@media (min-width: 992px) { @media (min-width: 992px) {

View File

@ -119,6 +119,14 @@
&__tag { &__tag {
} }
&__new {
position: absolute;
top: -1rem;
left: 50%;
transform: translateX(-50%);
width: 3rem;
}
} }
.snippet-demo { .snippet-demo {

1
src/img/new.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB