aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/source_sisupod.d
blob: 9ed2c971d71f8eb387eebc3aa55d894ad074f7f0 (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
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,
    ao_defaults;
  import
    ao_rgx,
    output_xhtmls;
  
  void SiSUpod(T)(T doc_matters) {
    debug(asserts){
    }
    mixin SiSUrgxInit;
    mixin SiSUpaths;
    auto pth_sisupod = SiSUpodPaths();
    mixin SiSUlanguageCodes;
    auto lang = Lang();
    auto rgx = Rgx();
    /+
      dir structure
      /tmp/_sisu_processing_/ralph/sisupod
        ├── conf
        ├── css (unless should be within conf?)
        ├── doc
        │   ├── en
        │   ├── es
        │   ├── fr
        │   └── zh
        └── image
  
      - tasks
        - create directory structure
        - map other language directories
          - check for corresponding files within
    +/
    assert (match(doc_matters.source_filename, rgx.src_fn));
    try {
      /+ create directory structure +/
      if (!exists(pth_sisupod.doc(doc_matters.source_filename))) {
        mkdirRecurse(pth_sisupod.doc(doc_matters.source_filename));
      }
      if (!exists(pth_sisupod.conf(doc_matters.source_filename))) {
        mkdirRecurse(pth_sisupod.conf(doc_matters.source_filename));
      }
      if (!exists(pth_sisupod.css(doc_matters.source_filename))) {
        mkdirRecurse(pth_sisupod.css(doc_matters.source_filename));
      }
      if (!exists(pth_sisupod.image(doc_matters.source_filename))) {
        mkdirRecurse(pth_sisupod.image(doc_matters.source_filename));
      }
      /+ copy relevant files +/
      debug(sisupod) {
        writeln(__LINE__, ": ",
          // doc_matters.environment["pwd"], "/",
            doc_matters.source_filename, " -> ",
          // doc_matters.environment["pwd"], "/",
            pth_sisupod.fn_doc(doc_matters.source_filename, "en")
        );
      }
      // need to extract language code directories (from directory structure or filenames & have a default)
      if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, "en"))) {
        mkdirRecurse(pth_sisupod.doc_lng(doc_matters.source_filename, "en"));
      }
      if (exists(doc_matters.source_filename)) {
        copy(doc_matters.source_filename,
          pth_sisupod.fn_doc(doc_matters.source_filename, "en"));
      }
      if (doc_matters.file_insert_list.length > 0) {
        foreach (insert_file; doc_matters.file_insert_list) {
          debug(sisupod) {
            writeln(
              // doc_matters.environment["pwd"], "/",
                insert_file, " -> ",
              // doc_matters.environment["pwd"], "/",
                pth_sisupod.fn_doc(doc_matters.source_filename, "en")
            );
          }
          if (exists(insert_file)) {
            copy(insert_file,
              pth_sisupod.fn_doc(doc_matters.source_filename, "en"));
          }
        }
      }
      foreach (image; doc_matters.image_list) {
        debug(sisupod) {
          writeln(
            // doc_matters.environment["pwd"], "/",
              "_sisu/image/", image, " -> ",
            // doc_matters.environment["pwd"], "/",
              pth_sisupod.image(doc_matters.source_filename), "/", image
          );
        }
        if (exists("_sisu/image/"~ image)) {
          copy(("_sisu/image/"~ image),
            (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image));
        }
      }
    }
    catch (ErrnoException ex) {
      // Handle error
    }
  }
  
  
}