aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/meta/conf_make_meta_json.d
blob: 0471dbf2de0f2cb55d5b2ca7b40d383c31699624 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/++
  json headers<BR>
  extract json header return json
+/
module sdp.meta.conf_make_meta_json;
static template contentJSONtoSiSUstruct() {
  import
    std.exception,
    std.regex,
    std.stdio,
    std.string,
    std.traits,
    std.typecons,
    std.utf,
    std.conv : to;
  import
    sdp.meta.conf_make_meta_structs,
    sdp.meta.conf_make_meta_json,
    sdp.meta.rgx;
  ConfCompositePlus _struct_composite;
  auto contentJSONtoSiSUstruct(C, J)(C _struct_composite, J _json, string _identifier) {
    mixin SiSUrgxInit;
    static auto _rgx = Rgx();
    debug (json) {
      writeln(">> --------------------------- >>");
      foreach (tag0; _json.object.byKeyValue) {
        if (tag0.value.stringof == "string") {
          writeln(tag0.key, ": ", tag0.value);
        } else {
          // writeln(tag0.key, ":");
          foreach (tag1; tag0.value.object.byKeyValue) {
            writeln(tag0.key, ":", tag1.key, ": ", tag1.value);
          }
        }
      }
      writeln("<< --------------------------- <<");
    }
    confCompositeMakeBuild _mk;
    /+ make ------------------------------------------------------------------- +/
    if ("make" in _json.object) {
      if ("bold" in _json.object["make"]) {
        _struct_composite.make_str.bold  = _json.object["make"]["bold"].str;
      }
      if ("breaks" in _json.object["make"]) {
        _struct_composite.make_str.breaks  = _json.object["make"]["breaks"].str;
      }
      if ("cover_image" in _json.object["make"]) {
        _struct_composite.make_str.cover_image  = _json.object["make"]["cover_image"].str;
      }
      if ("css" in _json.object["make"]) {
        _struct_composite.make_str.css  = _json.object["make"]["css"].str;
      }
      if ("emphasis" in _json.object["make"]) {
        _struct_composite.make_str.emphasis  = _json.object["make"]["emphasis"].str;
      }
      if ("footer" in _json.object["make"]) {
        _struct_composite.make_str.footer  = _json.object["make"]["footer"].str;
      }
      if ("headings" in _json.object["make"]) {
        _struct_composite.make_str.headings  = _json.object["make"]["headings"].str;
      }
      if ("home_button_image" in _json.object["make"]) {
        _struct_composite.make_str.home_button_image  = _json.object["make"]["home_button_image"].str;
      }
      if ("home_button_text" in _json.object["make"]) {
        _struct_composite.make_str.home_button_text  = _json.object["make"]["home_button_text"].str;
      }
      if ("italics" in _json.object["make"]) {
        _struct_composite.make_str.italics  = _json.object["make"]["italics"].str;
      }
      if ("num_top" in _json.object["make"]) {
        _struct_composite.make_str.num_top  = _json.object["make"]["num_top"].str;
      }
      if ("num_depth" in _json.object["make"]) {
        _struct_composite.make_str.num_depth  = _json.object["num_depth"][""].str;
      }
      if ("substitute" in _json.object["make"]) {
        _struct_composite.make_str.substitute  = _json.object["make"]["substitute"].arrayNoRef;
      }
      if ("texpdf_font" in _json.object["make"]) {
        _struct_composite.make_str.texpdf_font  = _json.object["make"]["texpdf_font"].str;
      }
      _struct_composite.make.bold_rgxmatch                  = _mk.bold_rgxmatch(_struct_composite.make_str.bold);
      _struct_composite.make.breaks                         = _mk.breaks(_struct_composite.make_str.breaks);
      _struct_composite.make.cover_image                    = _mk.cover_image(_struct_composite.make_str.cover_image);
      _struct_composite.make.css                            = _mk.css(_struct_composite.make_str.css);
      _struct_composite.make.emphasis_rgxmatch              = _mk.emphasis_rgxmatch(_struct_composite.make_str.emphasis);
      _struct_composite.make.footer                         = _mk.footer(_struct_composite.make_str.footer);
      _struct_composite.make.headings                       = _mk.headings(_struct_composite.make_str.headings);
      _struct_composite.make.home_button_image              = _mk.home_button_image(_struct_composite.make_str.home_button_image);
      _struct_composite.make.home_button_text               = _mk.home_button_text(_struct_composite.make_str.home_button_text);
      _struct_composite.make.italics_rgxmatch               = _mk.italics_rgxmatch(_struct_composite.make_str.italics);
      _struct_composite.make.num_top                        = _mk.num_top(_struct_composite.make_str.num_top);
      _struct_composite.make.num_depth                      = _mk.num_depth(_struct_composite.make_str.num_depth);
      _struct_composite.make.substitute                     = _mk.substitute(_struct_composite.make_str.substitute);
      _struct_composite.make.texpdf_font                    = _mk.texpdf_font(_struct_composite.make_str.texpdf_font);
    }
    /+ conf ------------------------------------------------------------------- +/
    if ("webserv" in _json.object) {
      if ("url_root" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_url_root = _json.object["webserv"]["url_root"].str;
      }
      if ("path" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_path = _json.object["webserv"]["path"].str;
      }
      if ("images" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_images = _json.object["webserv"]["images"].str;
      }
      if ("cgi" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi = _json.object["webserv"]["cgi"].str;
      }
      if ("cgi_host" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi_host = _json.object["webserv"]["cgi_host"].str;
      }
      if ("cgi_host_path" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str;
      }
      if ("cgi_port" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi_port = _json.object["webserv"]["cgi_port"].str;
      }
      if ("cgi_user" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi_user = _json.object["webserv"]["cgi_user"].str;
      }
      if ("cgi_file_links" in _json.object["webserv"]) {
        _struct_composite.conf.webserv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str;
      }
    }
    if ("processing" in _json.object) { // TODO check & match logic with sdlang
      if ("path" in _json.object["processing"]) {
        _struct_composite.conf.processing_path = _json.object["processing"]["path"].str;
      }
      if ("dir" in _json.object["processing"]) {
        _struct_composite.conf.processing_dir = _json.object["processing"]["dir"].str;
      }
      if ("concord_max" in _json.object["processing"]) {
        _struct_composite.conf.processing_concord_max = _json.object["processing"]["concord_max"].str;
      }
    }
    if ("flag" in _json.object) {
      if ("act0" in _json.object["flag"]) {
        _struct_composite.conf.flag_act0 = _json.object["flag"]["act0"].str;
      }
      if ("act1" in _json.object["flag"]) {
        _struct_composite.conf.flag_act1 = _json.object["flag"]["act1"].str;
      }
      if ("act2" in _json.object["flag"]) {
        _struct_composite.conf.flag_act2 = _json.object["flag"]["act2"].str;
      }
      if ("act3" in _json.object["flag"]) {
        _struct_composite.conf.flag_act3 = _json.object["flag"]["act3"].str;
      }
      if ("act4" in _json.object["flag"]) {
        _struct_composite.conf.flag_act4 = _json.object["flag"]["act4"].str;
      }
      if ("act5" in _json.object["flag"]) {
        _struct_composite.conf.flag_act5 = _json.object["flag"]["act5"].str;
      }
      if ("act6" in _json.object["flag"]) {
        _struct_composite.conf.flag_act6 = _json.object["flag"]["act6"].str;
      }
      if ("act7" in _json.object["flag"]) {
        _struct_composite.conf.flag_act7 = _json.object["flag"]["act7"].str;
      }
      if ("act8" in _json.object["flag"]) {
        _struct_composite.conf.flag_act8 = _json.object["flag"]["act8"].str;
      }
      if ("act9" in _json.object["flag"]) {
        _struct_composite.conf.flag_act9 = _json.object["flag"]["act9"].str;
      }
    }
    if ("default" in _json.object) {
      if ("papersize" in _json.object["default"]) {
        _struct_composite.conf.default_papersize = _json.object["default"]["papersize"].str;
      }
      if ("text_wrap" in _json.object["default"]) {
        _struct_composite.conf.default_text_wrap = _json.object["default"]["text_wrap"].str;
      }
      if ("emphasis" in _json.object["default"]) {
        _struct_composite.conf.default_emphasis = _json.object["default"]["emphasis"].str;
      }
      if ("language" in _json.object["default"]) {
        _struct_composite.conf.default_language = _json.object["default"]["language"].str;
      }
      if ("digest" in _json.object["default"]) {
        _struct_composite.conf.default_digest = _json.object["default"]["digest"].str;
      }
    }
    if ("search" in _json.object) {
      if ("flag" in _json.object["search"]) {
        _struct_composite.conf.search_flag = _json.object["search"]["flag"].str;
      }
      if ("action" in _json.object["search"]) {
        _struct_composite.conf.search_action = _json.object["search"]["action"].str;
      }
      if ("db" in _json.object["search"]) {
        _struct_composite.conf.search_db = _json.object["search"]["db"].str;
      }
      if ("title" in _json.object["search"]) {
        _struct_composite.conf.search_title = _json.object["search"]["title"].str;
      }
    }
    /+ meta ------------------------------------------------------------------- +/
    if ("classify" in _json.object) {
      if ("dewey" in _json.object["classify"]) {
        _struct_composite.meta.classify_dewey = _json.object["classify"]["dewey"].str;
      }
      if ("keywords" in _json.object["classify"]) {
        _struct_composite.meta.classify_keywords = _json.object["classify"]["keywords"].str;
      }
      if ("loc" in _json.object["classify"]) {
        _struct_composite.meta.classify_loc = _json.object["classify"]["loc"].str;
      }
      if ("subject" in _json.object["classify"]) {
        _struct_composite.meta.classify_subject = _json.object["classify"]["subject"].str;
      }
      if ("topic_register" in _json.object["classify"]) {
        _struct_composite.meta.classify_topic_register = _json.object["classify"]["topic_register"].str;
      }
    }
    if ("date" in _json.object) {
      if ("added_to_site" in _json.object["date"]) {
        _struct_composite.meta.date_added_to_site = _json.object["date"]["added_to_site"].str;
      }
      if ("available" in _json.object["date"]) {
        _struct_composite.meta.date_available = _json.object["date"]["available"].str;
      }
      if ("created" in _json.object["date"]) {
        _struct_composite.meta.date_created = _json.object["date"]["created"].str;
      }
      if ("issued" in _json.object["date"]) {
        _struct_composite.meta.date_issued = _json.object["date"]["issued"].str;
      }
      if ("modified" in _json.object["date"]) {
        _struct_composite.meta.date_modified = _json.object["date"]["modified"].str;
      }
      if ("published" in _json.object["date"]) {
        _struct_composite.meta.date_published = _json.object["date"]["published"].str;
      }
      if ("valid" in _json.object["date"]) {
        _struct_composite.meta.date_valid = _json.object["date"]["valid"].str;
      }
    }
    if ("links" in _json.object) {
      // if ("" in _json.object["links"]) {
      //   _struct_composite.meta.links_ = _json.object["links"][""].str;
      // }
    }
    if ("notes" in _json.object) {
      if ("abstract" in _json.object["notes"]) {
        _struct_composite.meta.notes_abstract = _json.object["notes"]["abstract"].str;
      }
      if ("description" in _json.object["notes"]) {
        _struct_composite.meta.notes_description = _json.object["notes"]["description"].str;
      }
    }
    if ("original" in _json.object) {
      if ("language" in _json.object["original"]) {
        _struct_composite.meta.original_language = _json.object["original"]["language"].str;
      }
      if ("language_char" in _json.object["original"]) {
        _struct_composite.meta.original_language_char = _json.object["original"]["language_char"].str;
      }
      if ("source" in _json.object["original"]) {
        _struct_composite.meta.original_source = _json.object["original"]["source"].str;
      }
      if ("title" in _json.object["original"]) {
        _struct_composite.meta.original_title = _json.object["original"]["title"].str;
      }
    }
    if ("publisher" in _json.object) {
      // if ("" in _json.object["publisher"]) {
      //   _struct_composite.meta.publisher = _json.object["publisher"][""].str;
      // }
    }
    if ("rights" in _json.object) {
      if ("copyright" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright = _json.object["rights"]["copyright"].str;
      }
      if ("copyright_text" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_text = _json.object["rights"]["copyright_text"].str;
      }
      if ("copyright_audio" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_audio = _json.object["rights"]["copyright_audio"].str;
      }
      if ("copyright_cover" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_cover = _json.object["rights"]["copyright_cover"].str;
      }
      if ("copyright_illustrations" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_illustrations = _json.object["rights"]["copyright_illustrations"].str;
      }
      if ("copyright_photographs" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_photographs = _json.object["rights"]["copyright_photographs"].str;
      }
      if ("copyright_translation" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_translation = _json.object["rights"]["copyright_translation"].str;
      }
      if ("copyright_video" in _json.object["rights"]) {
        _struct_composite.meta.rights_copyright_video = _json.object["rights"]["copyright_video"].str;
      }
      if ("license" in _json.object["rights"]) {
        _struct_composite.meta.rights_license = _json.object["rights"]["license"].str;
      }
    }
    if (_struct_composite.meta.creator_author.empty) {
      if ("creator" in _json.object) {
        if ("author" in _json.object["creator"]) {
          _struct_composite.meta.creator_author = _json.object["creator"]["author"].str;
        }
        if ("email" in _json.object["creator"]) {
          _struct_composite.meta.creator_author_email = _json.object["creator"]["email"].str;
        }
        if ("illustrator" in _json.object["creator"]) {
          _struct_composite.meta.creator_illustrator = _json.object["creator"]["illustrator"].str;
        }
        if ("translator" in _json.object["creator"]) {
          _struct_composite.meta.creator_translator = _json.object["creator"]["translator"].str;
        }
      }
      // dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"];
      string[] authors_arr;
      auto authors_raw_arr = _struct_composite.meta.creator_author.split(_rgx.arr_delimiter);
      foreach (author_raw; authors_raw_arr) {
        authors_arr ~= author_raw.replace(_rgx.raw_author_munge, "$2 $1");
      }
      _struct_composite.meta.creator_author = join(authors_arr, ", ").chomp.chomp;
    }
    if (_struct_composite.meta.title_main.empty) {
      if ("title" in _json.object) {
        if ((_json.object["title"].type().to!string) == "STRING") {
          _struct_composite.meta.title_main                     = _json.object["title"].str;
        } else {
          if ("edition" in _json.object["title"]) {
            _struct_composite.meta.title_edition                = _json.object["title"]["edition"].str;
          }
          if ("full" in _json.object["title"]) {
            // _struct_composite.meta.title_full                  = _json.object["title"]["full"].str;
          }
          if ("language" in _json.object["title"]) {
            _struct_composite.meta.title_language               = _json.object["title"]["language"].str;
          }
          if ("main" in _json.object["title"]) {
            _struct_composite.meta.title_main                   = _json.object["title"]["main"].str;
          }
          if ("note" in _json.object["title"]) {
            _struct_composite.meta.title_note                   = _json.object["title"]["note"].str;
          }
          if ("sub" in _json.object["title"]) {
            _struct_composite.meta.title_sub                    = _json.object["title"]["sub"].str;
          }
          if ("subtitle" in _json.object["title"]) {
            _struct_composite.meta.title_subtitle               = _json.object["title"]["subtitle"].str;
          }
        }
      }
      if ((!(_struct_composite.meta.title_subtitle.empty))
      && (_struct_composite.meta.title_sub.empty)) {
        _struct_composite.meta.title_sub = _struct_composite.meta.title_subtitle;
      }
      _struct_composite.meta.title_full = (_struct_composite.meta.title_sub.empty)
      ? _struct_composite.meta.title_main
      : format(
          "%s - %s",
          _struct_composite.meta.title_main,
          _struct_composite.meta.title_sub,
        );
    }
    return _struct_composite;
  }
}