-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainPage.cpp
70 lines (62 loc) · 2.06 KB
/
MainPage.cpp
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
/*
* This program is A Static Site Generator (SSG) Tool coded in C++ language.
* Author: Chi Kien Nguyen
* Git Hub: https://github.com/kiennguyenchi/potato-generator
*/
/* This is the file containing functionalities of a main page */
#include "MainPage.h"
//this function sets up main page and linked websites
void MainPage::setMainPage(string path, vector<string> textFiles, string lang)
{
setFolderName(path);
for (int i = 0; i < textFiles.size(); i++) {
HTMLFile newFile;
newFile.openFile(textFiles.at(i), lang);
newFile.setHtmlFile();
string fileName = textFiles.at(i).substr(textFiles.at(i).find(folderName) + 2, textFiles.at(i).size() - 2);
newFile.writeHTML(path);
sites.push_back(newFile);
}
setHTMLMainPage();
}
//this function returns html main page in string
string MainPage::getMainPage()
{
return htmlFile;
}
//this function displays html page
void MainPage::displayMainPage()
{
cout << htmlFile << endl;
}
//this function sets up html main page
void MainPage::setHTMLMainPage()
{
htmlFile = "<!doctype html><html lang='en'>\n<head>\n\t<meta charset='utf-8'>\n";
htmlFile += ("\t<title>" + getFolderName() + "</title>\n");
htmlFile += ("<link rel='stylesheet' href='../pgprogram.css'>");
htmlFile += "\t<meta name='viewport' content='width=device-width, initial-scale=1'>\n</head>\n";
htmlFile += ("\n<body>\n\t<div><h1>" + getFolderName() + "</h1></div><br>\n");
for (int i = 0; i < sites.size(); i++) {
htmlFile += ("\t\t<div id='menu'><a href='" + sites.at(i).getURL() + "'>" + sites.at(i).getTitle() + "</a></div>\n");
}
htmlFile += "\n</body>\n</html>";
}
//this function writes HTML main page
void MainPage::writeHTML(string path)
{
string name = "./" + path + "/" + path + ".html";
ofstream file(name);
file << getMainPage() << endl;
file.close();
}
//this function sets up folder name
void MainPage::setFolderName(string name)
{
folderName = name;
}
//this function returns folder name
string MainPage::getFolderName()
{
return folderName;
}