Doxygen
Loading...
Searching...
No Matches
sitemap.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 1997-2023 Dimitri van Heesch.
3 *
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation under the terms of the GNU General Public License is hereby
6 * granted. No representations are made about the suitability of this software
7 * for any purpose. It is provided "as is" without express or implied warranty.
8 * See the GNU General Public License for more details.
9 *
10 * Documents produced by Doxygen are derivative works derived from the
11 * input used in their production; they are not affected by this license.
12 */
13
14#include <algorithm>
15#include <memory>
16#include <string.h>
17#include <vector>
18#include <cassert>
19
20#include "config.h"
21#include "debug.h"
22#include "doxygen.h"
23#include "groupdef.h"
24#include "memberdef.h"
25#include "message.h"
26#include "sitemap.h"
27#include "textstream.h"
28#include "util.h"
29#include "portable.h"
30#include "language.h"
31#include "version.h"
32#include "containers.h"
33
34//-------------------------------------------------------------------------------------------
35
37{
38 public:
39 std::ofstream docFile;
40 TextStream doc;
41};
42
43Sitemap::Sitemap() : p(std::make_unique<Private>()) {}
44Sitemap::~Sitemap() = default;
45
47{
48 QCString fileName = Config_getString(HTML_OUTPUT) + "/" + sitemapFileName;
49
50 p->docFile = Portable::openOutputStream(fileName);
51 if (!p->docFile.is_open())
52 {
53 term("Could not open file %s for writing\n", qPrint(fileName));
54 }
55 p->doc.setStream(&p->docFile);
56
57 p->doc << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
58 p->doc << "<urlset\n";
59 p->doc << " xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
60 p->doc << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
61 p->doc << " xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n";
62 p->doc << " http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
63}
64
66{
67 p->doc << "</urlset>\n";
68 p->doc.flush();
69 p->docFile.close();
70}
71
72void Sitemap::addIndexFile(const QCString & fileName)
73{
74 QCString fn = fileName;
75 QCString sidemapUrl = Config_getString(SITEMAP_URL);
77 p->doc << " <url>\n";
78 p->doc << " <loc>" << convertToXML(sidemapUrl + fn) << "</loc>\n";
79 p->doc << " </url>\n";
80}
81
82//-------------------------------------------------------------------------------------------
83//
85{
86 public:
87 std::ofstream crawlFile;
88 TextStream crawl;
90};
91
92Crawlmap::Crawlmap() : p(std::make_unique<Private>()) {}
93Crawlmap::~Crawlmap() = default;
94
96{
97 QCString fileName = Config_getString(HTML_OUTPUT) + "/" + crawlFileName;
99 p->crawlFile = Portable::openOutputStream(fileName);
100 if (!p->crawlFile.is_open())
101 {
102 term("Could not open file %s for writing\n", qPrint(fileName));
103 }
104 p->crawl.setStream(&p->crawlFile);
105 p->crawl << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
106 p->crawl << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"" + theTranslator->trISOLang() + "\">\n";
107 p->crawl << "<head>\n";
108 p->crawl << "<title>Validator / crawler helper</title>\n";
109 p->crawl << "<meta http-equiv=\"Content-Type\" content=\"text/xhtml;charset=UTF-8\"/>\n";
110 p->crawl << "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=11\"/>\n";
111
112 p->crawl << "<meta name=\"generator\" content=\"Doxygen " + getDoxygenVersion() + "\"/>\n";
113 p->crawl << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/>\n";
114 p->crawl << "</head>\n";
115 p->crawl << "<body>\n";
116}
117
119{
120 std::sort(p->crawlLinks.begin(),p->crawlLinks.end());
121 p->crawlLinks.erase(std::unique(p->crawlLinks.begin(),p->crawlLinks.end()),p->crawlLinks.end());
122 for (auto &s : p->crawlLinks)
123 {
124 p->crawl << "<a href=\"" << s << "\"/>\n";
125 }
126
127 p->crawl << "</body>\n";
128 p->crawl << "</html>\n";
129 p->crawl.flush();
130 p->crawlFile.close();
131}
132
133void Crawlmap::addIndexFile(const QCString & fileName)
134{
135 QCString fn = fileName;
137 p->crawlLinks.push_back(fn.str());
138}
139
140void Crawlmap::addContentsItem(bool, const QCString &, const QCString & ref,
141 const QCString & file, const QCString & anchor,
142 bool ,bool ,
143 const Definition *)
144{
145 if (!file.isEmpty() && ref.isEmpty()) // made file optional param and
146 // don't place links in crawl file imported
147 // by tags
148 {
149 std::string link;
150 if (file[0]=='!' || file[0]=='^') // special markers for user defined URLs
151 {
152 link+=&file[1];
153 }
154 else
155 {
156 QCString currFile = file;
158 QCString currAnc = anchor;
159 link += currFile.data();
160 if (!currAnc.isEmpty())
161 {
162 link += "#";
163 link += currAnc.str();
164 }
165 }
166 p->crawlLinks.push_back(link);
167 }
168}
169
170static QCString makeFileName(const QCString & withoutExtension)
171{
172 QCString result=withoutExtension;
173 if (!result.isEmpty())
174 {
175 if (result.at(0)=='!') // relative URL -> strip marker
176 {
177 result=result.mid(1);
178 }
179 else // add specified HTML extension
180 {
182 }
183 }
184 return result;
185}
186
187static QCString makeRef(const QCString & withoutExtension, const QCString & anchor)
188{
189 if (withoutExtension.isEmpty()) return QCString();
190 QCString result = makeFileName(withoutExtension);
191 if (anchor.isEmpty()) return result;
192 return result+"#"+anchor;
193}
194
195void Crawlmap::addIndexItem(const Definition *context, const MemberDef *md,
196 const QCString &sectionAnchor, const QCString &title)
197{
198 if (context && md) // member
199 {
200 QCString cfname = md->getOutputFileBase();
201 QCString anchor = !sectionAnchor.isEmpty() ? sectionAnchor : md->anchor();
202 QCString ref = makeRef(cfname, anchor);
203 p->crawlLinks.push_back(ref.str());
204 }
205 else if (context) // container
206 {
207 QCString contRef = context->getOutputFileBase();
208 QCString ref = makeRef(contRef,sectionAnchor);
209 p->crawlLinks.push_back(ref.str());
210 }
211}
TextStream crawl
Definition sitemap.cpp:88
StringVector crawlLinks
Definition sitemap.cpp:89
std::ofstream crawlFile
Definition sitemap.cpp:87
void initialize()
Definition sitemap.cpp:95
std::unique_ptr< Private > p
Definition sitemap.h:79
void addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def)
Definition sitemap.cpp:140
void addIndexFile(const QCString &name)
Definition sitemap.cpp:133
void finalize()
Definition sitemap.cpp:118
void addIndexItem(const Definition *context, const MemberDef *md, const QCString &sectionAnchor, const QCString &title)
Definition sitemap.cpp:195
static const QCString crawlFileName
Definition sitemap.h:75
The common base class of all entity definitions found in the sources.
Definition definition.h:76
virtual QCString anchor() const =0
virtual QCString getOutputFileBase() const =0
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:567
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:526
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
TextStream doc
Definition sitemap.cpp:40
std::ofstream docFile
Definition sitemap.cpp:39
static const QCString sitemapFileName
Definition sitemap.h:47
std::unique_ptr< Private > p
Definition sitemap.h:51
void addIndexFile(const QCString &name)
Definition sitemap.cpp:72
void finalize()
Definition sitemap.cpp:65
Sitemap()
Definition sitemap.cpp:43
void initialize()
Definition sitemap.cpp:46
virtual QCString trISOLang()=0
#define Config_getString(name)
Definition config.h:32
std::vector< std::string > StringVector
Definition containers.h:33
Translator * theTranslator
Definition language.cpp:71
#define term(fmt,...)
Definition message.h:94
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:665
Portable versions of functions that are platform dependent.
const char * qPrint(const char *s)
Definition qcstring.h:661
static QCString makeRef(const QCString &withoutExtension, const QCString &anchor)
Definition qhp.cpp:187
static QCString makeRef(const QCString &withoutExtension, const QCString &anchor)
Definition sitemap.cpp:187
static QCString makeFileName(const QCString &withoutExtension)
Definition sitemap.cpp:170
QCString convertToXML(const QCString &s, bool keepEntities)
Definition util.cpp:4266
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:5243
A bunch of utility functions.