|
26 | 26 | #include "sitemap.h" |
27 | 27 | #include "textstream.h" |
28 | 28 | #include "util.h" |
| 29 | +#include "version.h" |
| 30 | +#include "language.h" |
29 | 31 | #include "portable.h" |
30 | 32 |
|
31 | 33 | class Sitemap::Private |
32 | 34 | { |
33 | 35 | public: |
| 36 | + bool site; |
34 | 37 | std::ofstream docFile; |
35 | 38 | TextStream doc; |
36 | | - TextStream index; |
| 39 | + //TextStream index; |
| 40 | + std::ofstream crawlFile; |
| 41 | + TextStream crawl; |
| 42 | + |
37 | 43 | }; |
38 | 44 |
|
39 | | -Sitemap::Sitemap() : p(std::make_unique<Private>()) {} |
| 45 | +Sitemap::Sitemap(const bool site) : p(std::make_unique<Private>()) {p->site = site;} |
40 | 46 | Sitemap::~Sitemap() = default; |
41 | 47 | Sitemap::Sitemap(Sitemap &&) = default; |
42 | 48 |
|
43 | 49 | void Sitemap::initialize() |
44 | 50 | { |
45 | 51 | QCString fileName = Config_getString(HTML_OUTPUT) + "/" + sitemapFileName; |
| 52 | + QCString fileNameCrawl = Config_getString(HTML_OUTPUT) + "/" + crawlFileName; |
| 53 | + addHtmlExtensionIfMissing(fileNameCrawl); |
46 | 54 |
|
47 | | - p->docFile = Portable::openOutputStream(fileName); |
48 | | - if (!p->docFile.is_open()) |
| 55 | + if (p->site) |
49 | 56 | { |
50 | | - term("Could not open file %s for writing\n", fileName.data()); |
| 57 | + p->docFile = Portable::openOutputStream(fileName); |
| 58 | + if (!p->docFile.is_open()) |
| 59 | + { |
| 60 | + term("Could not open file %s for writing\n", fileName.data()); |
| 61 | + } |
| 62 | + p->doc.setStream(&p->docFile); |
| 63 | + |
| 64 | + p->doc << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
| 65 | + p->doc << "<urlset\n"; |
| 66 | + p->doc << " xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n"; |
| 67 | + p->doc << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
| 68 | + p->doc << " xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n"; |
| 69 | + p->doc << " http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n"; |
| 70 | + } |
| 71 | + p->crawlFile = Portable::openOutputStream(fileNameCrawl); |
| 72 | + if (!p->crawlFile.is_open()) |
| 73 | + { |
| 74 | + term("Could not open file %s for writing\n", fileNameCrawl.data()); |
51 | 75 | } |
52 | | - p->doc.setStream(&p->docFile); |
| 76 | + p->crawl.setStream(&p->crawlFile); |
| 77 | + p->crawl << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
| 78 | + p->crawl << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"" + theTranslator->trISOLang() + "\">\n"; |
| 79 | + p->crawl << "<head>\n"; |
| 80 | + p->crawl << "<title>Validator / crawler helper</title>\n"; |
| 81 | + p->crawl << "<meta http-equiv=\"Content-Type\" content=\"text/xhtml;charset=UTF-8\"/>\n"; |
| 82 | + p->crawl << "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=11\"/>\n"; |
53 | 83 |
|
54 | | - p->doc << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
55 | | - p->doc << "<urlset\n"; |
56 | | - p->doc << " xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n"; |
57 | | - p->doc << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; |
58 | | - p->doc << " xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n"; |
59 | | - p->doc << " http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n"; |
| 84 | + p->crawl << "<meta name=\"generator\" content=\"Doxygen " + getDoxygenVersion() + "\"/>\n"; |
| 85 | + p->crawl << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n"; |
| 86 | + p->crawl << "</head>\n"; |
| 87 | + p->crawl << "<body>\n"; |
60 | 88 | } |
61 | 89 |
|
62 | 90 | void Sitemap::finalize() |
63 | 91 | { |
64 | | - p->doc << "</urlset>\n"; |
65 | | - p->doc.flush(); |
66 | | - p->docFile.close(); |
| 92 | + if (p->site) |
| 93 | + { |
| 94 | + p->doc << "</urlset>\n"; |
| 95 | + p->doc.flush(); |
| 96 | + p->docFile.close(); |
| 97 | + } |
| 98 | + p->crawl << "</body>\n"; |
| 99 | + p->crawl << "</html>\n"; |
| 100 | + p->crawl.flush(); |
| 101 | + p->crawlFile.close(); |
67 | 102 | } |
68 | 103 |
|
69 | 104 | void Sitemap::addIndexFile(const QCString & fileName) |
70 | 105 | { |
71 | 106 | QCString fn = fileName; |
72 | | - QCString sidemapUrl = Config_getString(SITEMAP_URL); |
73 | 107 | addHtmlExtensionIfMissing(fn); |
74 | | - p->doc << " <url>\n"; |
75 | | - p->doc << " <loc>" << convertToXML(sidemapUrl + fn) << "</loc>\n"; |
76 | | - p->doc << " </url>\n"; |
| 108 | + if (p->site) |
| 109 | + { |
| 110 | + QCString sidemapUrl = Config_getString(SITEMAP_URL); |
| 111 | + p->doc << " <url>\n"; |
| 112 | + p->doc << " <loc>" << convertToXML(sidemapUrl + fn) << "</loc>\n"; |
| 113 | + p->doc << " </url>\n"; |
| 114 | + } |
| 115 | + p->crawl << " <a href=\"" << fn << "\"/>\n"; |
77 | 116 | } |
0 commit comments