Browse Source

add date formating

axolotle 2 years ago
parent
commit
f7081d0514
2 changed files with 13 additions and 1 deletions
  1. 6 1
      src/store/nodes.js
  2. 7 0
      src/store/utils.js

+ 6 - 1
src/store/nodes.js

@@ -7,7 +7,8 @@ import {
   VARIANT_IDS,
   RELATIONS,
   reduceQueryIds,
-  reduceQueryLevels
+  reduceQueryLevels,
+  formatDate
 } from '@/store/utils'
 import {
   AllNodesOfVariant
@@ -40,6 +41,10 @@ export default {
           node.variant = [{ id: 0 }]
         }
 
+        if (node.date) {
+          node.date.start = formatDate(node.date.start)
+        }
+
         if (node.images && node.images.length) {
           const { url, alt, id } = node.images[0]
           node.image = { alt, id, url: url.replace('api', 'api/sites/default/files') }

+ 7 - 0
src/store/utils.js

@@ -1,6 +1,8 @@
 import { hierarchy } from 'd3-hierarchy'
 
 
+const dateFormatter = new Intl.DateTimeFormat('fr-FR', { month: 'long', year: 'numeric' })
+
 export const RELATIONS = [
   'parents',
   'siblings',
@@ -32,6 +34,11 @@ export const VARIANT_IDS = Object.fromEntries(
 export const SEARCH_KEYS = ['content', 'title', 'preTitle', 'authors']
 
 
+export function formatDate (date) {
+  return dateFormatter.format(new Date(date))
+}
+
+
 export function parseNodesQueryParams ({ mode, nodes = [] }) {
   let nodebook = typeof nodes === 'string' ? [nodes] : nodes
   nodebook = nodebook.map(ids => {