MyWebsitesGenerator/TestWebGen/GeneralBuilder.cpp

217 lines
6.1 KiB
C++
Raw Normal View History

2017-04-02 18:07:06 +02:00
#pragma once
#include "stdafx.h"
#include "GeneralBuilder.h"
#include "ThePraDev.h"
GeneralBuilder::GeneralBuilder()
{
}
GeneralBuilder::~GeneralBuilder()
{
}
2017-05-01 12:50:38 +02:00
void GeneralBuilder::BuildThePraSite(Sites site)
2017-04-02 18:07:06 +02:00
{
Utilities tool{Utilities()};
string cPath{tool.GetCurrentPath()};
2017-05-01 12:50:38 +02:00
cout << cPath << endl;
2017-04-02 18:07:06 +02:00
switch (site)
{
case DEV:
{
ThePraDev a{ThePraDev()};
string link = "https://www.thepra-dev.com/", html = ".html";
Document index = Document();
Head(index, link + "index" + html, "ThePra WebSite");
Body(index, cPath + a.contentLinks[0], site);
2017-05-01 12:50:38 +02:00
cout << cPath + a.contentLinks[0] << endl;
WriteToFile(index, a.outputLinks[0]);
2017-04-02 18:07:06 +02:00
Document code = Document();
Head(code, link + "code" + html, "ThePra Code");
Body(code, cPath + a.contentLinks[1], site);
2017-05-01 12:50:38 +02:00
cout << cPath + a.contentLinks[1] << endl;
WriteToFile(code, a.outputLinks[1]);
2017-04-02 18:07:06 +02:00
Document blog = Document();
Head(blog, link + "blog" + html, "ThePra Blog");
Body(blog, cPath + a.contentLinks[2], site);
2017-05-01 12:50:38 +02:00
cout << cPath + a.contentLinks[2] << endl;
WriteToFile(blog, a.outputLinks[2]);
2017-04-02 18:07:06 +02:00
Document about = Document();
Head(about, link + "about" + html, "ThePra About");
Body(about, cPath + a.contentLinks[3], site);
2017-05-01 12:50:38 +02:00
cout << cPath + a.contentLinks[3] << endl;
WriteToFile(about, a.outputLinks[3]);
2017-04-02 18:07:06 +02:00
Document contact = Document();
Head(contact, link + "contact" + html, "ThePra Contact");
Body(contact, cPath + a.contentLinks[4], site);
2017-05-01 12:50:38 +02:00
cout << cPath + a.contentLinks[4] << endl;
WriteToFile(contact, a.outputLinks[4]);
2017-04-02 18:07:06 +02:00
}
break;
case ART:
{
string link = "http://art.thepra-dev.com/", html = ".html";
Document index = Document();
Head(index, link + "index" + html, "title");
Body(index, cPath, site);
Document aboutme = Document();
Head(aboutme, link + "aboutme" + html, "title");
Body(aboutme, cPath, site);
Document twitch = Document();
Head(twitch, link + "twitch" + html, "title");
Body(twitch, cPath, site);
Document twitter = Document();
Head(twitter, link + "twitter" + html, "title");
Body(twitter, cPath, site);
Document youtubePosts = Document();
Head(youtubePosts, link + "youtubePosts" + html, "title");
Body(youtubePosts, cPath, site);
}
break;
default:
break;
}
}
void GeneralBuilder::Head(Document &file,
string canonicalURL,
string title,
Levels level,
string description,
list<string> cssStyles)
{
string whichLevel = ChooseLevel(level);
// ESSENTIAL
Node charset = Node(meta).SetAttribute("charset", "utf-8").UseClosingTag(false);
Node edge = Node(meta).SetAttribute(http_equiv, "x-ua-compatible").SetAttribute(content, "ie=edge").UseClosingTag(false);
Node viewport = Node(meta).SetAttribute(name, "viewport").SetAttribute(content, "width=device-width, initial-scale=1").UseClosingTag(false);
Node titleP = Node("title", title);
// OTHER
Node canon = Node(link).SetAttribute(rel, "canonical").SetAttribute(href, canonicalURL).UseClosingTag(false);
Node base = Node("base").SetAttribute(href, canonicalURL).UseClosingTag(false);
Node contentSecurityPolicy = Node(meta).SetAttribute(http_equiv, "Content-Security-Policy").SetAttribute(content, "default-src 'self'").UseClosingTag(false);
Node descriptionP = Node(meta).SetAttribute(name, "description").SetAttribute(content, description).UseClosingTag(false);
Node robots = Node(meta).SetAttribute(name, "robots").SetAttribute(content, "index,follow,noodp").UseClosingTag(false);
Node googleBot = Node(meta).SetAttribute(name, "googlebot").SetAttribute(content, "index,follow").UseClosingTag(false);
Node referrer = Node(meta).SetAttribute(name, "referrer").SetAttribute(content, "no-referrer").UseClosingTag(false);
Node icon = Node(link).SetAttribute(rel, "icon").SetAttribute(href, whichLevel + "icon/favicon.png").SetAttribute("type", "image/png").UseClosingTag(false);
file.AddNodeToHead(charset);
file.AddNodeToHead(edge);
file.AddNodeToHead(viewport);
file.AddNodeToHead(titleP);
file.AddNodeToHead(base);
file.AddNodeToHead(canon);
if (cssStyles.front() == "")
{
Node style = Node(link).SetAttribute(rel, "stylesheet").SetAttribute(href, whichLevel + "style.css").UseClosingTag(false);
file.AddNodeToHead(style);
}
else
{
for each (string s in cssStyles)
{
Node style = Node(link).SetAttribute(rel, "stylesheet").SetAttribute(href, whichLevel + s).UseClosingTag(false);
file.AddNodeToHead(style);
}
}
2017-05-01 12:50:38 +02:00
//file.AddNodeToHead(contentSecurityPolicy);
2017-04-02 18:07:06 +02:00
file.AddNodeToHead(descriptionP);
file.AddNodeToHead(robots);
file.AddNodeToHead(googleBot);
file.AddNodeToHead(referrer);
file.AddNodeToHead(icon);
}
void GeneralBuilder::Body(Document &file, string cPath, Sites site, PageType type)
{
switch (site)
{
case DEV:
{
ThePraDev::BuildBody(file, cPath, ROOT, type);
}
case ART:
{
}
default:// I'm drunk
break;
}
}
void GeneralBuilder::BuildHTMLFiles(Sites site, list<Document> rootFiles, list<Document> postFiles)
{
string cDevOutputPath{Utilities::GetCurrentPath() + "\\output_thepradev\\"};
string postcDevOutputPath{cDevOutputPath + "postsContent\\"};
path dir = current_path();
cout << dir.string() << endl;
for (auto& p : directory_iterator(dir))
{
path asd = p.path();
if (!is_directory(p))
cout << p.path().filename().string() << endl;
}
switch (site)
{
2017-04-02 22:31:53 +02:00
case DEV:
2017-04-02 18:07:06 +02:00
{
2017-04-02 22:31:53 +02:00
path devDir{dir};
devDir.append("thepradev");
path contentDir{devDir.append("content")};
path postsContentDir{devDir.append("postsContent")};
path outputDir{dir}; outputDir.append("output_thepradev");
path posts{outputDir}; posts.append("posts");
2017-05-01 12:50:38 +02:00
2017-04-02 18:07:06 +02:00
}
break;
2017-04-02 22:31:53 +02:00
case ART:
2017-04-02 18:07:06 +02:00
{
2017-04-02 22:31:53 +02:00
path artDir{dir};
artDir.append("thepraart");
path contentDir{artDir.append("content")};
path postsContentDir{artDir.append("postsContent")};
path outputDir{dir}; outputDir.append("output_thepraart");
path posts{outputDir}; posts.append("posts");
2017-04-02 18:07:06 +02:00
}
break;
default:
break;
}
2017-05-01 12:50:38 +02:00
}
void GeneralBuilder::WriteToFile(Document doc, string p)
{
path PathToCheck = path(p);
if (exists(PathToCheck))
{
remove(PathToCheck);
doc.WriteToFile(p, Readability::MULTILINE);
}
else
{
doc.WriteToFile(p, Readability::MULTILINE);
}
2017-04-02 18:07:06 +02:00
}