Skip to content

Commit

Permalink
Merge 3edfd3c into 9f03b19
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Nov 2, 2019
2 parents 9f03b19 + 3edfd3c commit 995ab13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions routes/appendLocals.js
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const url = require('url');
const { generateSri, capitalize } = require('../lib/helpers');
const { app, files } = require('../config');

Expand Down Expand Up @@ -58,11 +59,9 @@ function generateSRI(file) {
function appendLocals(req, res) {
const siteUrl = getCurrentSiteurl(req);
const pageUrl = req.originalUrl;
// OK, hack-ish way...
const pathname = pageUrl.split('?')[0];
const canonicalUrl = new URL(pathname, app.siteurl);
const canonicalUrl = url.resolve(app.siteurl, url.parse(pageUrl).pathname);
const theme = getThemeQuery(req);
const bodyClass = generateBodyClass(pathname);
const bodyClass = generateBodyClass(pageUrl);

const locals = {
siteUrl,
Expand Down
3 changes: 2 additions & 1 deletion test/test_helpers.js
Expand Up @@ -6,6 +6,7 @@ const ENV = process.env;
ENV.BCDN_HEADERS = ENV.BCDN_HEADERS || 'production';

const assert = require('assert').strict;
const url = require('url');
const escapeStringRegexp = require('escape-string-regexp');
const { htmlEncode } = require('htmlencode');
const mockDate = require('mockdate');
Expand Down Expand Up @@ -141,7 +142,7 @@ function assertPageHeader(txt, res, cb) {
}

function assertCanonicalUrl(str, res, cb) {
const expected = `<link rel="canonical" href="${new URL(str, config.siteurl)}">`;
const expected = `<link rel="canonical" href="${url.resolve(config.siteurl, str)}">`;

assert.ok(res.body.includes(expected), 'Expects page to have a canonical URL');
cb();
Expand Down

0 comments on commit 995ab13

Please sign in to comment.