#pragma once #include "stdafx.h" #include "GeneralBuilder.h" #include "ThePraDev.h" #include "ThePraArt.h" GeneralBuilder::GeneralBuilder() { } GeneralBuilder::~GeneralBuilder() { } void GeneralBuilder::BuildThePraSite(Sites site) { Utilities tool{Utilities()}; string cPath{tool.GetCurrentPath()}; cout << cPath << endl; 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", ROOT, a.description); Body(index, cPath + a.contentLinks[0], site); cout << cPath + a.contentLinks[0] << endl; WriteToFile(index, a.outputLinks[0]); Document code{Document()}; Head(code, link + "code" + html, "ThePra Code", ROOT, a.description); Body(code, cPath + a.contentLinks[1], site); cout << cPath + a.contentLinks[1] << endl; WriteToFile(code, a.outputLinks[1]); Document blog{Document()}; Head(blog, link + "blog" + html, "ThePra Blog", ROOT, a.description); Body(blog, cPath + a.contentLinks[2], site); cout << cPath + a.contentLinks[2] << endl; WriteToFile(blog, a.outputLinks[2]); Document about{Document()}; Head(about, link + "about" + html, "ThePra About", ROOT, a.description); Body(about, cPath + a.contentLinks[3], site); cout << cPath + a.contentLinks[3] << endl; WriteToFile(about, a.outputLinks[3]); Document contact{Document()}; Head(contact, link + "contact" + html, "ThePra Contact", ROOT, a.description); Body(contact, cPath + a.contentLinks[4], site); cout << cPath + a.contentLinks[4] << endl; WriteToFile(contact, a.outputLinks[4]); } break; case ART: { ThePraArt a{ThePraArt()}; string link = "http://art.thepra-dev.com/", html = ".html"; Document index{Document()}; Head(index, link + "index" + html, "ThePra Art Blog", ROOT, a.description); Body(index, cPath + a.contentLinks[0], site); cout << cPath + a.contentLinks[0] << endl; WriteToFile(index, a.outputLinks[0]); Document aboutme{Document()}; Head(aboutme, link + "aboutme" + html, "ThePra About", ROOT, a.description); Body(aboutme, cPath + a.contentLinks[1], site); cout << cPath + a.contentLinks[1] << endl; WriteToFile(aboutme, a.outputLinks[1]); Document youtubePosts{Document()}; Head(youtubePosts, link + "youtubeposts" + html, "ThePra Youtube videos", ROOT, a.description); Body(youtubePosts, cPath + a.contentLinks[2], site, Red); cout << cPath + a.contentLinks[2] << endl; WriteToFile(youtubePosts, a.outputLinks[2]); Document postTemplate{Document()}; Head(postTemplate, "", "*TEXT* - ThePra", ROOT, "*TEXT*"); Body(postTemplate, cPath + a.contentLinks[3], site); cout << cPath + a.contentLinks[3] << endl; WriteToFile(postTemplate, a.outputLinks[3]); } break; default: break; } } void GeneralBuilder::Head(Document &file, string canonicalURL, string title, Levels level, string description, list 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); } } //file.AddNodeToHead(contentSecurityPolicy); file.AddNodeToHead(descriptionP); file.AddNodeToHead(robots); file.AddNodeToHead(googleBot); file.AddNodeToHead(referrer); file.AddNodeToHead(icon); } void GeneralBuilder::Body(Document &file, string cPath, Sites site, Col color, PageType type) { switch (site) { case DEV: { ThePraDev::BuildBody(file, cPath, ROOT, type); } case ART: { ThePraArt::BuildBody(file, cPath, ROOT, color, type); } default:// I'm drunk break; } } 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); } }