/+ - Name: SisuDoc Spine, Doc Reform [a part of] - Description: documents, structuring, processing, publishing, search - static content generator - Author: Ralph Amissah [ralph.amissah@gmail.com] - Copyright: (C) 2015 - 2024 Ralph Amissah, All Rights Reserved. - License: AGPL 3 or later: Spine (SiSU), a framework for document structuring, publishing and search Copyright (C) Ralph Amissah This program is free software: you can redistribute it and/or modify it under the terms of the GNU AFERO General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see [https://www.gnu.org/licenses/]. If you have Internet connection, the latest version of the AGPL should be available at these locations: [https://www.fsf.org/licensing/licenses/agpl.html] [https://www.gnu.org/licenses/agpl.html] - Spine (by Doc Reform, related to SiSU) uses standard: - docReform markup syntax - standard SiSU markup syntax with modified headers and minor modifications - docReform object numbering - standard SiSU object citation numbering & system - Homepages: [https://www.sisudoc.org] [https://www.doc-reform.org] - Git [https://git.sisudoc.org/] +/ /++ yaml headers
extract yaml header return struct +/ module sisudoc.meta.conf_make_meta_yaml; @safe: template contentYAMLtoSpineStruct() { import std.algorithm, std.array, std.exception, std.path, std.regex, std.stdio, std.string, std.typecons, std.utf, std.conv : to; import sisudoc.meta.conf_make_meta_structs, sisudoc.meta.defaults, sisudoc.meta.rgx_yaml, sisudoc.meta.rgx; ConfComposite _struct_composite; @system ConfComposite contentYAMLtoSpineStruct(C,Y,M,O,Cfg)( C _struct_composite, Y _yaml, M _manifested, O _opt_action, Cfg _cfg, string _identifier ) { mixin spineRgxIn; static auto rgx = RgxI(); mixin spineRgxYamlTags; static auto rgx_y = RgxYaml(); string check_input_markup()( string _txt, ) { _txt = _txt .replaceAll(regex(r"\\"), mkup.br_line_inline) .strip; return _txt; } @system string _get_yaml_node_string(Y)( Y _yaml, string _return, string _title, string _subtitle, bool _munge=false ) { if ((_title in _yaml && _yaml[_title].type.sequence) && (_yaml[_title].type.mapping && _yaml[_title].tag.match(rgx_y.yaml_tag_is_map)) ) { if (_subtitle in _yaml[_title] && _yaml[_title][_subtitle].type.string && _yaml[_title][_subtitle].tag.match(rgx_y.yaml_tag_is_str) ) { _return = (!(_munge)) ? _yaml[_title][_subtitle].get!string : check_input_markup(_yaml[_title][_subtitle].get!string); } } return _return; } @system int _get_yaml_node_int(Y)( Y _yaml, int _return, string _title, string _subtitle ) { if ((_title in _yaml && _yaml[_title].type.sequence) && (_yaml[_title].type.mapping && _yaml[_title].tag.match(rgx_y.yaml_tag_is_map)) ) { if (_subtitle in _yaml[_title] && _yaml[_title][_subtitle].type.string && _yaml[_title][_subtitle].tag.match(rgx_y.yaml_tag_is_int) ) { _return = _yaml[_title][_subtitle].get!int; } else if (_subtitle in _yaml[_title] && _yaml[_title][_subtitle].type.string && _yaml[_title][_subtitle].tag.match(rgx_y.yaml_tag_is_str) ) { _return = _yaml[_title][_subtitle].get!int; } } return _return; } confCompositeMakeBuild _mk; if (_identifier != "header") { // called only once per run anyway string _init_string; /+ conf ------------------------------------------------------------------- +/ /+ _cfg. build defaults (else program runtime defaults) local_site_configuration defaults command line overrides +/ { if (_opt_action.webserver_http.length > 0) { _struct_composite.conf.w_srv_http = _opt_action.webserver_http; } else { _init_string = (_cfg.http_request_type.empty) ? "http" : _cfg.http_request_type; _struct_composite.conf.w_srv_http = _get_yaml_node_string(_yaml, _init_string, "webserv", "http"); } if (_opt_action.cgi_search_title.length > 0) { _struct_composite.conf.w_srv_cgi_search_form_title = _opt_action.cgi_search_title; } else { _init_string = (_cfg.cgi_search_form_title.empty) ? "≅ SiSU spine search form" : _cfg.cgi_search_form_title; _struct_composite.conf.w_srv_cgi_search_form_title = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_search_form_title"); } if (_opt_action.cgi_sqlite_search_filename.length > 0) { _struct_composite.conf.w_srv_cgi_search_script = _opt_action.cgi_sqlite_search_filename; } else { _init_string = (_cfg.cgi_filename.empty) ? "spine_search" : _cfg.cgi_filename; _struct_composite.conf.w_srv_cgi_search_script = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_search_script"); } if (_opt_action.sqliteDB_filename.length > 0) { _struct_composite.conf.w_srv_db_sqlite_filename = _opt_action.sqliteDB_filename; } else { _init_string = (_cfg.db_sqlite_filename.empty) ? "spine.search.db" : _cfg.db_sqlite_filename; _struct_composite.conf.w_srv_db_sqlite_filename = _get_yaml_node_string(_yaml, _init_string, "webserv", "db_sqlite_filename"); } if (_opt_action.sqliteDB_path.length > 0) { _struct_composite.conf.w_srv_db_sqlite_path = _opt_action.sqliteDB_path; } else { _init_string = (_cfg.db_sqlite_path.empty) ? "/var/www/sqlite" : _cfg.db_sqlite_path; _struct_composite.conf.w_srv_db_sqlite_path = _get_yaml_node_string(_yaml, _init_string, "webserv", "db_sqlite_path"); } if (_opt_action.cgi_url_action.length > 0) { _struct_composite.conf.w_srv_cgi_action = _opt_action.cgi_url_action; } else { _init_string = (_cfg.www_url_doc_root.empty) ? "http://locahost" : _cfg.www_url_doc_root; // "https://sisudoc.org" _struct_composite.conf.w_srv_cgi_action = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_action"); if (_opt_action.cgi_sqlite_search_filename.length > 0) { _struct_composite.conf.w_srv_cgi_action = _struct_composite.conf.w_srv_cgi_bin_url ~ "/" ~ _opt_action.cgi_sqlite_search_filename; // not yet right } } if (!(_struct_composite.conf.output_path)) { _struct_composite.conf.output_path = ((_manifested.output.path).asNormalizedPath).array; } { if (_opt_action.output_dir_set.length > 0) { _struct_composite.conf.output_path = (_opt_action.output_dir_set.asNormalizedPath).array; } else { _struct_composite.conf.output_path = (_cfg.processing_path_doc_root.empty) ? "/srv/www/spine" : _cfg.processing_path_doc_root; if (("webserv" in _yaml && _yaml["webserv"].type.sequence) && (_yaml["webserv"].type.mapping && _yaml["webserv"].tag.match(rgx_y.yaml_tag_is_map)) ) { if (_yaml["output"].type.mapping && _yaml["output"].tag.match(rgx_y.yaml_tag_is_map) ) { if ("path" in _yaml["output"] && _yaml["output"]["path"].type.string && _yaml["output"]["path"].tag.match(rgx_y.yaml_tag_is_str) ) { if (_manifested.output.path == _manifested.env.pwd && _yaml["output"]["path"].get!string.length > 0 ) { _struct_composite.conf.output_path = (((_yaml["output"]["path"].get!string).expandTilde).asNormalizedPath).array; } } } } } if (_opt_action.webserver_host_doc_root.length > 0) { // same as output_path immediately above, resolve FIX REMOVE _struct_composite.conf.w_srv_data_root_path = _opt_action.webserver_host_doc_root; } else { _init_string = (_cfg.processing_path_doc_root.empty) ? "/var/www/spine" : _cfg.processing_path_doc_root; _struct_composite.conf.w_srv_data_root_path = _get_yaml_node_string(_yaml, _init_string, "webserv", "data_root_path"); } } if (_opt_action.cgi_bin_root.length > 0) { _struct_composite.conf.w_srv_cgi_bin_path = _opt_action.cgi_bin_root; } else { _init_string = (_cfg.cgi_bin_root.empty) ? "/var/www/cgi/cgi-bin" : _cfg.cgi_bin_root; _struct_composite.conf.w_srv_cgi_bin_path = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_bin_path"); } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "data_root_part"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_data_root_part = _init_string; } } { _init_string = "image"; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "images_root_part"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_images_root_part = _init_string; } } } if (("webserv" in _yaml && _yaml["webserv"].type.sequence) && (_yaml["webserv"].type.mapping && _yaml["webserv"].tag.match(rgx_y.yaml_tag_is_map)) ) { // cannot be used as is with opt_action FIX look at remaining, decide what to do later { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "data_http"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_data_http = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_http"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_cgi_http = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "host"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_host = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_bin_subpath"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_cgi_bin_subpath = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_port"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_cgi_port = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_user"); if (!(_init_string.empty)) { _struct_composite.conf.w_srv_cgi_user = _init_string; } } if ("data_root_url" in _yaml["webserv"] && _yaml["webserv"]["data_root_url"].type.string && _yaml["webserv"]["data_root_url"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.conf.w_srv_data_root_url = _yaml["webserv"]["data_root_url"].get!string; _struct_composite.conf.w_srv_data_root_url_html = _yaml["webserv"]["data_root_url"].get!string ~ _struct_composite.conf.w_srv_data_root_part ~ "/" ~ _manifested.src.language ~ "/" ~ "html"; } else { _struct_composite.conf.w_srv_data_root_url = _struct_composite.conf.w_srv_data_root_part; _struct_composite.conf.w_srv_data_root_url_html = _struct_composite.conf.w_srv_data_root_part ~ "/" ~ _manifested.src.language ~ "/" ~ "html"; } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "webserv", "cgi_host"); _struct_composite.conf.w_srv_cgi_host = (!(_init_string.empty)) ? _init_string : _struct_composite.conf.w_srv_host; } if ("cgi_bin_url" in _yaml["webserv"] && _yaml["webserv"]["cgi_bin_url"].type.string && _yaml["webserv"]["cgi_bin_url"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.conf.w_srv_cgi_bin_url = _yaml["webserv"]["cgi_bin_url"].get!string; } else { _struct_composite.conf.w_srv_cgi_bin_url = (_struct_composite.conf.w_srv_cgi_http.empty) ? _struct_composite.conf.w_srv_http :_struct_composite.conf.w_srv_cgi_http ~ "://" ~ (_struct_composite.conf.w_srv_cgi_host.empty) ? _struct_composite.conf.w_srv_cgi_host : _struct_composite.conf.w_srv_host ~ _struct_composite.conf.w_srv_cgi_bin_subpath; } // if ("cgi_file_links" in _yaml["webserv"] // && _yaml["webserv"]["cgi_file_links"].type.string // && _yaml["webserv"]["cgi_file_links"].tag.match(rgx_y.yaml_tag_is_str) // ) { // _struct_composite.conf.w_srv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; // } } // make (in: conf, make, meta)? { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "processing", "concord_max"); if (!(_init_string.empty)) { _struct_composite.conf.processing_concord_max = _init_string; } } if ("flag" in _yaml && _yaml["flag"].type.sequence ) { if (_yaml["flag"].type.mapping && _yaml["flag"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act0"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act0 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act1"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act1 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act2"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act2 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act3"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act3 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act4"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act4 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act5"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act5 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act6"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act6 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act7"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act7 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act8"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act8 = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "flag", "act9"); if (!(_init_string.empty)) { _struct_composite.conf.flag_act9 = _init_string; } } } } string[] selected_papersize(string _sizes_str) { string[] _sizes = _sizes_str.split(regex(r"\s*,\s*")); string[] _selected_sizes; foreach (_size; _sizes) { switch (_size) { case "a4": _selected_sizes ~= "a4.portrait"; _selected_sizes ~= "a4.landscape"; break; case "a4.portrait": _selected_sizes ~= _size; break; case "a4.landscape": _selected_sizes ~= _size; break; case "b4": _selected_sizes ~= "b4.portrait"; _selected_sizes ~= "b4.landscape"; break; case "b4.portrait": _selected_sizes ~= _size; break; case "b4.landscape": _selected_sizes ~= _size; break; case "a5": _selected_sizes ~= "a5.portrait"; _selected_sizes ~= "a5.landscape"; break; case "a5.portrait": _selected_sizes ~= _size; break; case "a5.landscape": _selected_sizes ~= _size; break; case "letter": _selected_sizes ~= "letter.portrait"; _selected_sizes ~= "letter.landscape"; break; case "letter.portrait": _selected_sizes ~= _size; break; case "letter.landscape": _selected_sizes ~= _size; break; case "legal": _selected_sizes ~= "legal.portrait"; _selected_sizes ~= "legal.landscape"; break; case "legal.portrait": _selected_sizes ~= _size; break; case "legal.landscape": _selected_sizes ~= _size; break; default: break; } } return _selected_sizes; } string _set_papersize; if (_opt_action.latex_papersize.length > 0) { _set_papersize = _opt_action.latex_papersize; } else { _set_papersize = (_cfg.default_papersize.empty) ? "a4,letter.portrait" : _cfg.default_papersize; _init_string = _set_papersize; _init_string = _get_yaml_node_string(_yaml, _init_string, "default", "papersize"); if (!(_init_string.empty)) { _set_papersize = _init_string; } } _struct_composite.conf.set_papersize = selected_papersize(_set_papersize); if ( "default" in _yaml && _yaml["default"].type.sequence && _yaml["default"].type.mapping && _yaml["default"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "default", "text_wrap"); if (!(_init_string.empty)) { _struct_composite.conf.set_text_wrap = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "default", "emphasis"); if (!(_init_string.empty)) { _struct_composite.conf.set_emphasis = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "default", "language"); if (!(_init_string.empty)) { _struct_composite.conf.set_language = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "default", "digest"); if (!(_init_string.empty)) { _struct_composite.conf.set_digest = _init_string; } } } if ("search" in _yaml && _yaml["search"].type.sequence ) { if (_yaml["search"].type.mapping && _yaml["search"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "search", "flag"); if (!(_init_string.empty)) { _struct_composite.conf.search_flag = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "search", "action"); if (!(_init_string.empty)) { _struct_composite.conf.search_action = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "search", "db"); if (!(_init_string.empty)) { _struct_composite.conf.search_db = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "search", "title"); if (!(_init_string.empty)) { _struct_composite.conf.search_title = _init_string; } } } } } else { // !(_identifier != "header") string _init_string; int _init_int; /+ make ------------------------------------------------------------------- +/ if ("make" in _yaml && _yaml["make"].type.sequence ) { if (_yaml["make"].type.mapping && _yaml["make"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "doc_type"); if (!(_init_string.empty)) { _struct_composite.make_str.doc_type = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "breaks"); if (!(_init_string.empty)) { _struct_composite.make_str.breaks = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "bold"); if (!(_init_string.empty)) { _struct_composite.make_str.bold = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "cover_image"); if (!(_init_string.empty)) { _struct_composite.make_str.cover_image = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "css"); if (!(_init_string.empty)) { _struct_composite.make_str.css = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "make", "emphasis"); if (!(_init_string.empty)) { _struct_composite.make_str.emphasis = _init_string; } } if ("footer" in _yaml["make"] && _yaml["make"]["footer"].type.string && _yaml["make"]["footer"].tag.match(rgx_y.yaml_tag_is_str) ) { char[][] __match_footer_array = (cast(char[]) _yaml["make"]["footer"].get!string) .split(rgx.make_heading_delimiter); foreach(string hbt; __match_footer_array.to!(string[])) { _struct_composite.make_str.footer ~= url_markup(hbt); } } else if ("footer" in _yaml["make"] && _yaml["make"]["footer"].type.string && _yaml["make"]["footer"].tag.match(rgx_y.yaml_tag_is_seq) ) { _struct_composite.make_str.footer = []; foreach(string hbt; _yaml["make"]["footer"]) { _struct_composite.make_str.footer ~= url_markup(hbt); } } if ("headings" in _yaml["make"] && _yaml["make"]["headings"].type.string && _yaml["make"]["headings"].tag.match(rgx_y.yaml_tag_is_str) ) { char[][] __match_headings_array = (cast(char[]) _yaml["make"]["headings"].get!string) .split(rgx.make_heading_delimiter); _struct_composite.make_str.headings = __match_headings_array.to!(string[]); } else if ("headings" in _yaml["make"] && _yaml["make"]["headings"].type.string && _yaml["make"]["headings"].tag.match(rgx_y.yaml_tag_is_seq) ) { foreach(string identify_heading_level; _yaml["make"]["headings"]) { _struct_composite.make_str.headings ~= identify_heading_level; } } if ("home_button_image" in _yaml["make"] && _yaml["make"]["home_button_image"].type.string && _yaml["make"]["home_button_image"].tag.match(rgx_y.yaml_tag_is_str) ) { char[][] __match_home_button_image_array = (cast(char[]) _yaml["make"]["home_button_image"].get!string) .split(rgx.make_heading_delimiter); _struct_composite.make_str.home_button_image = __match_home_button_image_array.to!(string[]); } if ("home_button_text" in _yaml["make"] && _yaml["make"]["home_button_text"].type.string && _yaml["make"]["home_button_text"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.make_str.home_button_text = _yaml["make"]["home_button_text"].get!string; } else if ("home_button_text" in _yaml["make"] && _yaml["make"]["home_button_text"].type.string && _yaml["make"]["home_button_text"].tag.match(rgx_y.yaml_tag_is_seq) ) { _struct_composite.make_str.home_button_text = ""; foreach(string hbt; _yaml["make"]["home_button_text"]) { _struct_composite.make_str.home_button_text ~= hbt ~ "; "; } } if ("italics" in _yaml["make"] && _yaml["make"]["italics"].type.string && _yaml["make"]["italics"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.make_str.italics = _yaml["make"]["italics"].get!string; } if ("auto_num_top_at_level" in _yaml["make"] && _yaml["make"]["auto_num_top_at_level"].type.string && _yaml["make"]["auto_num_top_at_level"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.make_str.auto_num_top_at_level = _yaml["make"]["auto_num_top_at_level"].get!string; switch (_yaml["make"]["auto_num_top_at_level"].get!string) { case "A": break; case "B": _struct_composite.make_str.auto_num_top_lv = 1; break; case "C": _struct_composite.make_str.auto_num_top_lv = 2; break; case "D": _struct_composite.make_str.auto_num_top_lv = 3; break; case "1": _struct_composite.make_str.auto_num_top_lv = 4; break; case "2": _struct_composite.make_str.auto_num_top_lv = 5; break; case "3": _struct_composite.make_str.auto_num_top_lv = 6; break; case "4": _struct_composite.make_str.auto_num_top_lv = 7; break; default: break; } } { _init_int = _get_yaml_node_int(_yaml, 99, "make", "auto_num_depth"); if (!(_init_int == 99)) { _struct_composite.make_str.auto_num_depth = _init_int; } } if ("texpdf_font" in _yaml["make"] && _yaml["make"]["texpdf_font"].type.string ) { _struct_composite.make_str.texpdf_font = _yaml["make"]["texpdf_font"].get!string; } } _struct_composite.make.doc_type = _mk.doc_type(_struct_composite.make_str.doc_type); _struct_composite.make.breaks = _mk.breaks(_struct_composite.make_str.breaks); _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); _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 = _mk.emphasis(_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 = _mk.italics(_struct_composite.make_str.italics); _struct_composite.make.auto_num_top_at_level = _mk.auto_num_top_at_level(_struct_composite.make_str.auto_num_top_at_level); _struct_composite.make.auto_num_top_lv = _mk.auto_num_top_lv(_struct_composite.make_str.auto_num_top_lv); _struct_composite.make.auto_num_depth = _mk.auto_num_depth(_struct_composite.make_str.auto_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); } /+ meta ------------------------------------------------------------------- +/ if (_struct_composite.meta.creator_author.empty) { if ("creator" in _yaml && _yaml["creator"].type.sequence ) { if (_yaml["creator"].type.mapping && _yaml["creator"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "creator", "author"); if (!(_init_string.empty)) { _struct_composite.meta.creator_author = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "creator", "email"); if (!(_init_string.empty)) { _struct_composite.meta.creator_author_email = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "creator", "illustrator"); if (!(_init_string.empty)) { _struct_composite.meta.creator_illustrator = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "creator", "translator"); if (!(_init_string.empty)) { _struct_composite.meta.creator_translator = _init_string; } } } else if (_yaml["creator"].type.string && _yaml["creator"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.meta.creator_author = _yaml["creator"].get!string; } } string[] author_arr; string[][string] authors_hash_arr = [ "first" : [], "last" : [], "full" : [], "last_first" : [], "as_input" : [] ]; string[] authors_raw_arr = _struct_composite.meta.creator_author.split(rgx.arr_delimiter); auto _lastname = appender!(char[])(); foreach (author_raw; authors_raw_arr) { if (auto m = author_raw.match(rgx.raw_author_munge)) { author_arr ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); authors_hash_arr["first"] ~= author_raw.replace(rgx.raw_author_munge, "$2"); authors_hash_arr["last"] ~= author_raw.replace(rgx.raw_author_munge, "$1"); authors_hash_arr["full"] ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); (m.captures[1]).map!toUpper.copy(_lastname); authors_hash_arr["last_first"] ~= _lastname.data.to!string ~ ", " ~ m.captures[2]; _lastname = appender!(char[])(); } else { author_arr ~= author_raw; authors_hash_arr["last"] ~= author_raw; authors_hash_arr["full"] ~= author_raw; authors_hash_arr["last_first"] ~= author_raw; } authors_hash_arr["as_input"] ~= author_raw; } _struct_composite.meta.creator_author_arr = author_arr; _struct_composite.meta.creator_author = author_arr.join(", ").chomp.chomp; _struct_composite.meta.creator_author_surname = (authors_hash_arr["last"].length > 0) ? authors_hash_arr["last"][0] : ""; string _author_name_last_first = authors_hash_arr["last_first"].join("; ").chomp.chomp; _struct_composite.meta.creator_author_surname_fn = (_author_name_last_first.length > 0) ? _author_name_last_first : authors_hash_arr["as_input"].join("; ").chomp.chomp; } if (_struct_composite.meta.title_main.empty) { if ("title" in _yaml && _yaml["title"].type.sequence ) { if (_yaml["title"].type.mapping && _yaml["title"].tag.match(rgx_y.yaml_tag_is_map) ) { if ("main" in _yaml["title"] && _yaml["title"]["main"].type.string && _yaml["title"]["main"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.meta.title_main = _yaml["title"]["main"].get!string; } else if ("title" in _yaml["title"] && _yaml["title"]["title"].type.string && _yaml["title"]["title"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.meta.title_main = _yaml["title"]["title"].get!string; } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "edition"); if (!(_init_string.empty)) { _struct_composite.meta.title_edition = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "full"); if (!(_init_string.empty)) { _struct_composite.meta.title_full = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "language"); if (!(_init_string.empty)) { _struct_composite.meta.title_language = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "note"); if (!(_init_string.empty)) { _struct_composite.meta.title_note = _init_string; } } if ("subtitle" in _yaml["title"]) { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "subtitle"); if (!(_init_string.empty)) { _struct_composite.meta.title_subtitle = _init_string; } } else if ("sub" in _yaml["title"]) { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "title", "sub"); if (!(_init_string.empty)) { _struct_composite.meta.title_subtitle = _init_string; } } } else if (_yaml["title"].type.string && _yaml["title"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.meta.title_main = _yaml["title"].get!string; } } _struct_composite.meta.title_sub = _struct_composite.meta.title_subtitle; 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_subtitle.empty) ? _struct_composite.meta.title_main : format( "%s - %s", _struct_composite.meta.title_main, _struct_composite.meta.title_subtitle, ); } if ("classify" in _yaml && _yaml["classify"].type.sequence ) { if (_yaml["classify"].type.mapping && _yaml["classify"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "classify", "dewey"); if (!(_init_string.empty)) { _struct_composite.meta.classify_dewey = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "classify", "loc"); if (!(_init_string.empty)) { _struct_composite.meta.classify_loc = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "classify", "keywords"); if (!(_init_string.empty)) { _struct_composite.meta.classify_keywords = _init_string; } } if ("topic_register" in _yaml["classify"] && _yaml["classify"]["topic_register"].type.string && _yaml["classify"]["topic_register"].tag.match(rgx_y.yaml_tag_is_str) ) { _struct_composite.meta.classify_topic_register = _yaml["classify"]["topic_register"].get!string; if (_struct_composite.meta.classify_topic_register.length > 0) { auto wrds = ctRegex!(`([\wa-zA-Z(). -]+)`); // ctRegex!(`([(]?\w+[a-zA-Z(). -]*)+`); auto mkp_delim = ctRegex!(`:([^:]+?)(;|$)`); string _topic_register = _struct_composite.meta.classify_topic_register; _topic_register = _topic_register .replaceAll(wrds, "\"$1\"") .replaceAll(mkp_delim, ":$1$2"); } string[] main_topics_ = _struct_composite.meta.classify_topic_register.strip.split(rgx.topic_register_main_terms_split); string[] topics; string topics_tmp; string[] multiple_sub_terms; foreach (mt; main_topics_) { topics_tmp = mt.replaceAll(rgx.topic_register_main_term_plus_rest_split, mkup.sep); if (auto m = topics_tmp.match(rgx.topic_register_multiple_sub_terms_split)) { multiple_sub_terms = m.captures[1].split(rgx.topic_register_sub_terms_split); foreach (subterm; multiple_sub_terms) { topics ~= m.captures.pre ~ mkup.sep ~ subterm; } } else { topics ~= topics_tmp; } } _struct_composite.meta.classify_topic_register_arr = topics; string[] topics_expanded; if (_struct_composite.meta.classify_topic_register_arr.length > 0) { foreach (i, topic; _struct_composite.meta.classify_topic_register_arr) { string[] subject_tree = topic.split(mkup.sep); if (topic.length > 0) { topics_expanded ~= subject_tree.join(", "); } } } _struct_composite.meta.classify_topic_register_expanded_arr = topics_expanded; // writeln("\n------\n", _struct_composite.meta.title_full); // writeln(_struct_composite.meta.classify_topic_register); // writeln(_struct_composite.meta.classify_topic_register_expanded_arr.sort.join("\n")); // writeln(_struct_composite.meta.classify_topic_register_arr); } } } if ("date" in _yaml && _yaml["date"].type.sequence ) { if (_yaml["date"].type.mapping && _yaml["date"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "added_to_site"); if (!(_init_string.empty)) { _struct_composite.meta.date_added_to_site = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "available"); if (!(_init_string.empty)) { _struct_composite.meta.date_available = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "created"); if (!(_init_string.empty)) { _struct_composite.meta.date_created = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "issued"); if (!(_init_string.empty)) { _struct_composite.meta.date_issued = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "modified"); if (!(_init_string.empty)) { _struct_composite.meta.date_modified = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "published"); if (!(_init_string.empty)) { _struct_composite.meta.date_published = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "date", "valid"); if (!(_init_string.empty)) { _struct_composite.meta.date_valid = _init_string; } } } } _struct_composite.meta.language_document_char = _manifested.src.language; // move if ("links" in _yaml) { // if ("" in _yaml["links"]) { // _struct_composite.meta.links_ = _yaml["links"][""].str; // } } if ("notes" in _yaml && _yaml["notes"].type.sequence ) { if (_yaml["notes"].type.mapping && _yaml["notes"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "notes", "abstract"); if (!(_init_string.empty)) { _struct_composite.meta.notes_abstract = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "notes", "description"); if (!(_init_string.empty)) { _struct_composite.meta.notes_description = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "notes", "summary"); if (!(_init_string.empty)) { _struct_composite.meta.notes_summary = _init_string; } } } } if ("original" in _yaml && _yaml["original"].type.sequence ) { if (_yaml["original"].type.mapping && _yaml["original"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "original", "language"); if (!(_init_string.empty)) { _struct_composite.meta.original_language = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "original", "language_char"); if (!(_init_string.empty)) { _struct_composite.meta.original_language_char = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "original", "source"); if (!(_init_string.empty)) { _struct_composite.meta.original_source = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "original", "title"); if (!(_init_string.empty)) { _struct_composite.meta.original_title = _init_string; } } } } if ("publisher" in _yaml) { // if ("" in _yaml["publisher"]) { // _struct_composite.meta.publisher = _yaml["publisher"][""].str; // } } if ("rights" in _yaml && _yaml["rights"].type.sequence ) { if (_yaml["rights"].type.mapping && _yaml["rights"].tag.match(rgx_y.yaml_tag_is_map) ) { { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright", true); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_text"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_text = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_audio"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_audio = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_cover"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_cover = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_illustrations"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_illustrations = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_photographs"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_photographs = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_translation"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_translation = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "copyright_video"); if (!(_init_string.empty)) { _struct_composite.meta.rights_copyright_video = _init_string; } } { _init_string = ""; _init_string = _get_yaml_node_string(_yaml, _init_string, "rights", "license", true); if (!(_init_string.empty)) { _struct_composite.meta.rights_license = _init_string; } } } } } return _struct_composite; } } template configParseYAMLreturnSpineStruct() { import dyaml; import sisudoc.meta.conf_make_meta_structs, sisudoc.meta.conf_make_meta_json; mixin contentYAMLtoSpineStruct; @system ConfComposite configParseYAMLreturnSpineStruct(T,M,O,Cfg)( T _document_struct, ConfComposite _make_and_meta_struct, M _manifested, O _opt_action, Cfg _cfg ){ Node _yaml; if (_document_struct.content.length > 0) { try { _yaml = Loader.fromString(_document_struct.content).load(); } catch (Throwable) { import std.stdio; writeln("ERROR failed to parse content as yaml: ", _document_struct.filename); // writeln(_document_struct.content); } try { _make_and_meta_struct = contentYAMLtoSpineStruct!()(_make_and_meta_struct, _yaml, _manifested, _opt_action, _cfg, _document_struct.filename); } catch (Throwable) { import std.stdio; writeln("ERROR failed to convert yaml to struct: ", _document_struct.filename); } } return _make_and_meta_struct; } } template docHeaderMakeAndMetaTupYamlExtractAndConvertToStruct() { import std.exception, std.regex, std.stdio, // std.traits, std.typecons, std.utf, std.conv : to; import dyaml; import sisudoc.meta.conf_make_meta_structs, sisudoc.meta.conf_make_meta_json, sisudoc.meta.rgx_yaml, sisudoc.meta.rgx; mixin spineRgxIn; mixin contentJSONtoSpineStruct; static auto rgx = RgxI(); mixin spineRgxYamlTags; static auto rgx_y = RgxYaml(); @system ConfComposite docHeaderMakeAndMetaTupYamlExtractAndConvertToStruct(Src,M,O,Cfg)( Src header_src, ConfComposite _make_and_meta_struct, M _manifested, O _opt_action, Cfg _cfg, ) { Node _yaml; try { _yaml = Loader.fromString(header_src).load(); if (("title" in _yaml) && ("creator" in _yaml)) {} else { // need test for _yaml content (does not work) writeln("ERROR failed to read document header, yaml header does not contain essential information related to title and author"); } return contentYAMLtoSpineStruct!()(_make_and_meta_struct, _yaml, _manifested, _opt_action, _cfg, "header"); } catch (Throwable) { writeln("ERROR failed to read document header, header not parsed as yaml: ", _manifested.src.filename); return _make_and_meta_struct; } } }