template SiSUpod() { private import std.algorithm, std.array, std.container, std.digest.sha, std.exception, std.file, std.getopt, std.json, std.outbuffer, std.path, std.process, std.range, std.regex, std.stdio, std.string, std.traits, std.typecons, std.uni, std.utf, std.zip, std.conv : to; import create_zip_file, defaults, output_rgx, output_xhtmls; void SiSUpod(T)(T doc_matters) { debug(asserts) { // static assert(is(typeof(doc_matters) == tuple)); } mixin SiSUoutputRgxInit; mixin SiSUpaths; auto pth_sisupod = SiSUpodPathsZipped(); auto pth_sisupod_filesystem = SiSUpodPathsFilesystemArchive(); mixin SiSUlanguageCodes; auto lang = Lang(); auto rgx = Rgx(); assert (doc_matters.source_filename.match(rgx.src_fn)); try { /+ create directory structure +/ if (!exists(pth_sisupod_filesystem.doc(doc_matters.source_filename))) { pth_sisupod_filesystem.doc(doc_matters.source_filename).mkdirRecurse; } if (!exists(pth_sisupod_filesystem.conf(doc_matters.source_filename))) { pth_sisupod_filesystem.conf(doc_matters.source_filename).mkdirRecurse; } if (!exists(pth_sisupod_filesystem.css(doc_matters.source_filename))) { pth_sisupod_filesystem.css(doc_matters.source_filename).mkdirRecurse; } if (!exists(pth_sisupod_filesystem.image(doc_matters.source_filename))) { pth_sisupod_filesystem.image(doc_matters.source_filename).mkdirRecurse; } if (!exists(pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language))) { pth_sisupod_filesystem.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse; } debug(sisupod) { writeln(__LINE__, ": ", doc_matters.source_filename, " -> ", pth_sisupod_filesystem.fn_doc( doc_matters.source_filename, doc_matters.language )); } auto zip = new ZipArchive(); auto fn_sisupod = pth_sisupod.sisupod_filename(doc_matters.source_filename); { /+ bundle images +/ foreach (image; doc_matters.image_list) { debug(sisupodimages) { writeln( "_sisu/image/", image, " -> ", pth_sisupod.image(doc_matters.source_filename), "/", image ); } auto fn_src = "_sisu/image/"~ image; auto fn_out = pth_sisupod.image(doc_matters.source_filename).to!string ~ "/" ~ image; auto fn_out_filesystem = pth_sisupod_filesystem.image(doc_matters.source_filename).to!string ~ "/" ~ image; if (exists(fn_src)) { fn_src.copy(fn_out_filesystem); { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); zip_data.write(cast(char[]) ((fn_src).read)); zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); } } } } { /+ bundle sisu_document_make +/ auto fn_src = "_sisu/sisu_document_make"; // check (_sisu/sisu_document_make) auto fn_out = pth_sisupod.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; auto fn_out_filesystem = pth_sisupod_filesystem.conf(doc_matters.source_filename).to!string ~ "/" ~ "sisu_document_make"; if (exists(fn_src)) { fn_src.copy(fn_out_filesystem); { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); zip_data.write((fn_src).readText); zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); } } } { /+ bundle primary file +/ auto fn_src = doc_matters.source_filename; auto fn_out = pth_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc(doc_matters.source_filename, doc_matters.language).to!string; if (exists(fn_src)) { fn_src.copy(fn_out_filesystem); { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = fn_out; auto zip_data = new OutBuffer(); zip_data.write((fn_src).readText); zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); } } } { /+ bundle insert files +/ if (doc_matters.file_insert_list.length > 0) { foreach (insert_file; doc_matters.file_insert_list) { debug(sisupod) { writeln( insert_file, " -> ", pth_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, doc_matters.language )); } auto fn_src = insert_file; auto fn_out = pth_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, doc_matters.language ).to!string; auto fn_out_filesystem = pth_sisupod_filesystem.fn_doc_insert( doc_matters.source_filename, insert_file, doc_matters.language ).to!string; if (exists(fn_src)) { fn_src.copy(fn_out_filesystem); { auto zip_arc_member_file = new ArchiveMember(); zip_arc_member_file.name = insert_file; auto zip_data = new OutBuffer(); zip_data.write((fn_src).readText); zip_arc_member_file.expandedData = zip_data.toBytes(); zip.addMember(zip_arc_member_file); createZipFile!()(pth_sisupod.sisupod_filename(fn_src), zip.build()); } } } } } if (exists(fn_sisupod)) { try { auto data = (cast(byte[]) (fn_sisupod).read); writefln("%-(%02x%) %s", data.sha256Of, fn_sisupod); debug(sisupod) { try { auto zipped = new ZipArchive((fn_sisupod).read); foreach (filename, member; zipped.directory) { auto data = zipped.expand(member); writeln("> ", filename, " length ", data.length); // filename == member.name // Use data } } catch (ZipException ex) { // Handle errors } if (doc_matters.source_filename == "en/the_wealth_of_networks.yochai_benkler.sst") { assert( ((data).sha256Of).toHexString == "DDE0013C13C6A4F06D4BE72087E2CDEF47697CA38A6A2D65BA7207DB6B144271", "\nsisupod: sha256 value for " ~ doc_matters.source_filename ~ " has changed, is now: " ~ ((data).sha256Of).toHexString ); } if (doc_matters.source_filename == "en/sisu_markup_stress_test.sst") { assert( ((data).sha256Of).toHexString == "112C0AEDD2518A1803D91A7CF5785274A3116C0779A631782D0C0813B212C68A", "\nsisupod: sha256 value for " ~ doc_matters.source_filename ~ " has changed, is now: " ~ ((data).sha256Of).toHexString ); } } } catch (ErrnoException ex) { // Handle errors } } } catch (ErrnoException ex) { // Handle error } } }