-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
220 lines (199 loc) · 5.37 KB
/
index.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
var fs = require('fs');
const format = require('toris-format');
var async = require("async");
var fileName = 'generated-index.html';
var x, formattedHTML;
fs.open(fileName, 'r+', function(err, fd) {
if (err) {
return console.error(err);
}
});
async function initiateFile(){
var html = `
<html>
<head>
<title>↓ home ↓</title>
<link
rel="shortcut icon"
href="https://img.icons8.com/dusk/64/000000/monitor--v1.png"
title="Monitor icon by Icons8"
/>
<meta charset="utf-8" />
<!-- meta tags for SEO using Open Graph Protocol -->
<meta name="description" content="drag and drop website builder!" />
<meta name="keywords" content="HTML, CSS, JavaScript, Developer" />
<meta name="author" content="smolpkg" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta
property="og:image:url"
content="https://img.icons8.com/dusk/64/000000/monitor--v1.png"
/>
<meta property="og:image:width" content="300" />
<meta property="og:image:alt" content="a monitor graphic" />
<meta property="og:title" content="built with website builder" />
<meta property="og:description" content="a drag and drop website builder" />
<!-- meta tags for twitter -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content="@smolpkg" />
<meta
name="twitter:image"
content="https://img.icons8.com/dusk/64/000000/monitor--v1.png"
/>
<meta name="twitter:image:width" content="300" />
<meta name="twitter:image:alt" content="a monitor graphic" />
<meta
name="twitter:description"
content="built with drag and drop website builder!"
/>
<!-- all Bootstrap CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
/>
<link rel="stylesheet" href="/index.css"/>
</head>
<body>
<style>
.row{
padding: 5px;
}
</style>
<!-- content begins -->
<div class="container" style="padding: 10px">
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendHeading(text, heading){
var html =
`
<div class="row">
<h${heading} style="padding: 5px;">${text}</h${heading}> <!-- heading added -->
</div>
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendInputField(type, placeholder){
var html =
`
<div class="row">
<div class="col-sm-3">
<input type="${type}" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="${placeholder}"> <!-- input field added -->
</div>
</div>
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendButton(text, color){
var html =
`
<div class="row">
<div class="col-sm-3">
<button type="button" class= "btn ${color}">${text}</button> <!-- button added -->
</div>
</div>
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendCard(cardTitle, cardImageURL, cardBody, width){
var html =
`
<!-- card begins -->
<div class="row">
<div class="col-sm-3">
<div class="card" style="width: ${width}px;">
<img class="card-img-top" src="${cardImageURL}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">${cardTitle}</h5>
<p class="card-text">${cardBody}</p>
</div>
</div>
</div>
</div>
<!-- card ends -->
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendParagraph(text, alignment){
var html =
`
<div class="row">
<div class="col-sm-3">
<p class="${alignment}">${text}</p> <!-- paragraph added -->
</div>
</div>
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function appendIframe(url, height, width){
var html =
`
<iframe src="${url}" height="${height}" width="${width}" title="exampleIframe"></iframe>
`
}
async function endFile(){
var html =
`
</div>
<!-- content ends -->
</body>
</html>
`
fs.appendFile(fileName, html, {}, (err) => {
if(err){
console.log("Error! -> " + err);
}
}
);
}
async function formatFile(){
fs.readFile(fileName, 'utf8', function(err, data){
// Display the file content
x = data;
const unformattedHTML = x;
const config = {
definition_type: 'HTML'
}
formattedHTML = format.formatContents(unformattedHTML, config);
console.log(formattedHTML);
fs.writeFile(fileName, formattedHTML, function(err) {
if (err) {
return console.error(err);
}
});
});
}
module.exports = {initiateFile, appendHeading,appendInputField, appendButton, appendCard, appendParagraph, appendIframe, endFile, formatFile}