-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestions.ts
43 lines (38 loc) · 1.36 KB
/
questions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { unique } from '../helpers'
import { DEFAULT_LANGUAGE } from './language'
import { questionsByDate } from './questionsByDate'
import { Tag } from './tags'
export interface Question {
question: string
index: number
deepness: number
date: string
tags?: Tag[]
author?: string
}
export const questions: Question[] = Object.entries( questionsByDate )
.sort( ( a, b ) => ( a[0] <= b[0] ? -1 : 1 ) )
.flatMap( ( [ date, questionsInDate ], iDate, arr ) => {
const p = arr.slice( 0, iDate ).map( e => e[1].length ).reduce( ( acc, cur ) => acc + cur, 0 )
return questionsInDate.map( ( q, iQ ) => {
const questionsObject: Question = {
question: q.translations[DEFAULT_LANGUAGE],
index: iQ + p,
deepness: q.deepness,
date: date,
tags: q.tags,
author: q.author
}
if ( q.author ) {
if ( questionsObject.tags ) questionsObject.tags.push( 'hasAuthor' )
else questionsObject.tags = [ 'hasAuthor' ]
}
return questionsObject
}
)
} )
.sort( ( a, b ) => b.index - a.index )
const possibleDeepnessLevels = questions.map( e => e.deepness ).filter( unique ).sort()
export const minDeepness = Math.min( ...possibleDeepnessLevels )
export const maxDeepness = Math.max( ...possibleDeepnessLevels )
export const allTags = questions.flatMap( e => e.tags || [] ).filter( unique )