File : IndexHtmlBuilder.js

1
/*
2
Copyright - 2021 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v1.0.0:
21
        - created
22
Doc reviewed 20211111
23
*/
24
/* ------------------------------------------------------------------------------------------------------------------------- */
25
26
import fs from 'fs';
27
import theConfig from './Config.js';
28
import NavHtmlBuilder from './NavHtmlBuilder.js';
29
import { marked } from 'marked';
30
31
/* ------------------------------------------------------------------------------------------------------------------------- */
32
/**
33
Build the index.html home page
34
*/
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
37
class IndexHtmlBuilder {
38
39
    /**
40
    The constructor
41
    */
42
43
    constructor ( ) {
44
        Object.freeze ( this );
45
    }
46
47
    /**
48
    Build the index.html page
49
    */
50
51
    build ( ) {
52
53
        const navHtmlBuilder = new NavHtmlBuilder ( );
54
55
        // head
56
        let html =
57
            '<!DOCTYPE html><html><head><meta charset="UTF-8">' +
58
            '<link type="text/css" rel="stylesheet" href="ESSimpleDoc.css"></head><body>';
59
60
        // nav
61
        html += navHtmlBuilder.build ( '' );
62
63
        // reading the content of the indexUserContent.html file
64
        if ( fs.existsSync ( theConfig.srcDir + 'index.md' ) ) {
65
66
            // and adding to the html
67
            html += marked.parse ( fs.readFileSync ( theConfig.srcDir + 'index.md', 'utf8' ) );
68
        }
69
        else {
70
71
            // or adding a default content
72
            html += '<div><p>Move the mouse on one of the blue, green or red rectangles on top of the page to display' +
73
            ' the menus and select an item in the menu.<p></div>';
74
        }
75
76
        // footer
77
        html += navHtmlBuilder.footer;
78
        html += '</body></html>';
79
80
        // writing file
81
        fs.writeFileSync ( theConfig.destDir + 'index.html', html );
82
    }
83
}
84
85
export default IndexHtmlBuilder;
86
87
/* --- End of file --------------------------------------------------------------------------------------------------------- */
88