1
0
Fork 0
Browse Source

feat: add copyright partial and story.

This required my first filter! Using the `| date` filter, I can format a
date object using `date-fns` library, which is also pretty slim.

Since I like this library, logging will be done with `loglevel`.
This way, I can create a logging server down the road.

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
main
André Jaenisch 1 year ago
parent
commit
80b4a2b3e4
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 21
      filters/date.js
  2. 4
      filters/index.js
  3. 13
      logger.js
  4. 18
      package-lock.json
  5. 3
      package.json
  6. 4
      partials/copyright.njk
  7. 49
      stories/atoms/copyright.stories.mdx

21
filters/date.js

@ -0,0 +1,21 @@
const { format } = require('date-fns')
const log = require('../logger')
const logger = log.getLogger('helpers:dmy-date')
function date (dateObj, formatString) {
if (!dateObj) {
return ''
}
try {
const then = new Date(dateObj)
return format(then, formatString)
} catch (e) {
logger.debug('Could not format date %s => %o', dateObj, e)
return ''
}
}
module.exports = date

4
filters/index.js

@ -1,5 +1,7 @@
// Nunjucks filters are going to be added here
const dateFilter = require('./date')
const filters = [
{ name: 'date', value: dateFilter },
]
module.exports = filters

13
logger.js

@ -0,0 +1,13 @@
const log = require('loglevel')
const prefix = require('loglevel-plugin-prefix')
prefix.reg(log)
log.enableAll()
prefix.apply(log, {
format (level, name, timestamp) {
return `[${timestamp}] ${level.toUpperCase()} ${name}:`
}
})
module.exports = log

18
package-lock.json generated

@ -5571,6 +5571,12 @@
"integrity": "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=",
"dev": true
},
"date-fns": {
"version": "2.22.1",
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.22.1.tgz",
"integrity": "sha512-yUFPQjrxEmIsMqlHhAhmxkuH769baF21Kk+nZwZGyrMoyLA+LugaQtC0+Tqf9CBUUULWwUJt6Q5ySI3LJDDCGg==",
"dev": true
},
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
@ -8524,6 +8530,18 @@
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
"dev": true
},
"loglevel": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.1.tgz",
"integrity": "sha512-Hesni4s5UkWkwCGJMQGAh71PaLUmKFM60dHvq0zi/vDhhrzuk+4GgNbTXJ12YYQJn6ZKBDNIjYcuQGKudvqrIw==",
"dev": true
},
"loglevel-plugin-prefix": {
"version": "0.8.4",
"resolved": "https://registry.npmjs.org/loglevel-plugin-prefix/-/loglevel-plugin-prefix-0.8.4.tgz",
"integrity": "sha512-WpG9CcFAOjz/FtNht+QJeGpvVl/cdR6P0z6OcXSkr8wFJOsV2GRj2j10JLfjuA4aYkcKCNIEqRGCyTife9R8/g==",
"dev": true
},
"loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",

3
package.json

@ -8,7 +8,10 @@
"@storybook/addon-essentials": "^6.2.9",
"@storybook/addon-links": "^6.2.9",
"@storybook/html": "^6.2.9",
"date-fns": "^2.22.1",
"gray-matter": "^4.0.3",
"loglevel": "^1.7.1",
"loglevel-plugin-prefix": "^0.8.4",
"nunjucks": "^3.2.3",
"nunjucks-loader": "^3.0.0",
"storybook-addon-outline": "^1.3.4",

4
partials/copyright.njk

@ -0,0 +1,4 @@
<p>
&copy; 2013 - {{ globals.today | date('yyyy') }}
<a rel="me" href="https://jaenis.ch/" class="h-card">André Jaenisch</a>
</p>

49
stories/atoms/copyright.stories.mdx

@ -0,0 +1,49 @@
import { Canvas, Meta, Story } from '@storybook/addon-docs/blocks';
import template from '../../partials/copyright.njk';
export const Template = (args = {}) => template.render(args)
<Meta
title='Atoms/Copyright'
argTypes={{
globals: {
controls: {
type: 'date',
},
description: 'A copyright line.',
name: 'Copyright',
},
}}
/>
## Copyright
This shows the copyright line from the beginning until the current year.
The importance is on `rel="me"` which allows for [IndieAuth](https://indieweb.org/IndieAuth) of this website.
<Canvas>
<Story
name='Copyright'
args={{
globals: {
today: new Date()
},
}}
parameters={{
controls: {
expanded: true,
hideNoControlsWarning: true,
},
docs: {
source: {
code: Template(),
},
},
}}
>
{Template.bind()}
</Story>
</Canvas>
Loading…
Cancel
Save