Commit 1195e31d authored by jan.koester's avatar jan.koester
Browse files

theme: canonical and og:url without the doubled mount path

siteurl ends with the blog's path (https://tuxist.de/blog) and the
request path carries it too (/blog/staticpage/x), so canonical and og:url
pointed at https://tuxist.de/blog/blog/staticpage/x -- a 404 for search
engines and link previews.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent b0ea2410
Loading
Loading
Loading
Loading
+14 −1
Changes for src/theme.cpp: 14 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -569,7 +569,20 @@ void blogi::Theme::printSite(const int tid,libhtmlpp::HtmlString &output,libhtml

            std::string ogTitle = (seo && !seo->ogTitle.empty()) ? seo->ogTitle : (title && title[0] != '\0' ? title : "");
            std::string ogDescription = (seo && !seo->ogDescription.empty()) ? seo->ogDescription : (meta ? meta : "");
            std::string pageUrl = std::string(_Config.config.getsiteurl()).append(crrurl);
            // siteurl already ends with the blog's mount path
            // (https://tuxist.de/blog) and the request path carries it too
            // (/blog/staticpage/x): don't repeat it -- canonical and og:url
            // pointed at .../blog/blog/... (404)
            std::string site = _Config.config.getsiteurl();
            while(!site.empty() && site.back() == '/') site.pop_back();
            std::string path = crrurl;
            size_t scheme = site.find("://");
            size_t slash = scheme == std::string::npos ? std::string::npos : site.find('/', scheme + 3);
            std::string sitePath = slash == std::string::npos ? std::string() : site.substr(slash);
            if(!sitePath.empty() && path.compare(0, sitePath.size(), sitePath) == 0 &&
               (path.size() == sitePath.size() || path[sitePath.size()] == '/' || path[sitePath.size()] == '?'))
                path = path.substr(sitePath.size());
            std::string pageUrl = site + path;
            std::string canonicalUrl = (seo && !seo->canonicalUrl.empty()) ? seo->canonicalUrl : pageUrl;
            std::string pageType = (seo && !seo->pageType.empty()) ? seo->pageType : "website";
            std::string twitterCard = (seo && !seo->twitterCard.empty()) ? seo->twitterCard : "summary_large_image";