-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
43 lines (32 loc) · 1.39 KB
/
build.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
const fs = require('fs');
const path = require('path');
console.log('Build du fichier index');
// Directory to search for HTML files
const directoryPath = '.';
// Path to the model HTML file
const modelFilePath = path.join(directoryPath, 'index-modele.html');
// Function to insert links into the model HTML content
function insertLinksIntoModel(modelContent, files) {
const links = files.filter(file=>file!='index.html').map(file => `<li><a href="${file}">${file.split('.')[0]}</a></li>`).join('\n');
// Assuming the model HTML has a marker where the list should be inserted
const updatedContent = modelContent.replace('<!-- Links -->', `<ul>\n${links}\n</ul>`);
return updatedContent;
}
// Function to create index.htm based on the model file
function createIndexFile(files) {
fs.readFile(modelFilePath, 'utf8', (err, data) => {
if (err) throw err;
const htmlContent = insertLinksIntoModel(data, files);
const indexPath = path.join(directoryPath, 'index.html');
fs.writeFile(indexPath, htmlContent, (err) => {
if (err) throw err;
console.log('index.htm has been created based on index-modele.html!');
});
});
}
// Read the current directory to find HTML files
fs.readdir(directoryPath, (err, files) => {
if (err) throw err;
const htmlFiles = files.filter(file => path.extname(file) === '.html' && file !== 'index-modele.html');
createIndexFile(htmlFiles);
});