aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/source_sisupod.d
blob: e6702bf0b202a8009b88f86434376148e8596e9f (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
template SiSUpod() {
  private import
    std.algorithm,
    std.array,
    std.container,
    std.exception,
    std.file,
    std.getopt,
    std.json,
    std.process,
    std.stdio,
    std.path,
    std.range,
    std.regex,
    std.string,
    std.traits,
    std.typecons,
    std.uni,
    std.utf,
    std.conv : to;
  import
    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 = SiSUpodPaths();
    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.doc(doc_matters.source_filename))) {
        pth_sisupod.doc(doc_matters.source_filename).mkdirRecurse;
      }
      if (!exists(pth_sisupod.conf(doc_matters.source_filename))) {
        pth_sisupod.conf(doc_matters.source_filename).mkdirRecurse;
      }
      if (!exists(pth_sisupod.css(doc_matters.source_filename))) {
        pth_sisupod.css(doc_matters.source_filename).mkdirRecurse;
      }
      if (!exists(pth_sisupod.image(doc_matters.source_filename))) {
        pth_sisupod.image(doc_matters.source_filename).mkdirRecurse;
      }
      if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language))) {
        pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language).mkdirRecurse;
      }
      debug(sisupod) {
        writeln(__LINE__, ": ",
          // doc_matters.environment["pwd"], "/",
            doc_matters.source_filename, " -> ",
          // doc_matters.environment["pwd"], "/",
            pth_sisupod.fn_doc(
              doc_matters.source_filename,
              doc_matters.language
        ));
      }
      if (exists(doc_matters.source_filename)) {
        copy(
          doc_matters.source_filename,
          pth_sisupod.fn_doc(
            doc_matters.source_filename,
            doc_matters.language
        ));
      }
      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
            ));
          }
          if (exists(insert_file)) {
            insert_file.copy(
              pth_sisupod.fn_doc_insert(
                doc_matters.source_filename,
                insert_file,
                doc_matters.language
            ));
          }
        }
      }
      foreach (image; doc_matters.image_list) {
        debug(sisupod) {
          writeln(
              "_sisu/image/", image, " -> ",
              pth_sisupod.image(doc_matters.source_filename), "/", image
          );
        }
        if (exists("_sisu/image/"~ image)) {
          ("_sisu/image/"~ image).copy(
            (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image)
          );
        }
      }
      
    }
    catch (ErrnoException ex) {
      // Handle error
    }
  }
}