test opengraph functionality on more pages from checkup

This commit is contained in:
ansuz 2022-09-05 19:39:03 +05:30
parent ba363bbd22
commit 0219637502
1 changed files with 41 additions and 37 deletions

View File

@ -1420,47 +1420,51 @@ define([
});
});
assert(function (cb, msg) { // XXX
var url = '/code/index.html';
try {
url = new URL(url, ApiConfig.httpUnsafeOrigin).href;
} catch (err) {
console.error(err);
}
[
'/',
'/code/',
'/pad/index.html',
].forEach(url => {
assert(function (cb, msg) { // XXX
try {
url = new URL(url, ApiConfig.httpUnsafeOrigin).href;
} catch (err) {
console.error(err);
}
Tools.common_xhr(url, xhr => {
xhr.done(res => {
var dom = new DOMParser().parseFromString(res, 'text/html');
var sels = [
'og:url',
'og:type',
'og:title',
'og:description',
'og:image',
'twitter:card',
];
var missing = [];
sels.forEach(sel => {
var selector = `meta[property="${sel}"]`;
var el = dom.querySelector(selector);
if (!el) { missing.push(selector); }
Tools.common_xhr(url, xhr => {
xhr.done(res => {
var dom = new DOMParser().parseFromString(res, 'text/html');
var sels = [
'og:url',
'og:type',
'og:title',
'og:description',
'og:image',
'twitter:card',
];
var missing = [];
sels.forEach(sel => {
var selector = `meta[property="${sel}"]`;
var el = dom.querySelector(selector);
if (!el) { missing.push(selector); }
});
if (!missing.length) { return void cb(true); }
setWarningClass(msg);
msg.appendChild(h('span', [
h('p', [
link(url, url),
' is missing several attributes which provide better previews on social media sites and messengers. ',
"The administrator of this instance can generate them with ", code('npm run make-opengraph'), '.',
]),
h('p', "Missing attributes: "),
h('ul', missing.map(q => h('li', h('code', q)))),
]));
cb(false);
});
if (!missing.length) { return void cb(true); }
setWarningClass(msg);
msg.appendChild(h('span', [
h('p', [
link(url, url),
' is missing several attributes which provide better previews on social media sites and messengers. ',
"The administrator of this instance can generate them with ", code('npm run make-opengraph'), '.',
]),
h('p', "Missing attributes: "),
h('ul', missing.map(q => h('li', h('code', q)))),
]));
cb(false);
});
});
});
var serverToken;