@@ -5,79 +5,100 @@ const rawData = fs.readFileSync('./../../data/sessionize.json');
55const template = fs . readFileSync ( 'template.svg' , { encoding : 'utf-8' } ) ;
66const data = JSON . parse ( rawData ) ;
77
8-
98// banner-logo
10- execSync ( `"C:\\Program Files\\Inkscape\\bin\\inkscape" --export-filename "png/banner-logo.png" --export-type "png" "logo.svg"` , ( error , stdout , stderr ) => {
9+ execSync (
10+ `"C:\\Program Files\\Inkscape\\bin\\inkscape" --export-filename "png/banner-logo.png" --export-type "png" "logo.svg"` ,
11+ ( error , stdout , stderr ) => {
1112 console . log ( ' ' , error , stdout , stderr ) ;
12- } ) ;
13-
13+ }
14+ ) ;
1415
1516for ( let session of data . sessions ) {
16- try {
17- console . log ( session . title ) ;
18-
19- // title
20- let words = session . title . split ( ' ' ) ;
21- let chars = 0 ;
22- let title1 = '' ;
23- let title2 = '' ;
17+ try {
18+ console . log ( session . title ) ;
2419
25- for ( let word of words ) {
26- if ( chars + word . length < 90 && ! title2 ) {
27- if ( title1 ) {
28- title1 += ' ' ;
29- chars ++ ;
30- }
20+ // title
21+ let words = session . title . split ( ' ' ) ;
22+ let chars = 0 ;
23+ let title1 = '' ;
24+ let title2 = '' ;
3125
32- title1 += word ;
33- chars += word . length ;
34- } else {
35- if ( title2 ) {
36- title2 += ' ' ;
37- chars ++ ;
38- }
39-
40- title2 += word ;
41- chars += word . length ;
42- }
26+ for ( let word of words ) {
27+ if ( chars + word . length < 90 && ! title2 ) {
28+ if ( title1 ) {
29+ title1 += ' ' ;
30+ chars ++ ;
4331 }
4432
45- let svg = template . replace ( '{{title1}}' , title1 . replace ( '&' , '&' ) ) ;
46- svg = svg . replace ( '{{title2}}' , title2 . replace ( '&' , '&' ) ) ;
47-
33+ title1 += word ;
34+ chars += word . length ;
35+ } else {
4836 if ( title2 ) {
49- svg = svg . replace ( '{{bannerHeight}}' , 210 ) ;
50- svg = svg . replace ( '{{bannerY}}' , 1080 - 210 ) ;
51- svg = svg . replace ( '{{title1Y}}' , 930 ) ;
52- svg = svg . replace ( '{{title2Y}}' , 980 ) ;
53- } else {
54- svg = svg . replace ( '{{bannerHeight}}' , 160 ) ;
55- svg = svg . replace ( '{{bannerY}}' , 1080 - 160 ) ;
56- svg = svg . replace ( '{{title1Y}}' , 980 ) ;
57- svg = svg . replace ( '{{title2Y}}' , 980 ) ;
37+ title2 += ' ' ;
38+ chars ++ ;
5839 }
5940
60- // speaker
61- const answers = session . questionAnswers ;
62- let shortTitle = answers . find ( q => q . questionId === 71787 ) . answerValue ;
41+ title2 += word ;
42+ chars += word . length ;
43+ }
44+ }
6345
64- const speakers = session . speakers . map ( speakerId => data . speakers . find ( s => s . id === speakerId ) ) ;
65- const room = data . rooms . find ( s => s . id === session . roomId ) . name ;
66- let speakersText = speakers . sort ( ( a , b ) => a . lastName > b . lastName ? 1 : - 1 ) . map ( s => s . firstName + ' ' + s . lastName + ( s . tagLine && speakers . length === 1 ? ', ' + s . tagLine : '' ) ) . join ( ', ' ) ;
67- if ( speakers . length > 1 && shortTitle === 'dwh-porsche' ) {
68- speakersText += ' (Porsche Holding Salzburg)' ;
69- }
70- speakersText = speakersText . replace ( / \& / , '&' ) ;
71- svg = svg . replace ( '{{speakers}}' , speakersText ) ;
46+ let svg = template . replace ( '{{title1}}' , title1 . replace ( '&' , '&' ) ) ;
47+ svg = svg . replace ( '{{title2}}' , title2 . replace ( '&' , '&' ) ) ;
48+
49+ if ( title2 ) {
50+ svg = svg . replace ( '{{bannerHeight}}' , 210 ) ;
51+ svg = svg . replace ( '{{bannerY}}' , 1080 - 210 ) ;
52+ svg = svg . replace ( '{{title1Y}}' , 930 ) ;
53+ svg = svg . replace ( '{{title2Y}}' , 980 ) ;
54+ } else {
55+ svg = svg . replace ( '{{bannerHeight}}' , 160 ) ;
56+ svg = svg . replace ( '{{bannerY}}' , 1080 - 160 ) ;
57+ svg = svg . replace ( '{{title1Y}}' , 980 ) ;
58+ svg = svg . replace ( '{{title2Y}}' , 980 ) ;
59+ }
7260
73- // save
74- fs . writeFileSync ( './svg/' + shortTitle + '.svg' , svg , { encoding : 'utf-8' } ) ;
61+ // speaker
62+ const answers = session . questionAnswers ;
63+ let shortTitle = answers . find ( ( q ) => q . questionId === 71787 ) . answerValue ;
7564
76- // convert to png
77- execSync ( `"C:\\Program Files\\Inkscape\\bin\\inkscape" --export-filename "png/${ room } - ${ ( new Date ( session . startsAt ) ) . getHours ( ) } -00 - ${ shortTitle } .png" --export-type "png" "svg\\${ shortTitle } .svg"` , ( error , stdout , stderr ) => {
78- console . log ( ' ' , error , stdout , stderr ) ;
79- } ) ;
80- } catch ( e ) {
81- console . log ( 'error' , e )
65+ const speakers = session . speakers . map ( ( speakerId ) =>
66+ data . speakers . find ( ( s ) => s . id === speakerId )
67+ ) ;
68+ const room = data . rooms . find ( ( s ) => s . id === session . roomId ) . name ;
69+ let speakersText = speakers
70+ . sort ( ( a , b ) => ( a . lastName > b . lastName ? 1 : - 1 ) )
71+ . map (
72+ ( s ) =>
73+ s . firstName +
74+ ' ' +
75+ s . lastName +
76+ ( s . tagLine && speakers . length === 1 ? ', ' + s . tagLine : '' )
77+ )
78+ . join ( ', ' ) ;
79+ if ( speakers . length > 1 && shortTitle === 'dwh-porsche' ) {
80+ speakersText += ' (Porsche Holding Salzburg)' ;
8281 }
82+ speakersText = speakersText . replace ( / \& / , '&' ) ;
83+ svg = svg . replace ( '{{speakers}}' , speakersText ) ;
84+
85+ // save
86+ fs . writeFileSync ( './svg/' + shortTitle + '.svg' , svg , {
87+ encoding : 'utf-8' ,
88+ } ) ;
89+
90+ // convert to png
91+ execSync (
92+ `"C:\\Program Files\\Inkscape\\bin\\inkscape" --export-filename "png/${ room } - ${ new Date (
93+ session . startsAt
94+ ) . getHours ( ) } -${ new Date (
95+ session . startsAt
96+ ) . getMinutes ( ) } - ${ shortTitle } .png" --export-type "png" "svg\\${ shortTitle } .svg"`,
97+ ( error , stdout , stderr ) => {
98+ console . log ( ' ' , error , stdout , stderr ) ;
99+ }
100+ ) ;
101+ } catch ( e ) {
102+ console . log ( 'error' , e ) ;
103+ }
83104}
0 commit comments